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
- Enter value. Use the units and conventions below.
- Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
- 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 field | Meaning and units | Accepted input |
|---|---|---|
| value | Value | Required. Text; maximum UTF-16 length 8192. |
| Output field | Interpretation | Returned shape |
|---|---|---|
| sourceCodeUnits | Source Code Units | Required. Safe integer. |
| escapedCodeUnits | Complete JSON string-literal length in UTF-16 units, including two outer quotation marks. | Required. Safe integer. |
| overhead | Overhead | Required. Safe integer. |
{
"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
Similar or alternative tools
- JSON String Escape Length One Codepoint
Validate point as a Unicode scalar and count its JSON string content units without outer quotes.
- JSON String Utf16 Unit Count
Parse jsonString, require a string value, and return its decoded JavaScript length as utf16Units.