jsonPath

Description: The jsonPath function generates a string by evaluating the Subject as JSON and applying a JSON path expression. An empty string is generated if the Subject does not contain valid JSON, the jsonPath is invalid, or the path does not exist in the Subject. If the evaluation results in a scalar value, the string representation of scalar value is generated. Otherwise a string representation of the JSON result is generated. A JSON array of length 1 is special cased when [0] is a scalar, the string representation of [0] is generated.

Subject Type: String

Arguments: jsonPath : the JSON path expression used to evaluate the Subject.

Return Type: String

Examples: If the "myJson" attribute is


{
  "firstName": "John",
  "lastName": "Smith",
  "isAlive": true,
  "age": 25,
  "address": {
    "streetAddress": "21 2nd Street",
    "city": "New York",
    "state": "NY",
    "postalCode": "10021-3100"
  },
  "phoneNumbers": [
    {
      "type": "home",
      "number": "212 555-1234"
    },
    {
      "type": "office",
      "number": "646 555-4567"
    }
  ],
  "children": [],
  "spouse": null
}

Expression

Value

${myJson:jsonPath('$.firstName')}

John

${myJson:jsonPath('$.address.postalCode')}

10021-3100

${myJson:jsonPath('$.phoneNumbers[?(@.type=="home")].number')}

212 555-1234

${myJson:jsonPath('$.phoneNumbers')}

[{"type":"home","number":"212 555-1234"},{"type":"office","number":"646 555-4567"}]

${myJson:jsonPath('$.missing-path')}

empty

${myJson:jsonPath('$.bad-json-path..')}

exception bulletin

An empty subject value or a subject value with an invalid JSON document results in an exception bulletin.