When using API error Troubleshooting Details, you can get more flexibility in the data points you want to leverage, by collecting specific elements of the request or response body in JSON format, by using JSON Path.
JSON Path is a powerful query language used to navigate and extract data from JSON structures. However, in its application for Body elements, we have applied limitations on the use of certain JSON Path operators. This article will guide you through using JSON Path with a restricted set of operators.
Available Operators
Here is the list of available JSON Path operators:
Operator | Description |
.<name> | Dot-notated child: Use the dot notation to access child elements of an object. |
['<name>'] | Bracket-notated child: Use the bracket notation to access the child element. |
[<number>] |
Array index: Use the array index. |
Limits
- The root operator $ is not needed: You can optionally specify the root element to query, although this is not required.
- Accessing multiple elements with multiple names within an array is not allowed.
- Accessing multiple elements with multiple indexes within an array is not allowed.
Operators not available: Filter expressions, array slices, deep scans, current nodes, and wildcards.
Additionally, you are not allowed to use any of the JSON Path functions or filter operators.
By understanding the available operators and their usage, you can effectively navigate and extract data from your JSON structures, even with the provided limitations.
Example
Let's explore how you can use these operators for the following example:
{ "errors": [ { "message": "The account sign-in was incorrect or your account is disabled temporarily. Please wait and try again later.", "extensions": { "category": "graphql-authentication" }, "locations": [ { "line": 2, "column": 3 } ], "path": [ "generateCustomerToken" ], "code": 10005 } ], "data": { "generateCustomerToken": null, "emailAddressCheck": "valid", “emailAddress”: “bob@contentsquare.com” }
JsonPath | Status | Returned result |
errors[0].message | ✅ | “The account sign-in was incorrect or your account is disabled temporarily. Please wait and try again later.” |
errors[0].extensions.category | ✅ | “graphql-authentication” |
data.emailAddressCheck | ✅ | “valid” |
data[“emailAddressCheck”] | ✅ | “valid” |
data.emailAddress | ✅ | “name@contentsquare.com” |
errors | ❌ | “N/A” (errors is an array and only a string value can be returned) |
errors.message | ❌ | “N/A” (“errors” is an array) |
data[0] | ❌ | “N/A” (“data” element is not an array) |