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: 
Francis28
Contributor
Contributor

JSON Array with Web Service TRestClient

Hello,

I have a JSON file that looks like this:

0695b00000kWuKFAA0.png

I get JSON data from the web service using a TRESTClient component and I extract data with a tExtractJSONFields.

BUT I can't extract data from the "rapprochements" array.

I tried several JSON query unsuccesfully.

0695b00000kWuLIAA0.png

0695b00000kWuLNAA0.png

Any idea or suggestion ?

Thanks in advance for your help

Regards,

Labels (4)
2 Replies
anselmopeixoto
Partner - Creator III
Partner - Creator III

Hi @Francis Noyeau​ 

 

Your JSON has two loops defined by its arrays: the root level array and the "rapprochements" array.

 

But the tExtractJSONFields component allows only one loop at the "Requéte de boucle JSONPath".

 

So, there are some approaches you can try and see what fits best for you:

 

A) Set the Loop Jsonpath query to iterate over the root array using the "$" operator (that is the root object/element of a JSON). And then, in the Mapping Json query, you could use expressions like:

  • "id"
  • "rapprochements[*].propositionId"
  • "rapprochements[*].demande.id"

One downside of this approach is that the component will not loop over the "rapprochements" element. Instead, it will output its subelements as an array.

 

B) Set the Loop Jsonpath query to iterate over the "rapprochements" array using the expression "$..rapprochements[*]". And then, in the Mapping Json query, you could use expressions like:

  • ".propositionId"
  • ".demande.id"

But notice that using this loop level, you wouldn't be able to reach the "id" on the parent level because the jsonpath doesn't have a parent operator (reference).

 

C) Change the "Read by" option on tExtractJSONField to use Xpath expressions and set the loop xpath query to "/rapprochements". And then, in the Mapping Xpath query, you could use expressions like:

  • "../id"
  • "./propositionId"
  • "./demande/id"

Notice that this approach use the same loop level as the previous, but it allows you to reach the elements at parent level using the ".." expression.

 

D) Finally, since you're using tRESTClient to get this JSON, you could use tXMLMap instead of tExtractJSONFields because tRESTClient automatically converts JSON responses to a DOM Document and looping over multiple levels using tXMLMap is far easier, in my opinion.

Francis28
Contributor
Contributor
Author

Hi @Anselmo Peixoto​ 

 

Thank you very much for your reply.

It helps me to solve my problem and to learn more about Jsonpath query

Regards