One Star

Parsing Json in Talend?

Hey!
I've got problems with talend using json.
I have a file containing 2 cols :
I just want to exract some precise data from that json without losing my ID. So i could make a new file like : (and so on)
I attempted to use a tFileInputJSON. I had to separate my from my in order to do so but i couldn't mix those data again with a tMap for example.
So instead, i manage to use a tJavaRow. This way i can keep all my previous cols and treat my JSON string easier. BUT, i can't get this thing to work properly.
Here is my code :
JSONObject json = new JSONObject(input_row.jsonCol);
JSONArray jsonMainArr = json.getJSONArray("Att");
System.out.println(jsonMainArr.toString());

And i get an error saying to me that JSONArray is not visible.
So i thought that i forgot to "import" something so i added :
import org.json.simple.JSONArray;

It can't find it :/
When i try to look in "outines.system" i can only find a "JSONObject"...
I did not wanted to use a tExtractRegexFields...
So what should i do? any clue?
3 REPLIES
One Star

Re: Parsing Json in Talend?

Hi
Welcome to Talend Community!
Could you show us the data of your JSON file and the expected result?
Maybe we could create a job and get the result in a Talend way.
I think there is no need to code in tJavaRow. It shouldn't be so complex.
Regards,
Pedro
One Star

Re: Parsing Json in Talend?

Thx for reading.
Here is my json example :
{
"RawListDigest":" Test - 2001",
"Type":"Book",
"Title":"Book Test",
"Contributor":
{
"Authors":
,
"Editor":
},
"Topic":"Some topic",
"Attributes":
,
}

And i wanted to have something like
BookID|Type|Attribute - Collection (if AttributeKey == "A001")

So, my final file could like :
15648|Book|TestCollection
15649|Book|Collection2
15650|Book|TestCollection
16697|Book|My Collection

I get the "BookID" value from a file containing all my book id. Then i make a request via URL to get an XML for eache book id.
That XML contain my json Data (actually i managed to isolate that data thanx to XPath Smiley Happy ).
And voila ^^
Tell me if i missed something ^^.
One Star

Re: Parsing Json in Talend?

Hi there. I don't know if you came right... but your could try:

 import org.json.JSONArray;