JSON is everywhere. APIs return it, configuration files are written in it, browsers store it, mobile apps send it and databases accept it. When it is formatted nicely, JSON is easy to read. When it arrives as one enormous line, or when a single missing comma breaks an entire file, it becomes a headache.
A JSON formatter turns compressed JSON into clean, indented text you can actually read, and a validator tells you exactly where the syntax is broken. This guide shows how to use the free JSON Formatter & Validator on RexBD, explains the rules of valid JSON, and walks through the errors you will meet most often.
What JSON is
JSON stands for JavaScript Object Notation. It is a plain-text format for structured data, popularised in the early 2000s and now standardised (RFC 8259 and ECMA-404). Despite the name, it is used by almost every programming language.
JSON is built from just a few pieces:
- Objects: key-value pairs inside curly braces, such as
{"name": "Rahim", "age": 30}. - Arrays: ordered lists inside square brackets, such as
["red", "green", "blue"]. - Strings: text in double quotes.
- Numbers: such as
42or3.14. - Booleans:
trueorfalse. - null: an empty value.
These can be nested as deeply as you like, which is how JSON represents complex data such as an order with a customer, an address and a list of items.
How to use the JSON Formatter
Step 1: Paste your JSON
Open the JSON Formatter & Validator and paste your JSON. It might come from an API response, a log file, a browser's developer tools or a config file. The tool runs in your browser, so API keys, customer data and internal configuration are never uploaded.
Step 2: Format (beautify)
Choose format. The tool adds line breaks and indentation so each key, value and nesting level is easy to see. Long single-line JSON becomes a readable structure.
Step 3: Read any error message
If the JSON is invalid, the tool shows an error message describing the problem and where it was found. Go to that position and fix it.
Step 4: Minify if needed
When you need compact JSON again, for example to paste into a single-line environment variable or reduce file size, use minify. It removes all unnecessary whitespace.
Step 5: Copy the result
Copy the formatted or minified JSON and use it in your code, documentation or bug report.
The rules of valid JSON
JSON looks a lot like JavaScript, but it is stricter. Most errors come from writing JavaScript habits into JSON.
| Rule | Valid | Invalid |
|---|---|---|
| Keys must be in double quotes | {"id": 1} |
{id: 1} |
| Strings use double quotes only | "hello" |
'hello' |
| No trailing commas | [1, 2, 3] |
[1, 2, 3,] |
| No comments | (none allowed) | // note or /* note */ |
| No undefined or functions | null |
undefined |
| Numbers without leading zeros | 7 |
07 |
| No special values like NaN | null |
NaN, Infinity |
| Special characters escaped in strings | "line\nbreak" |
a real line break inside quotes |
If you remember only one thing, remember the trailing comma rule. It is the most common reason valid-looking JSON fails.
The most common JSON errors and how to fix them
Unexpected token
This usually means a character appears where JSON does not allow it: a single quote, an unquoted key, a comment, or a stray character after the closing brace. Look at the position the error points to and the character just before it.
Unexpected end of JSON input
The JSON stops before it is complete. A closing brace } or bracket ] is missing, or the text was cut off when copying. Formatting the JSON makes missing brackets easier to spot, because the indentation will look wrong near the end.
Expected comma or closing brace
You are missing a comma between two items, such as {"a": 1 "b": 2}. Add the comma.
Trailing comma
An extra comma after the last item, such as {"a": 1,}. Remove it.
Bad escape or control character
A string contains a raw line break or tab, or a backslash that is not part of a valid escape sequence. Inside JSON strings, write a line break as \n, a tab as \t, a quote as \" and a backslash as \\. The String Escape tool can escape text for you.
Invisible characters
Text copied from documents, chat apps or web pages can contain curly quotes (โ โ) instead of straight quotes (" "), or invisible characters such as zero-width spaces and a byte order mark at the start. They look almost identical but break JSON. Retype the quotes, or clean the text with the Smart Quotes Fixer.
A worked example: debugging an API response
Imagine you are integrating a payment or delivery API, and your code fails with "Unexpected token" when parsing the response. You copy the raw response from your logs. It is one long line:
{"status":"ok","order":{"id":5521,"items":[{"sku":"P-10","qty":2},{"sku":"P-22","qty":1},],"total":1450}}
Pasting it into the formatter immediately shows an error pointing near the end of the items array. Looking there, you see },]: a trailing comma after the last item. The API returned invalid JSON. You now have a precise, reproducible bug to report to the API provider, with the exact location of the problem. Until they fix it, you know what to work around.
Without a formatter, finding one comma in a long line can take far longer, especially in responses that run to thousands of characters.
Formatting versus minifying
| Formatted (pretty) | Minified | |
|---|---|---|
| Purpose | Reading, debugging, documentation | Sending over networks, storage |
| Whitespace | Indentation and line breaks | None |
| File size | Larger | Smallest |
| Human readability | Excellent | Poor |
APIs usually send minified JSON to save bandwidth. Developers format it to read it. Both contain exactly the same data.
Working with large JSON files
Very large JSON, such as a database export of several megabytes, may be slow in any browser tool. Tips:
- Extract just the part you need. The JSONPath Tester lets you query specific values with expressions such as
$.orders[*].total. - Compare two versions of a large file with the JSON Diff tool instead of reading both.
- Convert array data to a spreadsheet with JSON to CSV when you need to sort or filter it.
Converting JSON to and from other formats
JSON often needs to move between systems that expect different formats. RexBD has converters for the most common ones:
- JSON to CSV and CSV to JSON for spreadsheets.
- YAML โ JSON for configuration files.
- JSON โ XML for older systems and feeds.
- JSON to TypeScript to generate type definitions from sample data.
- JSON to PHP Array for PHP configuration and tests.
Always format and validate JSON first. Converters need valid input.
Security and privacy
JSON from real systems often contains sensitive data: access tokens, customer names, phone numbers, addresses, internal IDs. Many online formatters send your JSON to their servers. The RexBD formatter processes everything in your browser, so the data stays on your device.
Even so, good habits help: remove or replace secrets before sharing JSON in tickets, chats or screenshots. If your JSON contains a JWT, you can inspect it locally with the JWT Decoder.
Who uses a JSON formatter?
Almost everyone who touches modern software:
- Backend developers reading API responses and request bodies while debugging.
- Frontend developers inspecting data returned to the browser.
- QA testers checking that API responses contain the expected fields and values.
- DevOps engineers editing JSON configuration for cloud services and deployment tools.
- Data analysts exploring exports from analytics tools and databases before converting them to spreadsheets.
- Support staff reading error details attached to tickets.
- Students learning how APIs and web data work.
For all of them, the routine is the same: paste, format, read, fix, copy.
Tips for writing JSON by hand
- Write and format as you go, so mistakes show up early.
- Use two-space indentation for readability.
- Keep key names consistent, for example all camelCase or all snake_case. The Case Converter helps rename keys.
- Do not add comments. If you need explanations, use a separate documentation file or a format that supports comments, such as YAML.
- Validate before committing configuration files, because one error can stop an application from starting.
Our JSON formatter tips and mistakes article has more debugging techniques.
Frequently asked questions
What does a JSON formatter do?
It adds indentation and line breaks to make JSON readable, and checks whether the JSON is valid.
Why is my JSON invalid when it looks correct?
The usual causes are a trailing comma, single quotes, unquoted keys, comments or curly quotes copied from a document.
Is my JSON uploaded to a server?
No. The RexBD formatter works entirely in your browser.
Can JSON have comments?
No. Standard JSON does not allow comments. Some tools accept JSON with comments (JSONC), but it is not valid JSON.
What is the difference between JSON and a JavaScript object?
JSON is a text format with strict rules: double-quoted keys and strings, no functions, no comments and no trailing commas. JavaScript objects are more flexible.
Is the JSON Formatter free?
Yes. It is free, requires no sign-up and has no limits for normal use.
Keep reading
How to Generate UUIDs Online: Version 4 UUIDs ExplainedDeveloper ยท 7 min read
How to Encode and Decode Base64 Online (and What It Is Really For)Developer ยท 7 min read
How to Write a Cron Expression (With a Free Cron Builder)Developer ยท 7 min read
How to Test Regular Expressions Online: A Practical Regex GuideDeveloper ยท 7 min read
How to Decode a JWT and Check Its Expiry (JSON Web Token Guide)Developer ยท 8 min read
Gold Weight Converter Guide: Bhori, Ana, Rati, Point and GramsUnit converters ยท 8 min read
