Unable to use JsonPath expressions with filters

I am trying to use a JSONPath expression which has filter expressions. I validated the JSONPATH online using a online validator and itโ€™s correct but upon using the same in the postman I get a syntax error. Not sure what I am doing wrong and I am unable to find any info or posts regrading the same.
Here is line of code where I am trying to store the NAME of the player whose ID is โ€˜56782โ€™.
Note: The response I receive is in XML and PLAYERS is an array.

var responseJson = xml2Json(responseBody);
var JuniorLeaguePlayer = responseJson.RSP.ACTIVE.PLAYERS[?(@.ID=="56782")].NAME;

You do realize that you are in a JavaScript context, working with objects and arrays. Not sure how this can work.

Hi,
you can try to put it into a new array, maybe it will be useful.
pm.test(โ€˜Check of nameโ€™, () => {

let jsonData = xml2Json(responseBody),

    names= [];



_.each(jsonData, (item) => {

    if(item.RSP.ACTIVE.PLAYERS.ID=== '56782') {

        names.push(item.RSP.ACTIVE.PLAYERS.ID.NAME);

        console.log(names);

    }

});
1 Like