Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Write Table now available in Qlik Cloud Analytics: Read Blog
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to create a JSON nested where the objects have different names

Hello guys!

 

I have the following table structure and I'd like to create a JSON file using the tWriteJSONField.

 

FirstName | LastName
John      | McCain
Peter     | Fitzgerald
Pablo     | De Los Santos

 

My JSON should be something like that below. The name of the nest could be created using the Numeric.sequence function I suppose.

{
    "0" : {
        "FirstName" : "John",
        "LastName" : "McCain"
    },
    "1" : {
        "FirstName" : "Peter",
        "LastName" : "Fitzgerald"
    },
    "2" : {
        "FirstName" : "Pablo",
        "LastName" : "De Los Santos"
    }
}

 

Thanks for helping me.

 

 

Labels (3)
12 Replies
javvaji
Creator II
Creator II

Hi @lli,

 

We have tried the example which you sent but we are unable to get the expected json. Below are the issues

For parent json path you mentioned String.valueOf(row2.index), we used same way but we are getting null value. And one more thing we are getting only one value in object but here we need to get multiple values as object. I don't see an multiple objects in an object option. Could help me on this.

 

Source:

address_id,address_line_1,city,address_type
12345,1000 Main St.,Boston,home
6789,1000 Work Dr.,Boston,work

 

Expected Output:

"address":
{
"home":
{
"address_id":"123245",
"address_line_1":"1000 Main St.",
"city":"Boston",
"country":"US",
"state":"MA"
},
"work":
{
"address_id":"6789",
"address_line_1":"1000 Work Dr.",
"city":"Boston",
"country":"US",
"state":"MA"
}
}

 

Thanks,

Bharath.

Anonymous
Not applicable
Author

It was quite easy to do:

{
  "home" : {
    "address_id" : "12345",
    "address_line_1" : "1000 Main St.",
    "city" : "Boston"
  },
  "work" : {
    "address_id" : "6789",
    "address_line_1" : "1000 Work Dr.",
    "city" : "Boston"
  }
}

I have attached the demo job as item export. Use the item import to load this job into your studio. The job is created with Talend 6.5.1


test_tJSONDocOutput_dynamic_object2.zip
ragraw22
Contributor
Contributor

@lli Hi, Can you send us the sample job you created for this scenario :

Scenario 2: Example of multi-level document creation

 

I need to see how data look like in tfixedfileinput.