Waiting for input

Input

Output

 

The formatted JSON appears here as you type.

Format JSON in your code

The same formatting and minifying in Java, JavaScript, Python and Go, using each language's usual JSON library.

Java

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

public class FormatJson {
    public static void main(String[] args) throws Exception {
        String text = "{\"name\":\"Ada\",\"langs\":[\"en\",\"fr\"],\"active\":true}";

        ObjectMapper mapper = new ObjectMapper();
        // Throws JsonProcessingException (with line and column) on invalid JSON.
        JsonNode tree = mapper.readTree(text);

        // Jackson's default pretty printer puts a space before the colon
        // and keeps short arrays on one line.
        System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(tree));
        System.out.println(mapper.writeValueAsString(tree)); // minified
    }
}

Uses Jackson (com.fasterxml.jackson.core:jackson-databind).

JavaScript

// Format (pretty-print) and minify JSON with the built-in JSON object.
// Note: JSON.parse turns integers above 2^53 into approximations.
const text = '{"name":"Ada","langs":["en","fr"],"active":true}';

const value = JSON.parse(text); // throws SyntaxError on invalid JSON

console.log(JSON.stringify(value, null, 2)); // 2-space indent
console.log(JSON.stringify(value)); // minified

Python

import json

text = '{"name":"Ada","langs":["en","fr"],"active":true}'

# Raises json.JSONDecodeError (with .lineno and .colno) on invalid JSON.
value = json.loads(text)

print(json.dumps(value, indent=2, ensure_ascii=False))  # 2-space indent
print(json.dumps(value, separators=(",", ":"), ensure_ascii=False))  # minified

Go

package main

import (
	"bytes"
	"encoding/json"
	"fmt"
)

func main() {
	text := []byte(`{"name":"Ada","langs":["en","fr"],"active":true}`)

	// Indent and Compact work on the raw bytes, so numbers keep their exact text.
	var pretty bytes.Buffer
	if err := json.Indent(&pretty, text, "", "  "); err != nil {
		fmt.Println("invalid JSON:", err) // *json.SyntaxError has an Offset field
		return
	}
	fmt.Println(pretty.String())

	var compact bytes.Buffer
	if err := json.Compact(&compact, text); err != nil {
		fmt.Println("invalid JSON:", err)
		return
	}
	fmt.Println(compact.String())
}

Last verified . Each example is run automatically and its output checked.

Ctrl+Enter run / or Ctrl+K search tools Press Ctrl+D to bookmark this page

How to format JSON

  1. Paste or type your JSON into the Input box, or drop a .json file onto it.
  2. The formatted result appears in the Output box as you type. Choose 2 spaces, 4 spaces or tabs, and turn on Sort keys if you want keys in alphabetical order.
  3. Copy or download the result. Switch to Minify to get the same data on a single line.

If the JSON has mistakes, the Output box lists every problem it can find with its line and column. Use the arrows to step through them, or press Fix it to repair the common ones in one go.

Your values stay exactly as written

Many formatters parse the JSON into JavaScript and print it back. That quietly changes some data: an ID like 12345678901234567890 becomes 12345678901234567000, and 1.0 turns into 1. This formatter only changes whitespace. Numbers, string escapes such as \u00e9, and the order of keys are kept exactly as you entered them, and the summary under the tool confirms it.

It also warns about duplicate keys. JSON that repeats a key in the same object is technically allowed, but most parsers silently keep only the last value, which is a common source of confusing bugs.

Common JSON errors and how to fix them

ProblemExampleFix
Trailing comma[1, 2,]Remove the last comma: [1, 2]
Single quotes{'name': 'Ada'}Use double quotes: {"name": "Ada"}
Key without quotes{name: "Ada"}Quote the key: {"name": "Ada"}
Comments// noteRemove them; JSON has no comments
JavaScript or Python valuesundefined, NaN, None, TrueUse null, true or false
Missing comma{"a": 1 "b": 2}Add a comma between items
Raw line break in a stringa value split over two linesWrite \n instead

Fix it repairs these automatically. It shows the repaired JSON in the Output box and lists each change with its position in your original input, so you can check the result before using it.

Large files and edge cases

  • Large files (several megabytes) are processed in a background worker, so the page stays responsive. Very large output is shown without colors to keep scrolling smooth.
  • Several JSON values in one file, such as JSON Lines, are reported as extra content: a JSON document holds exactly one value. Wrap them in an array if you need one document.
  • Byte order marks at the start of a file are ignored.
  • Very deep nesting (more than 2,000 levels) is reported instead of processed.

Frequently asked questions

Is my JSON sent to a server?

No. Formatting, validation and Fix it all run in your browser. Nothing you paste is uploaded or stored on a server, and there is no save feature that could expose it. You can confirm this in your browser's Network tab.

Does formatting change my data?

No. Only whitespace changes. Numbers, string escapes and key order stay exactly as written. Sort keys reorders keys when you turn it on, but never changes a value.

What does Fix it change?

It repairs common mistakes such as trailing commas, single quotes, unquoted keys, comments and values like None or undefined. The repaired JSON appears in the Output box with a list of every change, and your input stays as it was until you choose to replace it.

How large a file can I format?

There is no fixed limit. Files of several megabytes are processed in a background worker so the page stays responsive. The practical limit is your device's memory.

Can I format JSON with comments (JSONC)?

Comments are not part of standard JSON, so they are listed as problems. Fix it removes them and gives you plain JSON.

Settings

Deletes everything this site keeps in your browser: saved inputs, favorites, theme, accent color and tool options.