logo
GeekFormat

JSON Compress

Free online JSON compression tool supporting single-line compact JSON minification, JSON Escape/Unescape, built-in smart syntax repair that automatically handles trailing commas and other common errors, real-time compression ratio display, CodeMirror editor with keyboard shortcuts, pure frontend processing.

Related

Use Cases

  • Compress JSON request/response bodies in API development to reduce HTTP transmission bytes and improve API response speed (especially on mobile weak networks)
  • Minify frontend JSON configuration files, i18n language packs, and Mock data before deployment to reduce static resource size
  • Escape JSON objects into string literals for embedding in unit test code, Postman/curl commands
  • One-click Unescape escaped JSON copied from logs (like \"key\":\"value\") into readable JSON
  • Batch repair JSON files with syntax errors like trailing commas and single quotes, converting to valid JSON in one click
  • Compress formatted JSON to single line and paste into command-line arguments or chat tools for sharing

Features

  • Three-in-one: JSON compact compression + Escape + Unescape, covering size reduction, code string embedding, and escape restoration scenarios
  • Smart syntax repair: Built-in tryFixJSON engine automatically detects and fixes trailing commas, single quotes, comments, unclosed quotes, and other common JSON errors
  • CodeMirror editor: Dual-pane layout with input on the left and results on the right, supporting JSON syntax highlighting, draggable divider, font size adjustment
  • Real-time compression stats: Status bar instantly shows original size (Bytes/KB/MB), compressed size, and precise compression ratio percentage
  • Keyboard shortcuts: Shift+Cmd/Ctrl+C compress, E escape, U unescape, O upload, D download, K clear — efficient mouse-free operation
  • Auto-execute mode: Auto compress/escape with 400ms debounce after paste or edit, WYSIWYG
  • File upload & download: Drag or click to upload .json/.txt files, one-click download of output.json after processing
  • Local history: localStorage automatically saves last input content, no data loss on page refresh
  • Sample data: One-click load sample JSON for quick trial, error messages with fix button
  • Pure frontend security: All operations run locally in browser, no data uploaded to server, works offline

How to Use

  1. Paste JSON content into the left editor, click the upload button to select a local .json/.txt file, or click the "Sample" button to load an example
  2. Compression mode runs automatically by default (400ms debounce), or manually click the "Compress" button or press Shift+Cmd/Ctrl+C
  3. To escape for code strings, press Shift+Cmd/Ctrl+E or switch to Escape mode; to restore escaped strings, press Shift+Cmd/Ctrl+U
  4. If JSON has syntax errors, a red error message appears at the bottom; when repairable errors exist, a "Try Fix" button appears — click to auto-correct
  5. The bottom status bar shows real-time before/after byte counts and compression ratio percentage; after confirming results, click "Copy" or "Download"
  6. The divider between left and right panels is draggable for width adjustment; you can also use keyboard shortcuts to complete all operations quickly

FAQ

What's the difference between JSON Compress and JSON Format?

JSON Format (Beautify/Pretty Print) adds indentation, newlines, and spaces between key-value pairs to make it easier for human eyes to read, suitable for development and debugging; JSON Compress (Minify) removes all unnecessary whitespace characters (spaces, newlines, tabs, indentation), converting multi-line JSON into a compact single-line format, aimed at reducing size and improving transmission efficiency, suitable for production API transmission, configuration file minimization, and embedding in code strings. The two are complementary operations — view the formatted version during development, use the compressed version for production.

What is JSON Escape? When do I need it?

JSON Escape refers to adding backslash escaping to special characters in JSON strings (mainly converting double quotes " to \", backslashes \ to \\, newlines to \n, etc.), turning multi-line JSON objects into single-line string literals that can be directly embedded in source code such as JavaScript, Java, Python, etc. Typical scenarios: embedding JSON responses as strings in test code when writing unit tests; passing JSON strings in Postman or curl commands; using JSON as string values in configuration files. Unescape is the reverse operation that restores escaped strings back to standard JSON.

If the input JSON has syntax errors (like trailing commas), can it still be compressed successfully?

Yes. This tool has a built-in smart syntax repair engine (tryFixJSON) that automatically detects and attempts to fix common JSON errors before compression: 1) trailing commas, such as {"a":1,}; 2) single quotes instead of double quotes, such as {'a':1}; 3) unclosed strings; 4) JavaScript comments (// and /* */); 5) trailing extra commas, etc. After repair, compression or escape is executed to ensure 100% valid JSON output. If a repairable error is detected, a "Try Fix" button will appear on the panel; click it to auto-correct.

Does JSON compression lose data? What's the typical compression ratio?

No data loss. JSON compression only removes formatting whitespace characters (spaces, newlines, tabs) without changing any key names, key values, data types, or structure. After JSON.parse then JSON.stringify, the data is completely identical to the original. The compression ratio depends on how formatted the original JSON is: if the original was formatted JSON with 2-space indentation, the compression ratio is typically 20%-40% (removing indentation and newlines); if there are large amounts of consecutive spaces or comments (after repair), the compression ratio can exceed 50%. The status bar displays original bytes, compressed bytes, and precise compression ratio in real time.

Will sensitive JSON configurations or API data leak during compression?

No. This tool uses a pure frontend processing architecture; all JSON parsing, compression, escaping, and repair operations are executed entirely in your local browser's JavaScript engine. Data is not uploaded to external servers via any network request, and it works normally offline. Your API keys, database configurations, business data, and other sensitive information always stay local.

What keyboard shortcuts are supported?

For efficiency, this tool provides full keyboard shortcut support (use ⌘+Shift on macOS, Ctrl+Shift on Windows): Shift+⌘/Ctrl+C for one-click compress; Shift+⌘/Ctrl+E for Escape; Shift+⌘/Ctrl+U for Unescape; Shift+⌘/Ctrl+O to upload file; Shift+⌘/Ctrl+D to download result; Shift+⌘/Ctrl+K to clear. While typing, the tool also auto-executes the current mode with 400ms debounce, no need to repeatedly click buttons.

What is JSON Compress (JSON Minify)?

JSON Compress (JSON Minification) is the process of removing all unnecessary whitespace characters (spaces, newlines \n, tabs \t, carriage returns \r) and comments (non-standard but common) from JSON text, converting multi-level indented formatted JSON into a compact single-line format. JSON compression does not change any data content — key names, values, data types (string/number/boolean/null/array/object), and nested structure remain completely unchanged; it only removes formatting whitespace intended for human readability.

The core value of JSON compression is reducing data size. Indentation spaces and newlines in formatted JSON, while developer-friendly, are redundant bytes during network transmission and storage. For example, a typical API response might be 2KB when formatted and only 1.2-1.5KB after compression, a 25%-40% size reduction. In high-concurrency API scenarios, mobile weak network environments, and large-scale configuration file distribution, JSON compression significantly reduces bandwidth consumption, improves transmission speed, and decreases server overhead. In production environments it's typically used alongside HTTP compression like Gzip/Brotli, but JSON Minify as a content-layer compression remains irreplaceable.

JSON compression implementation is very simple: use JSON.parse() to parse text into a JavaScript object, then use JSON.stringify(obj) without indentation parameters to serialize output — this is exactly the core implementation of this tool. This parse + stringify approach naturally guarantees that the output JSON is 100% valid, and can automatically remove illegal comments and trailing commas (with error repair). Note: JSON compression and Gzip compression are different layers of optimization — JSON Minify removes redundant whitespace at the content layer, Gzip is a general-purpose compression algorithm at the transport layer; the two can be used in combination.

术语表

JSON
JavaScript Object Notation, a lightweight data interchange format using key-value pairs and array structures, human-readable and machine-parseable, the standard data format for REST API.
Minify / Compress
The process of removing all unnecessary characters (spaces, newlines, comments) from code/data to reduce size, commonly applied to JS/CSS/JSON frontend resources.
Beautify / Format
The reverse of Minify, adding indentation, newlines, and spaces to make JSON structure clear and readable, also called Prettify or Pretty Print.
Escape
Adding backslashes before special characters (e.g., " becomes \", newline becomes \n), converting multi-line JSON into single-line string literals embeddable in code.
Unescape
The reverse of Escape, restoring escape sequences like \", \n, \\ back to original characters, recovering standard JSON format.
Trailing Comma
An extra comma after the last element in an object or array; allowed in JavaScript but not in the JSON standard, the most common JSON syntax error.
Gzip / Brotli
HTTP transport-layer general compression algorithms, complementary to JSON Minify; Gzip after Minify achieves the best compression.
Payload
The actual data body transmitted in an API request or response (usually in JSON format); compressing Payload directly reduces bandwidth consumption.
CodeMirror
A browser-side code editor component; this tool uses it to provide JSON syntax highlighting, line numbers, bracket matching, and other professional editing experiences.

JSON Compression vs Common Compression Methods

MethodCompression LayerLosslessReadabilityUse Case
JSON MinifyContent Layer (remove whitespace)LosslessUnreadable (single line)Production API transmission, config minimization
JSON BeautifyContent Layer (add whitespace)LosslessHighly readableDevelopment debugging, manual reading
GzipTransport LayerLosslessUnreadable (binary)HTTP response Content-Encoding
BrotliTransport LayerLosslessUnreadable (binary)HTTPS static resource compression (20% better than Gzip)
MessagePackSerialization LayerLosslessUnreadable (binary)High-performance RPC internal communication

JSON Escape Special Character Reference

Original CharacterEscapedNameDescription
"\"Double QuoteThe most common character that must be escaped in JSON strings
\\\BackslashThe escape character itself needs to be escaped
Newline\nNewlineMust be escaped when compressing multi-line strings to single line
Tab\tTabIndentation tab escape
Carriage Return\rCarriage ReturnCR in Windows CRLF newline
/\/SlashAllowed but not required by JSON standard (optional)

Authoritative References