JSON text and transport bytes are separate representations. Encode the text as UTF-8 before measuring or sending a byte payload.
Worked example
const record = { title: "Café", copies: 20 };
const bytes = new TextEncoder().encode(JSON.stringify(record));
console.log(JSON.parse(new TextDecoder().decode(bytes)));Result
{ title: 'Café', copies: 20 }Implementation notes
Measure a byte limit after encoding. Counting UTF-16 units can allow a payload to exceed a transport quota even when the string length looks safe.
Try it yourself
Compare string length with byte length for an accented character.
Open the JavaScript example →Editorial date September 17, 2026 · Published December 6, 2026