Document toolboxDocument toolbox

JSONPath expressions

USE:

JSONPath expressions are used to operate on JSON messages.

For testing JSONPath expressions see Int4 IFTT Expression Test Tool 

Int4 IFTT supports JSONPath expressions in dot-notation.

Here is a list of supported syntax elements and their XPath equivalents.

XPath

JSONPath

Description

XPath

JSONPath

Description

/

$

root element/object

//

..

recursive descent

*

*

wildcard (all objects)

[]

[]

collection/array operator

Examples:

JSON file:

{ "order": { "item": [{ "category": "Monitors", "itemText": "LCD Monitor 22 inch", "price": 128.95 }, { "category": "Printers", "itemText": "Label Printer", "price": 56.99 }, { "category": "Monitors", "itemText": "LCD Monitor 24 inch Full HD", "price": 211.99 }, { "category": "Printers", "itemText": "Laser Printer", "price": 77.99 } ], "paymentTerms": { "code": "N30", "description": "Payment 30 days after invoice date" } } }
  1. All item texts
    JSONPath: $.order.item[*].itemText

    Result:
    LCD Monitor 22 inch

    Label Printer

    LCD Monitor 24 inch Full HD

    Laser Printer

  2. Price of 3rd item
    JSONPath: $.order.item[2].price

    Result:
    211.99

  3. All categories
    JSONPath: $..category

    Result:
    Monitors

    Printers

 

Int4 IFTT converts JSON files to JSON-XML - SAP-specific representation of JSON data in XML format.

It is possible to use Xpath expressions for JSON files based on this representation. Such expressions have to be preceded with '$' sign.
This feature can be used in case it is not possible to select required values with current scope of JSONPath syntax.

JSON-XML representation of above file:

<?xml version="1.0"?> <object> <object name="order"> <array name="item"> <object> <str name="category">Monitors</str> <str name="itemText">LCD Monitor 22 inch</str> <num name="price">128.95</num> </object> <object> <str name="category">Printers</str> <str name="itemText">Label Printer</str> <num name="price">56.99</num> </object> <object> <str name="category">Monitors</str> <str name="itemText">LCD Monitor 24 inch Full HD</str> <num name="price">211.99</num> </object> <object> <str name="category">Printers</str> <str name="itemText">Laser Printer</str> <num name="price">77.99</num> </object> </array> <object name="paymentTerms"> <str name="code">N30</str> <str name="description">Payment 30 days after invoice date</str> </object> </object> </object>
  1. Select prices of items in Printer category
    Expression: $//array[@name="item"]/object[str[@name = 'category']/text() = 'Printers' ]/num[@name="price"]/text()

    Result:
    56.99

    77.99

 

© 2017 - 2022 Int4 AG All rights reserved