Skip to Content

XPATH for the JSON Struture

Dear Experts,

I am unable to find the XPath for JSON Structure.

Could you help me in finding the XPath for "id" from the below JSON Structure.

{"Success":"true","result_count": 8539,"results_per_page": 200,"page": 1,"data": [{"Order": {"id":"1954123116","is_cod":"1","order_type": null,"created":"2017-07-27 11:57:13","modified":"2017-07-27................... etc.

Thanks & Regards

Neelima

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • avatar image
    Former Member
    Aug 10, 2017 at 12:35 PM

    Hello Neelima,
    I guess you meant JSONPath. Could you please provide the whole json payload?

    Best regards,
    Vadym

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 10, 2017 at 01:16 PM

    Hello Neelima,

    XPath is only relevant for XML documents, as Vadym noted, you are likely to refer to JSONPath when dealing with JSON documents.

    For the extract of JSON document you provided, the following JSONPath can be used to access element 'id':

    $.data[*].Order.id

    Note that since element 'data' is an array, you will need to adapt the path above in case you don't want to retrieve all occurrences of 'id', but are looking for a single occurrence (for example, only the first or the last, etc.).

    Regards,

    Vadim

    Add comment
    10|10000 characters needed characters exceeded

    • Hi,

      I used following JSON document (completed it based on JSON fragment you provided in the initial post):

      {
      "Success": "true",
      "result_count": 8539,
      "results_per_page": 200,
      "page": 1,
      "data": [{
      "Order": {
      "id": "1954123116",
      "is_cod": "1",
      "order_type": null,
      "created": "2017-07-27 11:57:13",
      "modified": "2017-07-27"
      }
      }]
      }

      You can examine correctness of JSONPath for example at http://jsonpath.com/ - when I run it against the given JSON document, I get the expected output (value of the element 'id'):

      It might be helpful if you provide more information about context of the JSONPath expression execution. Where do you call this from, which JSON parser do you use, etc.

      Regards,

      Vadim

  • Aug 10, 2017 at 11:41 AM

    Where are you using xpath? do you want to use it in receiver/interface determination condition?

    if this is your sender payload, then you can convert json to xml to perform xpath condition test.

    Add comment
    10|10000 characters needed characters exceeded