omer khalid
omer khalid

Reputation: 895

How to Get the first value of same element in Json

I want to pick the first value of 'Code' element from following Json Payload. I am using following website to try this out. http://jsonpath.curiousconcept.com/

Json Payload:

   {
    "TotalAccounts": {
        "Account": [
            {
                "Code": 123,
                "Account": {
                    "Name": {
                        "Initials": null
                    },
                    "Address": {
                        "Street": "ABC"
                    }
                },
                "ContactInformation": {
                    "Email": "[email protected]"
                },
                "DunningLevelCode": "R0"
            },
            {
                "Code": 456,
                "Account": {
                    "Name": {
                        "Initials": null
                    },
                    "Address": {},
                    "CustomFields": null
                },
                "ContactInformation": {
                    "Email": "ABC@@gmail.com",
                    "Phone": null,
                    "Mobile": null,
                    "Fax": null
                },
                "DunningLevelCode": "abc"
            }
        ]
    }
}

The Json path i am using is below:

$..Code

Result:

[123,456]

Expected Result:

[123]

Need help.

Upvotes: 0

Views: 42

Answers (1)

Abhishek Mishra
Abhishek Mishra

Reputation: 639

Use this you will get the output

$..Account[0].Code

Upvotes: 1

Related Questions