Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
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....
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...
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.