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 Array with twriteJsonField

hello I would like to build an array of objects using the twritejsonFields as above.

but when I define the list type as my transaction field type and run the job.

I get an error that states <<cannot convert from string to list>> .

Please, can you help me

Labels (6)
13 Replies
Anonymous
Not applicable

As a test, could you please setup the column 'transactions' Type to 'String' in tWriteJSONField output schema?

0695b00000Z1WCGAA3.png

TRandy
Contributor III
Contributor III
Author

Hi @Aiming Chen​ , thanks for your feeldback

by filling in as type string it works.

But it doesn't solve my problem as the transaction field must be of type Array/List

Anonymous
Not applicable

You can add another component tJavaRow to read the json fields and convert it to type Array/List after the tWriteJSONField component

TRandy
Contributor III
Contributor III
Author

@Aiming Chen​ 

How can i do that ??

Is there a precise code to write ??

Anonymous
Not applicable

Maybe you can do it like:

  1. create a routine code JsonUtil -> add routine libraries to add json-lib jar and add one method to convert the json string to List as the below0695b00000Z1nTiAAJ.png
  2. in the tJavaRow component, invoke the routine code method to get the List of the input json string as the output_row column(List type) like 0695b00000Z1nUqAAJ.png
TRandy
Contributor III
Contributor III
Author

0695b00000Z2FCuAAN.png0695b00000Z2FCQAA3.pngHi @Aiming Chen​ 

thanks for your feeldback.

I have this error

Anonymous
Not applicable

@Tim Randy​  could you please right click on the routine JsonUtil ->Edit Routine Libraries -> make sure you select the json-lib-2.4.6-talend.jar?

0695b00000Z2VL4AAN.png

TRandy
Contributor III
Contributor III
Author

OK Thank you @Aiming Chen​ 

I have just imported this librairy

Here is the error I get the following

It seems to be related to the Student routine .....0695b00000Z2VnDAAV.png

Anonymous
Not applicable

@Tim Randy​  did you setup the property 'Amount' in the routines.Student?

the properties in the routines.Student should be the same as that in the json string, here is an example in my side:0695b00000Z2whMAAR.png