Make conditional changes

As detailed in the sections above, you can incorporate conditional tests into your initial JSONPath expression. But in many cases you can offload that conditional logic to execute as part of the patch.

For example, you can use this simple expression to match all origin behaviors' originCertificate option values, regardless of whether the certificate string is empty:

$..behaviors[?(@.name == 'origin')].options.originCertificate

To test for empty values, place an initial test patch before the patch that executes the replace operation. This example tests to make sure the matched value is blank, then assigns a certificate only if that condition is met:

{
  "patchPropertyVersions": [
    {
      "propertyId": "prp_123456",
      "propertyVersion": 4,
      "patches": [
        {
          "op": "test",
          "value": "",
          "path": "/rules/behaviors/0/options/originCertificate"
        },
        {
          "op": "replace",
          "value": "-----BEGIN CERTIFICATE-----\nMIIFH ... b+kIw==\n-----END CERTIFICATE-----\n",
          "path": "/rules/behaviors/0/options/originCertificate"
        }
      ]
    }
  ]
}

When including test operations within patches, as long as the path expression is a valid JSON Pointer location, the bulk update succeeds regardless of whether the replace operation executes.