Minify JSON Without Changing Large Numbers
Choose minified output and turn off the final newline if every byte matters. The tool validates the full JSON grammar, removes whitespace only where the grammar permits it, and writes number tokens exactly as they appeared instead of converting them through floating-point arithmetic.
A UTF-8 JSON document up to 25 MB. Its bytes stay in this browser tab.
Results are provided as-is, with no warranty of accuracy. The method and its sources are published below so you can check the working.
Spaces, tabs and line breaks inside quoted strings are data and are never removed.
A value such as 9007199254740993 stays spelled exactly that way.
The minified result is a new local file; the original is not modified.
How it works
How it is done
- Read the file as strict UTF-8. Accept and consume an initial UTF-8 byte-order mark for compatibility, but do not write one into the result.
- Validate the complete document as one RFC 8259 JSON value before producing an artifact. Refuse an empty file, invalid UTF-8, trailing content or malformed objects, arrays, strings, numbers and literal names.
- Scan the validated source while tracking quoted strings and backslash escapes. Inside a string, copy every code unit exactly; outside a string, discard only space, tab, carriage return and line feed.
- For readable output, insert the selected indentation after an opening container and comma, one space after a colon, and a correctly indented line before a non-empty closing container. For minified output, insert no optional whitespace.
- Encode the rewritten text as UTF-8, add one final line feed only when selected, and offer a new .json file. Never parse number tokens into floating-point values for output.
What it assumes
- Formatting is not canonicalisation. Object member order, duplicate names, number spelling and string escape choices stay as authored even where another parser might normalise or collapse them.
- JSON exchanged between independent systems is UTF-8 under RFC 8259. UTF-16 and legacy code pages belong in the separate text-encoding converter before this grammar is applied.
- The native JSON parser is used as a strict grammar validator only. The downloadable bytes come from a token-preserving scan of the original text, not from JSON.stringify.
- Input is capped at 25 MB. The rewrite yields every 250,000 characters so progress and Cancel remain responsive; native validation itself is intentionally left to the browser's optimised parser.
Common questions
Will the minifier remove spaces from a JSON string?
No. It tracks quoted strings and escape sequences, and removes whitespace only while outside a string.
Why validate before removing whitespace?
A byte-rewriter can otherwise produce a smaller file that is still invalid. Validation ensures the complete source is one JSON value with correct strings, numbers, arrays and objects before anything is offered for download.
Sources
The full method, worked example and every assumption behind this figure are on JSON Formatter.