How to convert key Value as case insensitive in the extract variable policy json payload
$.keys[?(@.keyValue==‘ABC’)].keyValue[0]
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]));
}