Format and indent JSON

turns JSON into a readable, structured form, perfect for inspecting REST API responses, configs and logs

Why JSON formatting?

JSON formatting makes JSON data more readable and easier to understand for developers and users. It eases debugging, code review and data analysis, especially when dealing with large and complex JSON files. Well-formatted JSON can also be embedded more easily in documents and reports.

How to format JSON

On the formatting page, you can format your JSON by pasting it into the dedicated text area or by uploading a file containing JSON.

As soon as the JSON is submitted, it will be formatted and displayed in a result area. If the JSON is invalid, an error will be displayed with an indication of the nature of the problem.

Using the formatted JSON

You can copy the formatted JSON with the dedicated copy button. This makes it easier to integrate JSON into your projects or reports.

Your JSON code should look like this:


{
    "id": 12345,
    "name": "John Doe",
    "email": "johndoe@example.com",
    "address": {
        "street": "123 Main St",
        "city": "Springfield",
        "state": "IL",
        "postalCode": "62704",
        "country": "USA"
    },
    "phoneNumbers": [
        {
            "type": "home",
            "number": "555-1234"
        },
        {
            "type": "work",
            "number": "555-5678"
        }
    ],
    "orders": [
        {
            "orderId": 1001,
            "orderDate": "2023-06-01T14:30:00Z",
            "items": [
                {
                    "productId": 2001,
                    "productName": "Laptop",
                    "quantity": 1,
                    "price": 999.99,
                    "details": {
                        "manufacturer": "TechCorp",
                        "warranty": "2 years"
                    }
                },
                {
                    "productId": 2002,
                    "productName": "Mouse",
                    "quantity": 2,
                    "price": 25.50,
                    "details": {
                        "manufacturer": "GadgetCo",
                        "warranty": "1 year"
                    }
                }
            ],
            "totalAmount": 1051.49
        },
        {
            "orderId": 1002,
            "orderDate": "2023-06-10T10:15:00Z",
            "items": [
                {
                    "productId": 2003,
                    "productName": "Keyboard",
                    "quantity": 1,
                    "price": 45.99,
                    "details": {
                        "manufacturer": "KeyMasters",
                        "warranty": "3 years"
                    }
                }
            ],
            "totalAmount": 45.99
        }
    ],
    "preferences": {
        "newsletter": true,
        "notifications": {
            "email": true,
            "sms": false
        },
        "theme": "dark"
    },
    "lastLogin": "2024-06-14T09:30:00Z"
}

    

Frequently asked questions

What is the difference between a JSON formatter, validator and minifier?

A formatter (beautifier) rewrites a compact JSON as an indented, readable version. A validator only checks that the syntax conforms to the specification (RFC 8259) and flags errors. A minifier does the opposite of the formatter: it removes all whitespace to reduce the file's size. Our tool combines formatting and validation: if the JSON is invalid, an error message specifies the position of the problem.

Does standard JSON accept comments and trailing commas?

No. The JSON specification (RFC 8259) strictly forbids comments (// or /* */) and trailing commas after the last element of an array or object. If you need them, look at JSON5 or JSONC, two extensions that accept comments and trailing commas, notably used by VS Code and TypeScript configuration files.

Why must strings use double quotes?

The JSON specification requires double quotes (") for all strings and all object keys. Single quotes (') are not valid, even though JavaScript accepts them. A frequent error when copying from JS code is to keep the single quotes: the formatter then reports a parsing error.

How do I handle very large numbers or very precise decimal numbers?

JSON does not distinguish integers from floats: everything is a number. JavaScript parsers automatically convert to Number, which loses precision beyond 2^53 (integers) and has a floating-point precision limited to 15 significant digits. For long identifiers (Twitter IDs, Discord snowflakes) or financial amounts, encode them as a string ("123456789012345678") to preserve precision.

Which indentation to pick: 2 or 4 spaces?

2-space indentation is the dominant convention (Prettier, ESLint defaults, npm conventions), and stays readable even for very nested documents. 4-space indentation suits flat documents where verticality helps reading. What matters is consistency within a single project. Our tool uses 4 spaces by default, matching the pretty print of json_encode(JSON_PRETTY_PRINT) in PHP.

What if my JSON contains Unicode characters or emojis?

JSON natively supports UTF-8. Emojis, accents, CJK characters and other non-Latin scripts are preserved as is in the formatted output. If your JSON uses Unicode escaping (é for é), it stays valid but the formatter does not rewrite it as a native character. To normalise, run it through a strict parser like JSON.parse followed by JSON.stringify.

Example request

curl -X POST https://cdrn.fr/api/v1/tools/json-formatter/execute \
  -H "Content-Type: application/json" \
  -d '{"input":"..."}'

Input schema

Field Type Required Default
input text

Endpoints

  • GET https://cdrn.fr/api/v1/tools - lists every available tool
  • GET https://cdrn.fr/api/v1/tools/json-formatter - returns the schema for this tool
  • POST https://cdrn.fr/api/v1/tools/json-formatter/execute - runs this tool with a JSON payload