Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Baptiste1
Contributor
Contributor

tExtractJSONFields altering node value

Hello,

 

I had the other day a JSON as input with that kind of structure :

{
"key1" : {
"label" : "delay", "month" : { "1" : 12, "2" : 24, "3" : 36, "4" : 44, "5" : 138, "6" : 195, "7" : 127, "8" : 91, "9" : 52, "10" : 45, "11" : 21, "12" : 15 } },
"key2" : {
"label" : "speed",
"value" : 144
}
}

I used a tExtractJSONFields to get key1.month and key2.value.
My goal was to have all monthly value in the correct order in the same cell : "12,24,36,44138,195,127,91,52,45,21,15", and as I some more keys concerned I wanted to avoid using a second tExtractJSONFields component to keep the visual clean.

I applied a quick regex to break down the node "month" into a string, working smoothly on regex101 :

StringHandling.EREPLACE(
        StringHandling.EREPLACE(<nodeJSON>, "\"\\d+\"",""),
        "(?:\\s|:|\\{|\\})",
        ""
       )
);

https://regex101.com/r/uMUPhC/1

https://regex101.com/r/nPJAFM/13

 

However, Talend output was : "21,12,15,24,36,44138,195,127,91,52,45"

The ordering was corresponding to "11,1,12,2,3,4,5,6,7,8,9,10", which does neither correspond the the JSON input's ordering nor an alphanumerical ordering. This ordering is always the same on all my values.

Even though I got it to work fine by using a second tExtractJSONFields component in order to get the right ordering, but I still ask myself two questions :

  • Why does selecting a full node alter its content ? when I look at a single page of a book I do not expect to see the sentences ordering change
  • Why this ordering "11,1,12,2,3,4,5,6,7,8,9,10" ? I do not see how it could be ordered like that

 

Attached is a job pointing out this issue, detected on 7.2.1 TCI and exported from 7.1 TOS.

 

Have a nice day and best regards,

Baptiste

Labels (2)
1 Reply
David_Beaty
Specialist
Specialist

Hi,

 

This is probably not what you want to hear, but generally it very bad practice to couple the position of data within a JSON (or XML) document to its meaning (assuming the first element is January, second is February, etc). Also, as you're finding, Talend doesn't guarantee processing in the same order as it forms the JSON object internally.