Skip to Content
0

XPATH for the JSON Struture

Aug 10, 2017 at 11:11 AM

113

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

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

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

Best regards,
Vadym

Share
10 |10000 characters needed characters left characters exceeded
Vadim Klimov Aug 10, 2017 at 01:16 PM
1

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

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Dear Vadim,

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

Thanks & Regards,

Neelima


0

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

0
Muniyappan Marasamy Aug 10, 2017 at 11:41 AM
0

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.

Show 1 Share
10 |10000 characters needed characters left characters exceeded

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


capture.png (6.8 kB)
0