Create array inside JSON

Highlighted
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


Accepted Solutions
Community Manager

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.


All Replies
Community Manager

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 :-)

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.

Community Manager

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.

Four Stars

Re: Create array inside JSON

Thank you, It works Smiley Happy

Calling Talend Open Studio Users

The first 100 community members completing the Open Studio survey win a $10 gift voucher.

Start the survey

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Downloads and Trials

Test drive Talend's enterprise products.

Downloads