cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Jsonpath to get value with @

walkerline117
Contributor

I have below json body, how would I use jsonpath in a mapper to get all 'nameโ€™s?
Its easier for me if the json have โ€˜nameโ€™ instead of โ€˜@nameโ€™โ€ฆ

Not sure how to get all those values in a mapper

{
โ€œresponseโ€:
{
โ€œlstโ€:[
{
@โ€œnameโ€:โ€œtermsโ€,โ€œlstโ€:{โ€œ@nameโ€:โ€œuser_queryโ€,โ€œintโ€:[
{โ€œ@nameโ€:โ€œsolar energyโ€,โ€œ$โ€:โ€œ4651โ€},
{โ€œ@nameโ€:โ€œscriptโ€,โ€œ$โ€:โ€œ1993โ€},
{โ€œ@nameโ€:โ€œscenario planningโ€,โ€œ$โ€:โ€œ641โ€},
{โ€œ@nameโ€:โ€œstrategy under uncertainty frameworkโ€,โ€œ$โ€:โ€œ627โ€},
{โ€œ@nameโ€:โ€œsmed gameโ€,โ€œ$โ€:โ€œ601โ€},
{โ€œ@nameโ€:โ€œspecialty pharmaโ€,โ€œ$โ€:โ€œ458โ€},
{โ€œ@nameโ€:โ€œspecialty pharmaceuticalโ€,โ€œ$โ€:โ€œ446โ€},
{โ€œ@nameโ€:โ€œspecialty careโ€,โ€œ$โ€:โ€œ444โ€},
{โ€œ@nameโ€:โ€œsupply chainโ€,โ€œ$โ€:โ€œ406โ€},
{โ€œ@nameโ€:โ€œsapโ€,โ€œ$โ€:โ€œ310โ€}]}}
]
}
}

Thanks

1 ACCEPTED SOLUTION

tstack
Former Employee

Iโ€™m not quite sure what youโ€™re asking, can you give an example of the output you want?

If youโ€™re asking how to reference a field with a special character, like the @ symbol, you can quote it like so:

['@name']

If you want to collect all the โ€˜@nameโ€™ values at any level, you can do:

jsonPath($, "$..['@name']")

That will return a list containing all the values.

View solution in original post

6 REPLIES 6

tstack
Former Employee

Iโ€™m not quite sure what youโ€™re asking, can you give an example of the output you want?

If youโ€™re asking how to reference a field with a special character, like the @ symbol, you can quote it like so:

['@name']

If you want to collect all the โ€˜@nameโ€™ values at any level, you can do:

jsonPath($, "$..['@name']")

That will return a list containing all the values.

Thanks
is there a tool that can help us to debug such jsonpath expression, i have tried @name in http://jsonpath.com/
However, such @name is not valid in this website.

I use this one: http://www.jsonquerytool.com/

{
โ€œresponseโ€: {
โ€œlstโ€: [{
โ€œ@nameโ€: โ€œtermsโ€,
โ€œlstโ€: {
โ€œ@nameโ€: โ€œuser_queryโ€,
โ€œintโ€: [{
โ€œ@nameโ€: โ€œsolar energyโ€,
โ€œ$โ€: โ€œ4651โ€
}, {
โ€œ@nameโ€: โ€œscriptโ€,
โ€œ$โ€: โ€œ1993โ€
}, {
โ€œ@nameโ€: โ€œscenario planningโ€,
โ€œ$โ€: โ€œ641โ€
}, {
โ€œ@nameโ€: โ€œstrategy under uncertainty frameworkโ€,
โ€œ$โ€: โ€œ627โ€
}, {
โ€œ@nameโ€: โ€œsmed gameโ€,
โ€œ$โ€: โ€œ601โ€
}, {
โ€œ@nameโ€: โ€œspecialty pharmaโ€,
โ€œ$โ€: โ€œ458โ€
}, {
โ€œ@nameโ€: โ€œspecialty pharmaceuticalโ€,
โ€œ$โ€: โ€œ446โ€
}, {
โ€œ@nameโ€: โ€œspecialty careโ€,
โ€œ$โ€: โ€œ444โ€
}, {
โ€œ@nameโ€: โ€œsupply chainโ€,
โ€œ$โ€: โ€œ406โ€
}, {
โ€œ@nameโ€: โ€œsapโ€,
โ€œ$โ€: โ€œ310โ€
}
]
}
}
]
}
}

And use this: $[@name] or $.[@name]

thank you for your information