Compress a JSON Event Without Changing Its Digits
Admin ·
A JSON event can carry an ID longer than JavaScript’s safe integer range. If you only need a smaller artifact, keep the original tokens through compression so a reader with the right numeric type can still read the exact ID.
Keep the event’s original 110 bytes
Load the example, leave Minify before compression off, and compress. Input and UTF-8 payload both show 110 bytes. The source includes the ID 9007199254740993, the literal exponent spelling 1.2300e+4 and two spaces between Café and open.
Download document.json.gz. A tiny sample can grow because GZIP needs its own header and trailer. Compare the compressed size and the UTF-8 payload size before assuming one is smaller.
RFC 8259, JSON syntax and interoperabilityRFC 1952, GZIP members and checksums
Compare the 92-byte compact payload
Select Minify before compression and compress again. The 92-byte payload has no inter-token spaces or line breaks. The two spaces in the message, the exact integer and exponent, and the source escape for the coffee symbol remain.
When a supplied file begins with a UTF-8 BOM, original-byte compression retains it and minification removes it. The JSON check accepts a leading BOM for existing files. RFC 8259 describes the interoperability rule for generating networked JSON.
RFC 8259, JSON syntax and interoperabilityRFC 1952, GZIP members and checksums
Extract the file and inspect the JSON as text
Select Use output to extract, then Extract GZIP. Open the restored document.json as UTF-8 text. The compact example contains the original numeric tokens and string escapes. Use a parser with an exact integer or decimal representation if you need to compare their numeric values.
For an exact original round trip, repeat with minification off and compare the extracted file’s bytes with the source. A syntax error blocks compression. Corrupt archives and content over the expansion limit block extraction.
RFC 8259, JSON syntax and interoperabilityWHATWG Compression Standard, supported formats
Common questions
Can I minify and then recover the original indentation?
Extraction restores the compressed payload. Use original-byte compression to keep indentation and line endings.
Does JSON have to be an object for this workflow?
The syntax check accepts a single JSON value, such as an array, scalar or object.