Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
param75
Contributor III
Contributor III

DataMapper - Transform JSON array to XML

Hi,
I use a mapping (component tHMap) to transform data from a JSON to XML.
However, I do not know how to retrieve the first, second (or more) values of a JSON array.
My first step would be to just get the first item and place it in the first tag category_1.
Ditto for the next elements.
"category" field into my JSON file:
"category":


Here is the structure that I want to generate:
<categories>
<category_1>test</category_1>
<category_1>test_talend_2</category_1>
<category_1>test_talend</category_1>
</categories>


Here is my mapping (Map):
0683p000009MC1S.png
I think we should to use a Loop function but i dont know how to use it:
0683p000009MBwY.png
Properties of "category" in JSON structure:
0683p000009MC1X.png
My second step is to sort the values by string length. Exemple:
<categories>
<category_1>test</category_1>
<category_1>test_talend</category_1>
<category_1>test_talend_2</category_1>
</categories>

Is there a function for this in DataMapper?
Thks all.
Labels (4)
6 Replies
Anonymous
Not applicable

Hello,
We have re-directed your issue to TDM expert and then come back to you as soon as we can.
Best regards
Sabrina
Haitao
Creator
Creator

Hello PM_param, what's your expected output?

a loop of category_1?
<categories>
<category_1>test</category_1>
<category_1>test_talend_2</category_1>
<category_1>test_talend</category_1>
</categories>

category_1 and category_2 and category_3?
<categories>
<category_1>test</category_1>
<category_2>test_talend_2</category_2>
<category_3>test_talend</category_3>
</categories>

a sorted loop of category_1?
<categories>
<category_1>test</category_1>
<category_1>test_talend</category_1>
<category_1>test_talend_2</category_1>
</categories>

Something else?
Haitao
Creator
Creator

To get the 2nd type of output, please use the AgConcat and SingleIndex functions as below
0683p000009MC1c.png
param75
Contributor III
Contributor III
Author

Hi hnie,
Thank's for your answer, the expected ouput is the lowest value in category 1, category 2 in the second and last (the longuest value) in category 3.
Today i resolve the first problem which was the XML structure. Now the field is set as below:
0683p000009MByF.png
In my Map, I loop on "category" and I recovers only one that interested me as below:
0683p000009MByt.png
However I think there is a simpler method to get the right values, no? There is a function for compare values length?
Thank's for you help.
Haitao
Creator
Creator

Functions/String/StringLength and Functions/Comparison and Logical/* will allow your to compare values length.
param75
Contributor III
Contributor III
Author

Thank's for reply, I used a RegEx for determine category to use.
category_1:
0683p000009MByu.png
category_2:
0683p000009MC1h.pngcategory_3:
0683p000009MC0p.pngHowever, when I click on "Test Run", I have the bug:
 " Exception during test run:

Thread Expr in$/Root/hits/hits/_source/category enclosing node: out$/Root/RequiredRecord/souscategorie_value != out$/Root/RequiredRecord/souscategorie2_value"
0683p000009MBjy.pngI specify that I use this function in several Maps. On the other Map (1 only), everything is ok.
There is a problem with json structure?