Searching for a specific config item validity using JSON path can be achieved by specifying the key name condition. This process works seamlessly on platforms like , accurately extracting the desired value:
https://i.sstatic.net/2ffAAnNM.png
In Typescript, the code implementation would look something like this:
import * as jsonpathPlus from 'jsonpath-plus';
const key = "configTwoEnabled"
const configCurrentValue = jsonpathPlus.JSONPath({ path: `$.featureSwitches[?(@.key == "${key}")]`, json: jsonResponse })[0];
However, there might be instances where the JSON response may not return expected results. For example, querying with just $.
retrieves all values but adding featureSwitches
path could result in no output. Here's an illustrative snippet of the sample JSON structure:
{
"featureSwitches": [
{
"key": "configOneEnabled",
"isEnabled": true
},
{
"key": "configTwoEnabled",
"isEnabled": true
},
{
"key": "configThreeEnabled",
"isEnabled": true
},
{
"key": "configFourEnabled",
"isEnabled": false
},
{
"key": "configFiveEnabled",
"isEnabled": true
}
]
}