json output... almost there. i need arrays and it's creating objects
newbie to TOS (5.3) familiar with json, i think the json TOS is producing is "correct", it's just my endpoint wants arrays not objects
big picture... i'm trying to read a csv, convert each record to json and call a rest api to insert. I want this...
,
"FirstName": ,
"LastName":
},
"xref":
}
]
I'm getting this
{
"type":"conf/nodeTypes/Person",
"attributes": {
"Name": {
"type":"conf/nodeTypes/Person/attributes/Name",
"value":"DavidCole"
},
"FirstName": {
"type":"conf/nodeTypes/Person/attributes/FirstName",
"value":"David"
},
"LastName": {
"type":"conf/nodeTypes/Person/attributes/LastName",
"value":"Cole"
}
},
"xref": {
"type":"conf/sources/IMD",
"value":"1",
"url":"
www.domainName.com"
}
}
Problems...
1. JSON is output as objects {...} not Arrays (see Name, FirstName, etc.) maybe technically that's ok, it's valid JSON, but my endpoint wants Arrays.
2. I'm not getting the surrounding brackets... I was able to use TFileOutputJSON to add brackets but
A. I don't want to go to a file
B. It does all my rows not one at a time
I tried a bunch of things but can't force an array. I posted the job stream, using viewers for debug, not very interesting.
any suggestion would be welcomed.
BTW... if someone had an example of process a record POST to REST, read response, process next... that would be helpful, i'll post a separate thread as well.
thanks for reading.
hi
I couldn't create a json array in tjava row.can anyone help me out with the solution because I am new to this....
I am getting this o/p.
{"Customer":"JI0000","RecordType":"POH","Warehouse":"","RecordNumber":"000001","OrderDate":"20140730","Action":"A","SalesOrder":"01","Company":"56","InboundOrder":"P0001982"}
but I need this inside an array...
So this post is 4 years old. People are obviously still having problems with this issue. Talend Team, can you please respond? I'm having the same issue as everyone here and not sure how to resolve it. Thanks!
Since this sounded indeed interesting, I checked it out. It seems to do the trick in forcing square brackets around the desired value if it has only on occurence.
Maybe I made some mistakes in my tWriteJSONField, but declaring for example my loop element as an array, I ended up with each element being an array inside an array of the loop elements. So it depends on how your JSON should look like, but it is still worth keeping in mind.
Btw: What worked for me,but it is not as neat and easy as some settings in tWriteJSONField, is manipulating the JSON String after tWriteJSONField by calling a self-written Java Routine which puts some [] around the content of a given element which I want to be an array. Maybe this is also an approach for others.