Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to convert json path condition as case insensitive in extract variable policy

How to convert key Value as case insensitive in the extract variable policy json payload
<Variable name="keyValue"> <JSONPath>$.keys[?(@.keyValue=='ABC')].keyValue[0]</JSONPath>

Solved Solved
0 3 3,814
1 ACCEPTED SOLUTION

I think you want to get the element text, when an attribute on the parent case-insensitively matches a specific value.

And JsonPath doesn't do that. Not in Apigee, not in any JsonPath implementation, as far as I know.

So the way to do the extraction, is to use JavaScript. If you show me an example JSON , I can show you a JS that will extract the value you want. Or you can sort of explore yourself by checking out prior examples that reference JSON here on community.

View solution in original post

3 REPLIES 3

I think you want to get the element text, when an attribute on the parent case-insensitively matches a specific value.

And JsonPath doesn't do that. Not in Apigee, not in any JsonPath implementation, as far as I know.

So the way to do the extraction, is to use JavaScript. If you show me an example JSON , I can show you a JS that will extract the value you want. Or you can sort of explore yourself by checking out prior examples that reference JSON here on community.

Thanks @Dino-at-Google
<JSONPayload>
        <Variable name="keyValue">
            <JSONPath>$.keys[?(@.keyValue=='ABC')].keyValue[0]</JSONPath>
        </Variable>
 </JSONPayload>

Request: {"keys": [ { "keyValue": "abc", "keyName": "programName" } ] }<br>I'm trying here to extract keyValue when json path matches and want condition to be case insensitive.<br>

I think you want something like this:

var valueToFind = 'ABC';
var payload = JSON.parse(context.getVariable('request.content'));

function matchCaseInsensitive(needle) {
  needle = needle.toLowerCase();
  return function (item) {
    return item.keyValue.toLowerCase() == needle;
  };
}


var found = payload.keys.filter(matchCaseInsensitive(valueToFind));

if (found.length) { 
  context.setVariable('foundKey', JSON.stringify(found[0]));
}