- 2 minutes to read

Formula - JsonPathKey

The jsonPathKey Formula function returns the property names (keys), not the values, of the JSON nodes that match a JSONPath expression.

List the property names of the ship-to address with jsonPathKey instead of jsonPath, animated walkthrough (7.12)
Animated walkthrough: on the JSON Order Received event of order ORD-10005 in the Order-to-Cash demo, jsonPath with $.shipTo.* returns the address values; jsonPathKey with the same expression returns the property names zip, country, city, street, and region.

Syntax

jsonPathKey('expression', content)

Parameters

Parameter Required Description
'expression' Yes A JSONPath expression in single quotes that selects the properties whose names you want, such as '$.paths.*' for every property directly under paths.
content Yes The JSON text: body, context, or the result of another function (see Formula language rules).

Returns

The name of every property the expression selects, one value each; duplicates are collapsed. When nothing matches, nothing is returned.

To return the values of the same properties, use jsonPath with the same expression.

Examples

Example 1: List the API paths in a Swagger document

Input

The message body is the OpenAPI 3.0.4 document that the Nodinite Web API publishes at https://<web api>/swagger/v1/swagger.json (shortened here):

{
  "openapi": "3.0.4",
  "info": { "title": "Nodinite.WebAPICore", "version": "1.0" },
  "paths": {
    "/api/ActiveDirectoryGroups": { "get": { "tags": [ "ActiveDirectoryGroups" ] } },
    "...": {}
  }
}

Formula

jsonPathKey('$.paths.*', body)

Result

/api/ActiveDirectoryGroups
/api/ActiveDirectoryGroups/{id}
/api/ActiveDirectoryGroups/GetByFullName
/api/ActiveDirectoryGroups/IsNameAvailable
/api/ActiveDirectoryGroups/{id}/IsNameAvailable
/api/ActiveDirectoryGroups/{id}/Restore
...

Formula jsonPathKey expression returning the API path keys of the Web API OpenAPI document in the Test Expression tab (7.12)
Each key under paths is returned as its own value, in the case the routes are declared; the full 7.12 document gives 735 unique matches.

Example 2: List the fields of an order

Input

{ "order": { "id": "PO-1001", "customer": "ACME", "total": 250 } }

Formula

jsonPathKey('$.order.*', body)

Result

id
customer
total

Formula jsonPathKey returning the property names id, customer, and total of an order in the Test Expression tab (7.12)
$.order.* selects every property directly under order; jsonPathKey returns their names, where jsonPath would return PO-1001, ACME, and 250.

Notes

  • jsonPathKey takes a JSONPath expression, not a regular expression. To filter the returned names by pattern, nest the result in regex, for example regex('^/api/alarms', jsonPathKey('$.paths.*', body)).

Next Steps