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: 
walidmas
Partner - Contributor

Extracting JSON data from a file

Hello team, we have a json file with three loops Po, Delivery and Items,

we manage to extract data from the file using the tExtractjsonCompoenent (XPATH or JSONPATH) if the files contains the the three loops

however we are facing this issues , i will try to explain in the following exemple

i'am reading a file named data.json which contain

  • 2 PO (first loop level )
  • 2 Delivery (seocnd loop level ) - ---> 1 delivery in the first PO

----> 1 delivery in the second PO

  • 2 item (third loop level ) ------> 2 item in the first delivery of the the first PO

------> the second PO does not include any item inside the the delivery level

0695b00000Uyp7NAAR.png

we manage to read the first PO successfully as shown in the job however we couldn't read the second PO beacasue it does not contain

the item level in the delivery so how can we read a complex Json file with optional level (which means that the item level could exist in one PO

but not in the seocnd or in the thrid , it is an optinal element

0695b00000Uyp7cAAB.png

this is the configuration that we are doing in tExtractJson

0695b00000Uyp8BAAR.png

0695b00000Uyp8LAAR.png

Thanks

Labels (4)
3 Replies
tchanabc
Contributor III

I know this isn't ideal, but you can create 3 JSON inputs, each with the 3 JSON arrays and then merge them together

KrishnaApurva
Contributor

Hi @wmasmoudi,

 

You can try by using three tExtractJSONField components one-by-one like this and expand your JSON fields by extracting them.

For example: In your case, you can first extract PO [ ..., Delivery,...] ------> then expand the Delivery [..., item,...] ---------> then expand Item.

0695b00000WtP54AAF.pngAfter that, you have fully expanded JSON with all the elements.

 

Mehdi_Mhedhbi2
Contributor III

Hi , thanks for your answer , actually we tried that at the the beginning but the result was the same