You are not logged in.
Announcement
Unanswered posts
|
Pages: 1
Hey!
I've got problems with talend using json.
I have a file containing 2 cols : [ID][JSON]
I just want to exract some precise data from that json without losing my ID. So i could make a new file like : [ID][JSON_Data1][JSON_Data2] (and so on)
I attempted to use a tFileInputJSON. I had to separate my [ID] from my [JSON] 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?
Offline

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
Offline
Thx for reading.
Here is my json example :
{
"RawListDigest":" Test - 2001",
"Type":"Book",
"Title":"Book Test",
"Contributor":
{
"Authors":
[
{"Name":"John"},
{"Name":"Smith"}
],
"Editor":[{"Name":"Foo"}]
},
"Topic":"Some topic",
"Attributes":
[
{
"AtributeKey":"A001",
"Value":"TestCollection",
"ValueKey":"V001",
"AttributeName":"Collection"
},
{
"AtributeKey":"A002",
"Value":255,
"ValueKey":"V002",
"AttributeName":"Number of pages"
},
{
"AtributeKey":"A015",
"Value":"350g",
"ValueKey":"V003",
"AttributeName":"Weight"
},
{
"AtributeKey":"A099",
"Value":"2001-01-01 00:00:00.0",
"ValueKey":"V055",
"AttributeName":"Date"
}
],
}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
).
And voila ^^
Tell me if i missed something ^^.
Offline
Pages: 1