Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. READ MORE

Qlik Talend Data Integration: Using JSONPath expressions to filter JSON data

No ratings
cancel
Showing results for 
Search instead for 
Did you mean: 
TalendSolutionExpert
Contributor II
Contributor II

Qlik Talend Data Integration: Using JSONPath expressions to filter JSON data

Last Update:

May 13, 2024 5:42:45 AM

Updated By:

Shicong_Hong

Created date:

Jul 3, 2023 11:17:21 AM

JSON data returned from a web service often contains a single parent object, which wraps child objects or arrays. If the parent object is used directly, the response will not display any detail records.

When using tExtractJSONFields to extract JSON data from a JSON string or using tFileInputJSON to read a JSON file, if the number of array elements is very large, it will take up a lot of resources. Sometimes you only need to extract JSON data that matches specific criteria, and it is more convenient to return an array of child objects instead of a parent object.

Resolution

Use JSONPath expressions in the Loop Json query field to query and filter JSON data from a JSON file.

Example JSON file:
 
{
  "array": [
    {
      "filename": "CoverLetter.docx",
      "url": "",
      "type": "cover_letter",
      "created_at": "2022-01-03T19:09:12.839Z",
      "price": 8.95
    },
    {
      "filename": "Resume1.pdf",
      "url": "",
      "type": "resume",
      "created_at": "2022-02-03T19:09:12.602Z",
      "price": 10.11
    },
    {
      "filename": "image.jpg",
      "url": "",
      "type": "image",
      "created_at": "2023-02-27T13:01:04.786Z",
      "price": 8.85
    },
       {
      "filename": "Resume2.pdf",
      "url": "",
      "type": "resume",
      "created_at": "2022-03-04T19:09:12.602Z",
      "price": 11.11
    }
  ]
}

Example 1: Filter the JSON data only when the type is 'resume'.
 
$.array[?(@.type=='resume')]

0EM5b00000AsPga.png

Expected result:

0EM5b00000AsPgp.png

Example 2: Filter the JSON data only when the type is 'resume' and created_at is <'2022-03-01'.
 
$.array[?(@.type=='resume'&&@.created_at<'2022-03-01')]

0EM5b00000AsPh4.png

Expected result:

0EM5b00000AsPh9.png
 
For more information about JSONPath syntax, see the JSONPath - XPath for JSON page on goessner.net.
 

Environment

Labels (3)
Version history
Last update:
‎2024-05-13 05:42 AM
Updated by: