cancel
Showing results for 
Search instead for 
Did you mean: 

XPATH for the JSON Struture

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (3)

Answers (3)

vadimklimov
Active Contributor

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

Former Member
0 Kudos

Dear Vadim,

I tried "$.data[*].Order.id". It gives me error "invalid JSON path".

Thanks & Regards,

Neelima


vadimklimov
Active Contributor
0 Kudos

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

Former Member

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

Best regards,
Vadym

Muniyappan
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

Dear Muni,

I need to maintain Xpath of json structure in rest sender channel in the field "Unique ID element."

.

In this field, it will accepts only xpath of JSON structure.

Thanks & Regards,

Neelima