GetJsonValue
The GetJsonValue function receives two input parameters: a JSON object, and a string specifying the desired path within the JSON. This function takes the provided JSON and attempts to retrieve the value located at the specified path. If the path exists and a valid value is found, the function returns that value. However, if the path cannot be found, or if any parsing errors occur during the process (e.g., invalid JSON syntax), the function returns NULL as a result. This ensures safe handling of input data and provides a consistent response when encountering issues with the JSON structure or path.
Syntax
GetJsonValue(JSON Object, JSON path string)
Example
Assuming we have the following JSON that is saved in the context under the variable name ‘studentsList’:
{ "name": "John Doe", "age": 30, "still.student": false, "address": { "street": "123 Main Street", "city": "Anytown", "state": "CA" }, "friends": [{ "name": "Alice", "age": 28 }, { "name": "Bob", "age": 32 } ] }
To get the value from the key that called "name", use the function as follows:
GetJsonValue(${studentsList},"name")-> returns 'Jhon Doe'
To get the value from the key that called "city", use the function as follows:
GetJsonValue(${studentsList},"address.city")-> returns 'Anytown'
To get the value from the key that called "age" that associated to Alice, use the function as follows:
GetJsonValue(${studentsList},"friends[0].age")-> returns '28'
To get the value from the key that called "still.student", use the function as follows:
GetJsonValue(${studentsList},"[still.student]")-> returns 'false'