JSON · Developer Guide
How to Format and Validate JSON
An API response can be valid JSON and still contain the wrong data. Separate syntax checks from data checks before copying a payload into a configuration file, test fixture, or request.
What is JSON?
JSON represents objects, arrays, strings, numbers, booleans, and null. It is a data format; a JavaScript object literal containing comments or unquoted property names is not necessarily JSON.
How the workflow works
- Keep a copy of the original response. Paste the complete body, excluding HTTP headers, into JSON Validator.
- Fix syntax errors first. Format the valid document to inspect nesting and field types.
- Check application rules separately: required fields, allowed values, and relationships between fields need a schema or application tests.
- Minify a reviewed document when compact text is useful. Minification does not encrypt or redact data.
Example: review an API response
The formatter uses two spaces for indentation. In this example, the array contains an object and the active field is a boolean, not a quoted string.
{"users":[{"id":"42","active":true}],"next":null}
{
"users": [
{
"id": "42",
"active": true
}
],
"next": null
}Common mistakes
- Trailing commas: remove the comma before a closing brace or bracket.
- Single quotes: use double quotes for property names and strings.
- Unescaped newlines: inside a string, use a backslash followed by n rather than a literal line break.
- Wrong structure: an array of objects is different from an object keyed by IDs; formatting cannot choose the correct structure for your API.
Practical use cases and limitations
For a failed request, first validate the outgoing body, then compare the expected field types with the API contract. For a fixture, format it before code review and run the application test after editing.
These tools parse through JavaScript values. Duplicate keys can collapse to the last value, and large numeric IDs can lose precision. Preserve identifiers as strings in the producing system and retain the source when exact bytes matter. Conversion to or from YAML also requires reviewing types; comments are not JSON data.
Privacy and security
The linked transformations run in your browser without uploading input to Small Tools servers. Use redacted samples when possible, especially before sharing screenshots, copied output, or fixtures. Formatting does not remove tokens or personal information.
Run it yourself
Node.js v26.12.1 printed the results below. Small Tools JSON Validator reports the same messages for the single-quote and trailing-comma inputs and shows Valid JSON ✓ for the duplicate-key and large-number documents. JSON Formatter turns {"a":1,"a":2} into an object with a: 2 and writes 12345678901234567890 as 12345678901234567000.
Error wording comes from the browser's JSON parser, so it can differ from these messages in another browser. A valid result only means the text is JSON; it does not mean the values are the ones you intended.
JSON.parse("{'a':1}")
// SyntaxError: Expected property name or '}' in JSON at position 1 (line 1 column 2)
JSON.parse('{"a":1,}')
// SyntaxError: Expected double-quoted property name in JSON at position 7 (line 1 column 8)
JSON.parse('{"a":1} // c')
// SyntaxError: Unexpected non-whitespace character after JSON at position 8 (line 1 column 9)
JSON.parse('{"a":NaN}')
// SyntaxError: Unexpected token 'N', "{"a":NaN}" is not valid JSON
JSON.parse('{"s":"a\nb"}') // the \n is a real line break inside the JSON string
// SyntaxError: Bad control character in string literal in JSON at position 7 (line 1 column 8)
JSON.parse('{"a":1,"a":2}')
// { a: 2 }
JSON.parse('{"id":12345678901234567890}').id
// 12345678901234567000
JSON.stringify({ a: undefined, b: () => 1, c: NaN })
// {"c":null}What this guide does not verify
- Schema rules such as required fields, allowed values and relationships between fields. Valid JSON says nothing about them.
- JSON5, JSON with comments, JSON Lines and other relatives. Only strict JSON as RFC 8259 defines it is covered.
- How other languages and libraries handle duplicate keys, large numbers or key order. The examples ran in Node.js only.
- Very large documents and streaming parsers. The browser tools hold the whole text in memory.
Frequently asked questions
Why did my large ID change after formatting? The tools parse the number as a JavaScript double, so 12345678901234567890 becomes 12345678901234567000. RFC 8259 says good interoperability comes from software that expects no more range or precision than IEEE 754 doubles provide. Send identifiers as strings.
Why does a duplicate key not cause an error? JSON.parse keeps the last value, so {"a":1,"a":2} becomes {"a":2}. RFC 8259 says names within an object should be unique and that software behavior is unpredictable when they are not.
Why are undefined values missing from JSON.stringify output? JSON has no undefined or function values, so they are omitted from objects, and NaN becomes null. Check generated JSON before you rely on it.
Related tools
- JSON Formatter — Format and beautify JSON with readable indentation.
- JSON Validator — Check JSON syntax and see clear parsing errors.
- JSON Minifier — Remove unnecessary whitespace from JSON data.
- YAML to JSON — Convert YAML documents into formatted JSON.
- JSON to YAML — Convert JSON values into readable YAML.