web stats
Mirth Community - View Single Post - CSV into JSON !
Thread: CSV into JSON !
View Single Post
  #3  
Old 04-08-2019, 01:44 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,005
agermano is on a distinguished road
Default

I would normally expect the JSON to look like this:
Code:
{
  "Day": "Monday",
  "Fruits": ["Apples", "Oranges", "Peaches", "Mangoes"]
}
That would be produced by this code:
Code:
msg = {
    Day: msg.row.child(0).toString(),
    Fruits: msg.row.child(1).toString().split(';')
}
This will output JSON like you described:
Code:
msg = {
    Day: msg.row.child(0).toString(),
    Fruits: [msg.row.child(1).toString().split(';').reduce(function(obj, fruit, i) {obj['Fruit'+(i+1)] = fruit; return obj}, {})]
}
Reply With Quote