One Star

JSON list of values

Hi everyone! Need your help:
I have json file :
{
"Name": "Items List",
"Items":
}
I need to convert it to something like this:
|=---------+-----------------------=|
|Name |Items |
|=---------+-----------------------=|
|Items List| |
'----------+--------------------------'
|Items List| |
'----------+--------------------------'
|Items List| |
'----------+--------------------------'
Unfortunately i have some strange results, i run my job in TOS Version: 5.3.1 on windows
and i get
!!!!!! Items list:]
!!!!!! Items list size: 1
.----------+---------------------------.
| tLogRow_1 |
|=---------+--------------------------=|
|Name |Items |
|=---------+--------------------------=|
|Items List|]|
'----------+---------------------------'
1. I use tFileInputJSON like my input (scheme: Name - string, Items - List)
2. I use tJavaRow
3. tLogRow
All it sounds very basic but not works like i expected :-(
Any ideas?
Please, little help will be appreciated, thanks
10 REPLIES
Moderator

Re: JSON list of values

Hi,
Please take a look at component reference TalendHelpCenter:tExtractJSONFields.
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: JSON list of values

Hi Sabrina, thanks for answering me, but still it's not so clear for me :-(
I got through all docs about tExtractJSONFields and so?? exampels of it ... I inserted tExtractJSONFields in my job but i have no idea what about parameter "XPath query" of this component, I have a list of Strings and don't have any label to every item, so what i put in "XPath query"??
Moderator

Re: JSON list of values

Hi,
For XPath query, here is a reference http://www.w3schools.com/xpath/default.asp.
You can use File JSON metadata to Set up a JSON schema for an input file, which will be helpful for you to understand XPath query.
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: JSON list of values

I use TOS for Big Data, i don't have the "Metadata" in my Repository :-(
Xpath that i looking for is to member (string) of element collections and NOT object collection that every member has its label. Its Possible that Talend not supports list of strings (or integers) and only list of objects in json field??
Sabrina, please look at my simple example above, hope you have an answer
thanks
One Star

Re: JSON list of values

Any help. please!!
One Star

Re: JSON list of values

Hi again,
I still can not overcome the problem, is it possible only in Subscription License?
Community Manager

Re: JSON list of values

Hi Oksana
If the size of the item list is always fixed, for example, 3 items in this example, you can set the xpath query as "../Items" to map the first item. Here I show you an demo job how to read the json file and get the expected result.
in.json
{
"Name": "Items List",
"Items":
}
code on tJavaRow:
output_row.item_list = input_row.item_list;
//concatenate column0, column1, column1 to one column, eg: item1;item2;item3
output_row.conn = input_row.column0+";"+input_row.column1+";"+input_row.column2;

console:
Starting job Demo at 16:45 19/12/2013.
connecting to socket on port 4061
connected
.----------+-------+-------+-------.
| tLogRow_1 |
|=---------+-------+-------+------=|
|item_list |column0|column1|column2|
|=---------+-------+-------+------=|
|Items List|Item1 |Item2 |Item3 |
'----------+-------+-------+-------'
.----------+-----.
| tLogRow_2 |
|=---------+----=|
|item_list |conn |
|=---------+----=|
|Items List|Item1|
|Items List|Item2|
|Items List|Item3|
'----------+-----'
disconnected
Job Demo ended at 16:45 19/12/2013.

----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: JSON list of values

So thank you !!!
But still i have i problem, I don't know how many members is going to be in the list!! Is there is some other work around?
Thanks a lot
Community Manager

Re: JSON list of values

Hi
This approach don't suitable for the case the number of items changes. Read the json file without by XPath, and then extract the fields from the string list with tExtractRegexFields, see my screenshots.
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: JSON list of values

Thank you very much, i'll try it.