Skip to content

Main content

JSON String Utf16 Unit Count Tool

Count UTF-16 code units in one decoded JSON string literal.

Loading tool…

Description

Parse jsonString, require a string value, and return its decoded JavaScript length as utf16Units.

JSON strings use escape syntax, while decoded JavaScript strings are sequences of UTF-16 units. A supplementary Unicode scalar occupies a surrogate pair, and a lone surrogate is not a complete scalar.

Parse jsonString, require a string value, and return its decoded JavaScript length as utf16Units.

When to use this tool

Use JSON String Utf16 Unit Count when you need a decoded UTF-16 or normalization diagnostic.

How to use the tool and how it works

  1. Enter jsonString. 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 utf16Units. Use the output convention below.

Parse jsonString, require a string value, and return its decoded JavaScript length as utf16Units.1

Input fieldMeaning and unitsAccepted input
jsonStringJson StringRequired. Text; maximum UTF-16 length 8192.
Output fieldInterpretationReturned shape
utf16UnitsUtf16 UnitsRequired. Safe integer.
json
{
  "input": {
    "jsonString": "\"A🚀\""
  },
  "output": {
    "utf16Units": 3
  }
}

Limitations and assumptions

  • The count excludes JSON quotes and escape spelling; supplementary characters occupy two UTF-16 units.
  • 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

Use Unicode-aware text processing and a full JSON parser when decoding, comparing, or repairing complete documents.

References

  1. Calculation and input contract: json/json-string-utf16-unit-count — tool.io

Similar or alternative tools