JSON Dependent Key Presence Check

Audit own-member dependencies when a trigger exists, including a null trigger value; do not infer semantic value requirements.

Description

Audit own-member dependencies when a trigger exists, including a null trigger value; do not infer semantic value requirements.

A dependent-key rule requires certain keys only when a trigger key is present. Presence is different from truthiness.

When to use this tool

Audit own-member dependencies when a trigger exists, including a null trigger value; do not infer semantic value requirements.

  • Prepare the supplied objectJson, triggerKey, requiredKeys fields for this operation.
  • Compare the complete example with the representation used by your own input before carrying the result into another step.

How to use the tool and how it works

  1. Enter objectJson, triggerKey, requiredKeys. Use the exact text syntax, units and index conventions explained below.
  2. Run the tool. If input validation fails, correct the supplied fields before interpreting any result.
  3. Read result.triggerPresent, result.missingRequiredKeys, result.passes. Interpret false, null and empty lists using the distinctions below; they can be valid outputs.

Require a nonempty list of unique nonblank requiredKeys, parse objectJson as an object and test own-key presence. If triggerKey exists, return missing required keys and passes only when none are missing; otherwise pass with an empty missing list.1

Input fieldMeaning and representationAccepted input
objectJsonJSON text, entered as one text field. The decoded structure is illustrated below; it is not a separate file.Text
triggerKeytrigger key.Text; at most 8,192 UTF-16 code units, subject to the grammar above
requiredKeysrequired keys.At most 128 strings, each at most 128 UTF-16 code units

For the JSON text fields, the following decoded structures show the example records before they are serialized into input strings. Keep field names, list nesting and value types as shown.

json
[
  {
    "field": "objectJson",
    "decoded": {
      "a": null
    }
  }
]
Output fieldInterpretation
resultObject containing the named outputs below.
result.triggerPresentFlag for trigger present under the exact condition described above.
result.missingRequiredKeysThe missing required keys list in the ordering and representation described above.
result.passesFlag for passes under the exact condition described above.
json
{
  "input": {
    "objectJson": "{\"a\":null}",
    "triggerKey": "a",
    "requiredKeys": [
      "b"
    ]
  },
  "output": {
    "result": {
      "triggerPresent": true,
      "missingRequiredKeys": [
        "b"
      ],
      "passes": false
    }
  }
}

Limitations and assumptions

  • Null, false and empty values still count as present. No property-value schema, nested dependency or full JSON Schema validation occurs.
  • Every declared top-level field is required and unexpected fields are rejected. Numeric inputs must be finite; ordinary text fields are bounded to 8,192 UTF-16 code units, with tighter operation-specific limits where stated.
  • String lists have at most 128 entries of at most 128 code units; matrices have at most 128 rows and columns. Larger numeric lists and parsed JSON have separate bounded budgets. Nonfinite results and excessively large serialized outputs are rejected.
  • Indexes are zero-based and spans have an exclusive end unless explicitly stated otherwise. A valid false, null or empty-list result is distinct from malformed input.

Alternative or Complementary methods

Use a full schema validator when several shape, type and value constraints must work together. These tools apply the one declared presence, name, length or leaf policy and return explicit evidence of its scope.

References

  1. Tool behavior and example: JSON Dependent Key Presence Check — tool.io

Similar or alternative tools

Don't forget to set a bookmark for tool.io!
Privacy | Imprint | Cookies