Format and validate JSON
Make JSON easier to read, check its syntax, or produce a compact version. This guide walks through indentation, key sorting and saving the result.
Try the supplied sample
Download order-options.json, an invented order with two items and English field names. The customer object groups a name and city; the items array is a list containing CARD-02 followed by BOX-01. The sample includes quoted text, numeric quantities and prices, the boolean true, and null for an empty delivery note. Its fields are deliberately unsorted so you can see what the sorting option changes.
Step by step
- Open JSON Formatter & Validator. Use File to open the supplied order-options.json, or paste the file's contents into Your inputs.
- Set Indentation to 2 for two spaces per level. Leave Sort object keys unchecked for the first run.
- Select Process input. The tool checks the JSON syntax before showing a result. If it reports an error, use the line and column to locate the problem, correct the input and try again.
- Read the result. The customer object and the two items should be easy to follow, with one field or list entry on each line. The fields keep the sample's order while sorting is unchecked.
- Select Download result to save formatted.json. You can also use Copy text to put the result in another editor.
- Open the downloaded file in a text editor and compare it with the sample using the checks below. Then try the other indentation and sorting choices, selecting Process input again after each change.
Before and after examples
These short examples use the customer object from order-options.json, shown as a small JSON document. Compare the same name and city before and after each setting. The optional reference section at the end shows the complete order.
Make compact JSON easier to read
Set Indentation to 2, leave Sort object keys unchecked and select Process input. The result adds line breaks and two spaces per level while keeping the fields in their original order.
Before: compact input
{"customer":{"name":"Zoë","city":"Bergen"}}After: two-space indentation
{
"customer": {
"name": "Zoë",
"city": "Bergen"
}
}Sort the keys inside an object
Keep Indentation at 2, check Sort object keys and select Process input. Inside customer, city now comes before name. Both values stay the same.
Before: original key order
{
"customer": {
"name": "Zoë",
"city": "Bergen"
}
}After: sorted object keys
{
"customer": {
"city": "Bergen",
"name": "Zoë"
}
}Make the JSON compact
Choose Minify under Indentation, leave Sort object keys unchecked and select Process input. Formatting spaces and line breaks disappear; the text and field order stay the same.
Before: two-space indentation
{
"customer": {
"name": "Zoë",
"city": "Bergen"
}
}After: Minify
{"customer":{"name":"Zoë","city":"Bergen"}}Choose the indentation
| Choice | What it does |
|---|---|
| 2 | Uses two spaces for each nesting level. This is the main walkthrough's setting. |
| 4 | Uses four spaces for each nesting level, making nested objects and arrays stand out further. |
| ↹ | Uses a tab for each nesting level. How wide a tab looks depends on your text editor. |
| Minify | Removes the formatting spaces and line breaks. Spaces inside quoted text remain part of that text. Choose this for compact output, then select Process input. |
Changing the input or an option clears the previous result. Select Process input again to create a result with the new settings. The tool reads the input area each time; it does not automatically feed the previous result back into the input.
Sort object keys
Leave Sort object keys unchecked to keep each object's original field order. When checked, it sorts keys in case-sensitive text order throughout the document, including objects inside arrays. The array entries themselves keep their original sequence.
- Keep Indentation at 2, check Sort object keys and select Process input.
- The top-level keys now read customer, deliveryNote, items, order and paid. Inside customer, city comes before name. Inside each item, price comes before quantity and sku.
- The items array still contains CARD-02 followed by BOX-01. Sorting keys does not sort the items by their sku or price.
Copy, download and start again
| Choice | What it does |
|---|---|
| Copy text | Copies the current result as text. If copying is unavailable, the tool selects the result so you can copy it manually. |
| Download result | Saves the current result as formatted.json. This filename is used for formatted, minified and sorted results, so rename files if you want to keep several versions. |
| Print results | Opens the browser's print dialog for the result text. |
| Load example | Replaces the input with the tool's built-in example and processes it using the current settings. That example is different from this guide's order-options.json. |
| Clear all | Clears the input, selected file and result. The indentation and sorting choices remain selected. |
Check your downloaded JSON
- Open formatted.json in a text editor. Confirm that the order is ORD-1042, the customer is Zoë in Bergen, and there are two items.
- Check the values and their types: quantity is numeric 2 then 1, prices retain 19.50 and 5.00, paid is the unquoted boolean true, and deliveryNote is the unquoted value null. Quoted names and item codes remain strings.
- After trying Sort object keys, confirm the expected field order above and that CARD-02 still precedes BOX-01 in the items array.
- Try Minify and Process input. Paste that result back into Your inputs, set Indentation to 2 and select Process input again. Compare the values and item order with the original sample; formatting choices should preserve them.
Questions and troubleshooting
Why does it report invalid JSON?
Check the reported line and column, plus the field immediately before that position. Keys and text need double quotes; fields need commas and colons; brackets and braces must close. Correct the input and select Process input again. Validation checks JSON syntax, so a valid result can still be missing fields required by your application.
Can I use comments or a trailing comma?
Remove comments and any comma immediately before a closing bracket or brace. They are not valid JSON. The formatter requires valid input and does not automatically repair it.
What does the repeated-key warning mean?
The message “Repeated object keys were preserved. Some readers discard repeated keys.” means a key appears more than once in the same object. The formatter keeps those entries and warns you. Review the source, choose the intended value and remove the extra entry; another application may keep only one of them.
Why won't my file open or process?
The input limit is 2 MiB, or 2,097,152 bytes. Local text files must be UTF-8. If the tool reports that the data is too complex, reduce its nesting or number of entries. Split large input into smaller complete JSON documents rather than cutting it in the middle of an object or array.
Why do long numbers change in another application?
The separate precision sample below contains 9007199254740993 and 0.10000000000000001. This formatter keeps their number text exactly with every indentation and sorting choice. Format exact-numbers.json and compare your result with exact-numbers-formatted.json in a text editor. An application that imports the result can still round numbers, so confirm that it supports the precision you need. A zero-prefixed code such as 00123 must be a quoted string in JSON.
Can formatting restore digits that were already rounded?
Formatting cannot recover digits that were rounded or removed before the text reached the tool. Return to the original source and export the complete value again. Where the value is an identifier rather than a quantity, using a string can help receiving applications retain its digits.
Optional: compare the sample and reference outputs
These code examples and downloads were produced from order-options.json by the same formatter used on the tool page. The formatted and minified references leave key sorting off; the sorted reference uses two-space indentation with sorting on.
Original sample
{"order":"ORD-1042", "customer": {"name":"Zoë","city":"Bergen"}, "items":[{"sku":"CARD-02", "quantity":2,"price":19.50},{"sku":"BOX-01","quantity":1, "price":5.00}], "paid":true, "deliveryNote":null}
Two spaces; original key order
{
"order": "ORD-1042",
"customer": {
"name": "Zoë",
"city": "Bergen"
},
"items": [
{
"sku": "CARD-02",
"quantity": 2,
"price": 19.50
},
{
"sku": "BOX-01",
"quantity": 1,
"price": 5.00
}
],
"paid": true,
"deliveryNote": null
}Minify; original key order
{"order":"ORD-1042","customer":{"name":"Zoë","city":"Bergen"},"items":[{"sku":"CARD-02","quantity":2,"price":19.50},{"sku":"BOX-01","quantity":1,"price":5.00}],"paid":true,"deliveryNote":null}Two spaces; sorted object keys
{
"customer": {
"city": "Bergen",
"name": "Zoë"
},
"deliveryNote": null,
"items": [
{
"price": 19.50,
"quantity": 2,
"sku": "CARD-02"
},
{
"price": 5.00,
"quantity": 1,
"sku": "BOX-01"
}
],
"order": "ORD-1042",
"paid": true
}| Reference file | Settings | Bytes |
|---|---|---|
| order-formatted.json | Two spaces; original key order | 300 |
| order-minified.json | Minify; original key order | 193 |
| order-sorted.json | Two spaces; sorted object keys | 300 |
These are actual text outputs, not interface screenshots. Code may wrap to fit your screen. The reference filenames distinguish the examples; the tool itself downloads every version as formatted.json.