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
Highlighted
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.

View solution in original post


All Replies
Highlighted
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 :-)

Highlighted
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.

Highlighted
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.

View solution in original post

Highlighted
Four Stars

Re: Create array inside JSON

Thank you, It works Smiley Happy

Highlighted
Four Stars

Re: Create array inside JSON

@rhall_2_0  Could you please let me know how to configure multiple array objects

my expected output is as below

{
"_id": "123",
"cabins": [
{
"cabin_Id": "12434",
"name": "Cabin 1"
},
{
"cabin_Id": "8765",
"name": "Cabin 3"
}
],
"country": "FR",
"departments": [
{
"dept_id": "123",
"name": "Computers"
},
{
"dept_id": "345",
"name": "arch"
}
]
}

2019 GARTNER 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

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog