Forum Discussion

DonLarson's avatar
DonLarson
Qrew Elite
6 months ago

Parse JSON

If you are looking to parse a JSON response in a Pipeline and you know where and what value are looking for there is a simple way to get to a specific piece of data.  Credit for this goes to Jenny on the QB Support Team for getting me the solution.

There are five parts to the Jinja Expression

  • The STEP that the JSON is resident in
  • The SECTION of the JSON to get
  • What part of the ARRAY to get
  • The FIELD to get 
  • The value

Here is the expression

{{STEP.json.SECTION[ARRAY]['FIELD'].value}}

So here is what my JSON looked like

{ 'data': [{'3': {'value': 14}}],

 'metadata': {'updatedRecordIds': [],

 'createdRecordIds': [14],

'unchangedRecordIds': [],

'totalNumberOfRecordsProcessed': 1}}

{createdRecordIds}

}

This is a really small array.  In the 'data' section is only one piece of data for FID3 and its value is 14.   That is what I wanted to get.

So my working Jinja Expression is 

{{b.json.data[0]['3'].value}}

  • The JSON was coming from Step B.  
  • data is the section I want to get something from.  There is another on it called metadata but I am not interested in those at the moment.
  • 0 is the first part of the array. If your JSON returns ten records JSON counts to ten by going:
    •  0, 1, 2, 3, 4, 5, 6, 7, 8, 9
  • 3 is the name of the information I want.   The real world case here is that I asked for the value of FID 3.  In QB the name of the field would be Record ID but the name is not what got returned it was the FID
  • value  tells it to give me the value for '3'  

The answer that the Pipeline Step kicks out is

14

which is exactly what I needed for the next part of my problem.

If you have large arrays, need to search for data or manipulate the result further, this is probably not helping much.  If you know where and what you want to pull from the JSON, it will do the trick.

 

 

 

 

 

 

No RepliesBe the first to reply