- 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.

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 a Swagger 2.0 document (shortened here):

{"swagger":"2.0","info":{"version":"V1","title":"Nodinite WebAPI","x-swagger-net-version":"8.3.38.001"},"host":"localhost","basePath":"/Nodinite/Dev/WebAPI","schemes":["http"],"paths":{"/api/activedirectorygroups":{"get":{"tags":["ActiveDirectoryGroups"],"summary":"Get a list of Active Directory Groups, limited by specified input","operationId":"ActiveDirectoryGroups_List"}}, "...": {}}}

Formula

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

Result

/api/activedirectorygroups
/api/activedirectorygroups/{id}
/api/activedirectorygroups/{id}/isnameavailable
/api/activedirectorygroups/{id}/restore
/api/activedirectorygroups/getbyfullname
...

Formula jsonPathKey expression returning the API path keys of a Swagger document in the Test Expression tab
Each key under paths is returned as its own value; the full document gives 341 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
$.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