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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to parse Dictionary with talend?

Hi,

I'm trying to loop the dictionary as below

{"Departments":{"aaa":111,"bbb":222,"ccc":333,"ddd":444,"eee":555,"fff":666,"ggg":777,"hhh":888}}

with tfileinputjson and with XPath, 

In my scenario I have N number of keys, how can I store all the keys in column 1 and values in column two without using custom component.

Please find the pic of my tfileinputjson component details.

PFA

Labels (2)
1 Reply
Anonymous
Not applicable
Author

Unfortunately unknown keys are a bit of a challenge with Talend JSON components. However, you can get around this using Java.

 

Take a look at the code I have used in this question (https://community.talend.com/t5/Design-and-Development/how-can-i-parsing-json-array-and-create-the-t...). You can use that same code, with a Job that looks like this....

0683p000009M8U6.png

The tFixedFlowInput_1 is where I am beginning, but you can change this if required. It simply provides the JSON. I extract the "Description" entity using the tExtractJSONFields_1 component. I have configured it like this...

0683p000009M8Td.png
In the tJavaFlex component, I am using the routine method I described in the post I have linked to above. In my example the routine is called TestRoutines and my method is called getSubJSON.

 

Main Code

java.util.ArrayList<String> al = routines.TestRoutines.getSubJSON(row2.Description);
java.util.Iterator<String> it = al.iterator();

while(it.hasNext()){
	System.out.println(it.next());
}

I am simply iterating this out to the System.out. You will need to decide what you do with the data from there.

In the output window I get the following using your JSON....

[statistics] connecting to socket on port 4036
[statistics] connected
{"aaa":111}
{"ccc":333}
{"bbb":222}
{"eee":555}
{"ddd":444}
{"ggg":777}
{"fff":666}
{"hhh":888}
[statistics] disconnected

You can get to the key and value using simple String manipulation from here.