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

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

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
0683p000009MBsQ.jpg 0683p000009MBqV.jpg
Labels (4)
10 Replies
Anonymous
Not applicable
Author

Hi,
Please take a look at component reference TalendHelpCenter:tExtractJSONFields.
Best regards
Sabrina
Anonymous
Not applicable
Author

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"??
0683p000009MBiM.png
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

Any help. please!!
Anonymous
Not applicable
Author

Hi again,
I still can not overcome the problem, is it possible only in Subscription License?
Anonymous
Not applicable
Author

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.

0683p000009MBsV.png 0683p000009MBlz.png 0683p000009MBKt.png
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

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
0683p000009MBpD.png 0683p000009MBsa.png 0683p000009MBsf.png