Code Tools

JSON Minifier

All tools

Validate JSON and reprint it on one line, with every insignificant space removed.

How it works

Four simple steps

1

Paste JSON

Add an indented payload, fixture or config file.

2

Parsed first

Invalid JSON stops here and the parser error is shown.

3

Reprinted compactly

Valid input is written back on one line with no spare whitespace.

4

Copy the line

Copy the result or download it as min.json.

JSON Minifier

About JSON Minifier

Pretty JSON is for people; compact JSON is for request bodies, environment variables and log lines. You have a nicely indented fixture and need it on a single line for a curl command or a test assertion.

Instead of deleting whitespace with a regex, the minifier parses your input with JSON.parse and writes it back with JSON.stringify. Spaces inside string values are preserved, the output is guaranteed to be valid JSON, and a broken document is refused with the parser's error rather than turned into something subtly worse. Output updates live; copy it or download min.json.

Parsing has side effects worth knowing: duplicate keys collapse to the last value, and integers larger than 2^53 are rounded. Trailing commas and comments are not accepted, so fix those in the JSON beautifier first, where you can see the structure. Keep the pretty version in version control and minify at send time, because hand-editing a one-liner is an easy way to introduce a syntax error. If an API expects the compact JSON encoded, pass it to the Base64 encoder, or follow the full JSON to Base64 recipe on the blog.

The round trip through the browser's JSON engine happens locally, and no copy of the payload is kept.

Keyboard shortcut

Ctrl Enter - Run tool

Use cases

curl and HTTP clients

Fit a request body on one line inside a shell command.

Log fixtures

Keep sample events to a single line for log-based tests.

Env variables

Store a small JSON config in a single environment variable.

Instructions

How to use this tool

FAQ

Frequently asked questions

See all FAQs

Answers for this tool. For site-wide help, open the FAQ hub.

No, with one exception defined by JavaScript itself: keys that look like non-negative integers, such as "2" or "10", are moved to the front in numeric order. All other keys keep the order they had in the input.

The output is the same. This page is a focused single-purpose view for when you only ever want compact output, with min.json as the download name.

Not directly. The input must be a single JSON value, so several objects on separate lines fail to parse. Wrap them in an array, or minify each line on its own.

View more FAQs

Related tools

View all

HTML Formatter

Beautify and indent HTML markup.

Open

CSS Formatter

Format and pretty-print CSS.

Open

JS Formatter

Beautify JavaScript code.

Open

JSON Formatter

Beautify and validate JSON.

Open

Explore 321 free tools

Everything you need as a developer, marketer or creator - in one beautiful place.

Browse all tools