JSON Pointer Array Index Token Check

Audit a decoded JSON Pointer array index token: canonical decimal, safe integer, in-range and optional append marker are distinct checks.

Description

Audit a decoded JSON Pointer array index token: canonical decimal, safe integer, in-range and optional append marker are distinct checks.

A JSON Pointer token identifies an array element only when its spelling is a canonical nonnegative decimal index. An append marker is a separate application choice.

When to use this tool

Audit a decoded JSON Pointer array index token: canonical decimal, safe integer, in-range and optional append marker are distinct checks.

  • Prepare the supplied token, arrayLength, allowAppend 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 token, arrayLength, allowAppend. 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.canonicalIndex, result.safeIndex, result.withinArray, result.appendAllowed. Interpret false, null and empty lists using the distinctions below; they can be valid outputs.

Test token against zero or a nonzero digit followed by digits, then require a JavaScript safe integer. Return its numeric index when representable, whether it is below arrayLength, and whether the exact token "-" is allowed by allowAppend.1

Input fieldMeaning and representationAccepted input
tokentoken.Text; at most 8,192 UTF-16 code units, subject to the grammar above
arrayLengtharray length.Integer from 0 to 1e9 inclusive
allowAppendExplicit choice for allow append; supply a boolean rather than a text label.true or false
Output fieldInterpretation
resultObject containing the named outputs below.
result.canonicalIndexFlag for canonical index under the exact condition described above.
result.safeIndexRepresentable canonical array-index token as a number, or null when the token is not such an index.
result.withinArrayFlag for within array under the exact condition described above.
result.appendAllowedWhether token is exactly "-" and the caller enabled append; independent of existing-element membership.
json
{
  "input": {
    "token": "01",
    "arrayLength": 3,
    "allowAppend": true
  },
  "output": {
    "result": {
      "canonicalIndex": false,
      "safeIndex": null,
      "withinArray": false,
      "appendAllowed": false
    }
  }
}

Limitations and assumptions

  • Leading zeros, signs and whitespace are not canonical indexes. The append marker does not identify an existing element. This checks one token against a supplied length, without resolving a document.
  • Decoded JSON is bounded to 20,000 nodes and 32 nesting levels; record arrays have at most 128 records. Parsed number values use JavaScript floating point rather than arbitrary-precision decimal arithmetic.
  • 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.
  • Ordinary string lists have at most 128 entries of at most 128 code units each; numeric lists and matrices have separate bounded size checks. 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

For document-wide requirements, combine these structural inventories with an explicit JSON Schema. Preserve the distinction between missing properties and null values, and between numbers and numeric-looking strings when building joins or indexes.

References

  1. Tool behavior and example: JSON Pointer Array Index Token Check — tool.io

Similar or alternative tools

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