json output... almost there. i need arrays and it's creating objects

One Star

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.
Community Manager

Re: json output... almost there. i need arrays and it's creating objects

Hi
We usually use a tRestClient component to call a rest web service, and post a request with json format, you can find an example in this topic:
http://www.talendforge.org/forum/viewtopic.php?id=31284
But, it don't output the json request with Arrays format on tXMLMap.
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
Employee

Re: json output... almost there. i need arrays and it's creating objects

We are working on better support for arrays in XML to JSON auto-conversion supported by tRESTClient
Cheers, Sergey
One Star

Re: json output... almost there. i need arrays and it's creating objects

Any update on this?  It's been a couple years now and wondering if Talend has any solutions to this problem?
Thanks
One Star

Re: json output... almost there. i need arrays and it's creating objects

Hi,
Any update on this one? I am also trying to use tXMLmap to output array of JSON objects and it is not working. I am using Talend 5.5.
Thanks,
Gowri
One Star

Re: json output... almost there. i need arrays and it's creating objects

Any update on this?  This is a hot topic in the Talend community and it needs attention.  Any help would be greatly appreciated.
One Star

Re: json output... almost there. i need arrays and it's creating objects

We are also interested in finding a solution to this.
We have a data source passed to a tXMLMap component that loops object according to this structure:
<root>
   <person name="" />
</root>

If the person tag is looped having 2 rows (name1 and name2) would produce the following json, correctly:
{ person:  }

But if it's only one row (name1) the following json is produced:
{ person: { name="name1" } }

I guess this is a result of talend placing looped objects as tags, and one single tag has no indication of being a looped entity.
Regardless, this needs to be resolved for the JSON output to be accurate. Consuming systems will otherwise have to validate the json outcome, or we need to manually change the string before passing it as a response.
One Star

Re: json output... almost there. i need arrays and it's creating objects

Hi,
We are also waiting for someone who make this structure works. Is there any news?
Thanks
Rafael
One Star

Re: json output... almost there. i need arrays and it's creating objects

Anyone solved this problem?
How can I convert json objects into arrays of objects?
One Star

Re: json output... almost there. i need arrays and it's creating objects

Any update with this? I'm facing the same problem.
One Star

Re: json output... almost there. i need arrays and it's creating objects

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...
One Star

Re: json output... almost there. i need arrays and it's creating objects

Any news ?
The issue still occurs when using TOS for Big Data 6.2.1
Five Stars

Re: json output... almost there. i need arrays and it's creating objects

I have the same problem: it returns:
{"types":{"symbolicName":}}

needed is:
{"types":
}

I have tried multiple ways, but there seems to be no way to create this using TXMLMAP and responste
One Star

Re: json output... almost there. i need arrays and it's creating objects

Is there Update on this I do have same isse. Not able to create a JSON file with array []
One Star

Re: json output... almost there. i need arrays and it's creating objects

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! 
One Star

Re: json output... almost there. i need arrays and it's creating objects

Create an attribute under the field that you want as an array and default it as an array.
One Star

Re: json output... almost there. i need arrays and it's creating objects

I'm ran into the same problem with Talend 6.3.1. Talend Team, any news for us?
One Star

Re: json output... almost there. i need arrays and it's creating objects

Create an attribute under the field that you want as an array and default it as an array.

I like this idea, but how do you "default it as an array"
One Star

Re: json output... almost there. i need arrays and it's creating objects

Hi
Type the word Array in the static Value column of the write Json task
@class - Attribute
set a fixed value - Array
Works for me

HTH
Four Stars

Re: json output... almost there. i need arrays and it's creating objects

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.