Four Stars

Create array inside JSON

Hi,

I created a JSON file using tWriteJSONfield.

Currently, I got the following format:

 

{
"url": "http://google.com",
"findings": {
"id": "1",
"type": "1",
"sub_type": "7",
"cul": [],
"or": "3",
"date": "05-05-2015",
"num": []
}
}

 

 

and need the following ("findings" data should be inside an array):

{
"url": "http://google.com",
"findings": [{
"id": "1",
"type": "1",
"sub_type": "7",
"cul": [],
"or": "3",
"date": "05-05-2015",
"num": []
}]
}

 

 

How can I do that?

Attached is a screenshot of my Json tree.

 

Thanks,

Emma

1 ACCEPTED SOLUTION

Accepted Solutions
Fifteen Stars

Re: Create array inside JSON

OK, I have built the following dummy structure.....

 

{"rootTag":{"newColumn1":"IH4IST","newColumn2":[{"newColumn3":"IqGyhp","newColumn4":"ULsg8G"}]}}

....using this configuration.....

json_demo.png

 

Basically, add an element called "element", assign it a class of object and add your fields to that element. That should do it.

Rilhia Solutions
4 REPLIES
Fifteen Stars

Re: Create array inside JSON

Take a look at this webpage:  

https://help.talend.com/reader/KxVIhxtXBBFymmkkWJ~O4Q/50PMKM8mz4A5fAL~FQcLHw?section=twritejsonfield...

 

Notice the @class attribute and the "array" in the "static value" column? You need to make use of these. You will need to play around with this functionality until you "get it", but it is worth spending a few hours doing this to get it to sink in :-)

Rilhia Solutions
Four Stars

Re: Create array inside JSON

Thank you,

I defined "findings" as @class  = array, and added the sub-element "element" and defined it as "loop element", I managed to get "findings" as an array,

But without the element names (id, type, sub_type, cul, or, date, num):

 

{
"url": "http://google.com",
"findings": [
"1",
"1",
"7",
[],
"3",
"05-05-2015",
null,
[]
]
}

 

Do you know how to display the element names inside the array?

 

Thanks.

Fifteen Stars

Re: Create array inside JSON

OK, I have built the following dummy structure.....

 

{"rootTag":{"newColumn1":"IH4IST","newColumn2":[{"newColumn3":"IqGyhp","newColumn4":"ULsg8G"}]}}

....using this configuration.....

json_demo.png

 

Basically, add an element called "element", assign it a class of object and add your fields to that element. That should do it.

Rilhia Solutions
Four Stars

Re: Create array inside JSON

Thank you, It works Smiley Happy