Checking the byte length of a JSON document and its string value
The byte count of a JSON document is not the byte count of the string it contains. This worksheet counts the text é three ways: as a bare value, inside quotation marks, and as an escaped spelling.
Which text are you measuring
A byte count belongs to a specific sequence of characters, so the first step is to decide which sequence you mean. The string value é is one character. A JSON document that holds that string has to wrap it in quotation marks, and it may also spell the character as an escape. These are three different pieces of text with three different lengths. The UTF-8 byte length calculator counts the bytes of exactly what you paste, so pasting the value gives one answer, pasting the document gives another, and pasting an escaped spelling gives a third. Choosing among them is a matter of knowing what the receiving system limits. A short list of candidates helps: the decoded value, the document with its quotation marks, the document with escapes, a minified body, and a pretty-printed body. Each has its own count, and the right one is whichever matches the limit you are trying to meet.
The bare value: two bytes
The character é is the Unicode code point U+00E9. UTF-8, defined in RFC 3629, encodes code points from U+0080 to U+07FF in two bytes, so é becomes the bytes C3 and A9 in hexadecimal. The calculator reports 2 bytes for the input é. The characters of plain ASCII text, which covers U+0000 to U+007F, take one byte each, so a string such as abc has 3 bytes while its character count is also 3. The difference between character count and byte count appears as soon as a character outside ASCII shows up, which is why the unit of the limit must be stated. The same value in UTF-16 would take two bytes and in UTF-32 four, so the UTF-8 figure of 2 is a property of that encoding. Seeing the bytes C3 and A9 in a hex view is a quick way to confirm that a file really holds UTF-8 text, since that pair is the standard spelling of the character in the encoding.
Adding the quotation marks
A JSON string literal starts and ends with a double quotation mark. The document containing the literal string é is therefore the three characters quote, é and quote. Each quote is an ASCII character occupying one byte, so the document takes 1 plus 2 plus 1, which is 4 bytes. The calculator confirms 4 for that input. The two extra bytes are syntax. They are not part of the value, and a program that parses the document discards them. A limit on the size of a JSON payload and a limit on the size of a decoded field can therefore disagree by exactly the overhead of such punctuation. A bare object such as the empty braces adds two more bytes, and each member adds its own name, colon and comma. Two more bytes of overhead would appear if the document were wrapped in square brackets as a one-element array, which shows how structure accumulates.
The escaped spelling
JSON lets any character in the Basic Multilingual Plane be written as backslash, the letter u, and four hexadecimal digits. The character é can appear as the six characters backslash u 0 0 E 9. Wrapped in quotes the document has eight characters, all of them ASCII, so it takes 8 bytes. The decoded value is still the single character é, which has 2 bytes as plain UTF-8. The escaped form is four times the size of the value in this case, and double the size of the unescaped document. Escaping is a choice made by the software that writes the document, and it changes the size on the wire without changing the data. Some serializers write the hexadecimal digits in uppercase and others in lowercase, so the same escape can appear as 00E9 or 00e9. Both are valid and both have the same length.
Why writers choose escapes
Different serializers make different choices. Some write non-ASCII characters directly, producing compact UTF-8 output. Others escape every non-ASCII character to keep the document pure ASCII, which can be useful for systems that mishandle encodings. Some escape only control characters, the quotation mark and the backslash, as the JSON specification requires. The same data can therefore produce documents of different sizes depending on the library and its settings. When a size limit is close, test with the actual output of the actual serializer and not with a hand-built sample. Escaping protects against encoding mistakes in transit, and the price is the extra bytes counted in the third worksheet case.
Characters beyond the Basic Multilingual Plane
A character above U+FFFF, such as many emoji, takes four bytes in UTF-8. Written as an escape in JSON it needs a surrogate pair, two six-character sequences such as backslash uD83D followed by backslash uDE00, which spell one emoji. That is 12 characters, or 14 bytes with the quotation marks, for a value that takes 4 bytes as UTF-8. The ratio between the escaped form and the value grows in such cases. JavaScript also counts string length in UTF-16 code units, so the same emoji has a length of 2 in a script, 4 bytes in UTF-8 and 12 characters in escaped form. Three different numbers describe one character. If you must stay within a byte budget, remember that a few emoji in a text field can use more bytes than a whole line of ordinary letters.
The layer a limit applies to
Real systems state limits in different layers. A web server may cap the size of a request body, which is the serialized document in bytes. A database column may cap the length of a text field in bytes or in characters, depending on the engine and its settings. A message queue may limit the whole message including metadata. To compare a count with a limit, find out which layer the limit measures, then measure that layer. The worksheet counts of 2, 4 and 8 are all correct. They answer three different questions, and only one of them matches any given limit. When documentation is vague, send a test payload near the limit and observe where it fails.
A longer example
Consider the JSON document consisting of the string Café menu. The value has 9 characters, and one of them, é, takes two bytes, so the value occupies 10 bytes in UTF-8. With quotation marks the document has 12 bytes. If a serializer escapes the é, the document becomes the characters quote, C, a, f, backslash, u, 0, 0, E, 9, space, m, e, n, u, quote, which is 16 bytes. The value is the same in all three forms. The example is illustrative and shows how a single accented letter can move a total by several bytes. Longer text with more accents multiplies the effect. The same sentence in Cyrillic or Greek letters would take two bytes per letter, and many East Asian characters take three, so a text of the same character count can differ in size by a factor of three.
Whitespace and structure
The worksheet documents are single strings, but real payloads are objects and arrays. Every brace, bracket, colon, comma and quotation mark adds to the byte count, and pretty-printing adds spaces, tabs and newlines on top. A line break is a single byte as a character, yet a document that uses carriage return and line feed together spends two. Counting a prettified file therefore gives a larger number than counting its minified form, even though they parse to identical data. If a limit applies to what travels over the network, measure the form actually sent. A short object with two members, such as one holding a name and an age, already includes two pairs of quotation marks for the names, a colon for each, and a comma between them.
Other encodings change the count
All of these counts assume UTF-8, which RFC 8259 requires for JSON exchanged between systems that are not part of a closed ecosystem. If the same text were encoded as UTF-16, the character é would take two bytes and an ASCII character would also take two, so the document in quotes would take 6 bytes. A legacy single-byte encoding such as ISO 8859-1 would store é in one byte. Always state the encoding along with the count, because the number alone is ambiguous. The calculator counts UTF-8 bytes, and the guide figures follow it. When data cross systems, check the declared encoding in headers or file metadata, since a mismatch produces garbled characters and incorrect counts.
Practical habits
Measure the exact string that will be sent or stored, using a count of bytes in UTF-8 and not a count of characters. Record which layer the number describes, such as the decoded field or the serialized body. Keep a margin below any hard limit, since a change in serializer settings can alter the size. When a payload sits near the limit, consider whether escaping can be turned off, whether whitespace can be removed, or whether the data should be sent another way. The three numbers on this page show the size of the gap that these choices control. Keep the original, unmodified document too, so that a count can be repeated later if the question changes. A habit worth adding is to log the byte length of outgoing payloads in production, so growth is visible well before a limit is reached.
Checking a count against a limit
Suppose a service accepts request bodies up to 1,000 bytes and a field holds 300 accented characters, each taking two bytes in UTF-8. The value alone takes 600 bytes, which looks safe. A serializer that escapes non-ASCII characters writes each one as six ASCII characters, so the same field takes 1,800 bytes, and the request fails. The text is identical in both cases. Only the spelling differs. Pasting the real serialized body into the byte length calculator reveals this before a failure occurs. It also shows how little can be inferred from a character count, which is 300 for the value, 302 with quotation marks and 1,802 for the escaped form.
Reproduce the checks
Decoded string-value bytes
Open the Utf8 Byte Length Calculator and enter:
- Text or encoded input
é
Expected output:
Bytes
2Only the value is supplied.
Literal JSON document bytes
Open the Utf8 Byte Length Calculator and enter:
- Text or encoded input
"é"
Expected output:
Bytes
4The document includes its quotation marks.
Escaped JSON document bytes
Open the Utf8 Byte Length Calculator and enter:
- Text or encoded input
"\u00E9"
Expected output:
Bytes
8The source escape spelling is six ASCII characters inside two quotes.
References and implementation scope
The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.
Sources
- Primary definition and convention reference ↗ · 2026-10-08