Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
TRandy
Contributor III
Contributor III

Json list array and not json string array using twritejson

Hi, I would like to build an array of objects using twritejsonFields as below.

But when i set the type list as the transaction field type and run the job.

I get <<cannot convert from string to list>> .

yet I need transactions to be of type list and not string

Please can you help me

Labels (4)
11 Replies
TRandy
Contributor III
Contributor III
Author

Hi @Richard Hall​ ,

input data 👇

0695b00000aDUUzAAO.pngoutput desired

0695b00000aDUVdAAO.pngyou notice here that transactions is a json array so its value is not between "".

Anonymous
Not applicable

Fundamentally you have to treat your input data as Strings, Numbers, Booleans and nulls, contained in arrays and objects (JSON Objects). JSON is essentially just text. As such, you will need to extract this input data into rows like this.....

 

Cash, Code, DateAt, Identifiant, Validate

5000, Tx-1000, 2001-11-03T15:38:52.330+01:00, 1001, true

5000, Tx-1002, 2001-11-03T15:38:52.330+01:00, 1002, true

 

Your output will then build this up again. I have a question about your output because I can see a potential flaw in this structure. In your "data" objects, you have 2 sub-objects in the examples above. So you have 2 identifiant and valide entities in each. Looking at your input data I see that this is likely because your cash and dateAt values are the same. What if you have 3 the same? Would your data object grow to hold 3 sub-objects? If so, this may cause you problems. It might be better to have data as an array of JSON objects holding identifiant and valide.

 

Anyway, this structure may be difficult to build with a single tWriteJSONField component. They are really meant for simple structures. The subscription Talend product has Talend Data Mapper which would be better suited to this. Alternatively (and a favourite method of mine), you can use Java to build slightly more complicated structures. But the first issue you need to resolve is how you will extract your data from JSON and group it.