Skip to content

Main content

JSON String Escape Length Budget Tool

Calculate json string escape length budget from explicit caller-supplied inputs.

Loading tool…

Description

Serialize value as a JSON string and return source UTF-16 length, complete serialized length, and their difference as overhead.

A JSON lexeme is its textual spelling, which differs from the decoded value. Escapes, quotes, raw control characters, and surrounding whitespace must be interpreted in context.

Serialize value as a JSON string and return source UTF-16 length, complete serialized length, and their difference as overhead.

When to use this tool

Use JSON String Escape Length Budget when you need a narrowly defined JSON string or separator diagnostic.

How to use the tool and how it works

  1. Enter value. Use the units and conventions below.
  2. Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
  3. Read sourceCodeUnits, escapedCodeUnits, overhead. Use the output convention below.

Serialize value as a JSON string and return source UTF-16 length, complete serialized length, and their difference as overhead.1

Input fieldMeaning and unitsAccepted input
valueValueRequired. Text; maximum UTF-16 length 8192.
Output fieldInterpretationReturned shape
sourceCodeUnitsSource Code UnitsRequired. Safe integer.
escapedCodeUnitsComplete JSON string-literal length in UTF-16 units, including two outer quotation marks.Required. Safe integer.
overheadOverheadRequired. Safe integer.
json
{
  "input": {
    "value": "a\nb"
  },
  "output": {
    "sourceCodeUnits": 3,
    "escapedCodeUnits": 6,
    "overhead": 3
  }
}

Limitations and assumptions

  • The serialized count includes both quotation marks; this is not a UTF-8 byte-size calculation.
  • Inputs must satisfy both the field types and the cross-field conditions above. Invalid input causes an error; a successful false flag or documented placeholder is a different result.

Alternative or Complementary methods

Parse the entire document when validity matters; a local pattern match cannot establish complete JSON syntax.

References

  1. Calculation and input contract: json/json-string-escape-length-budget — tool.io

Similar or alternative tools