THE PRACTICAL GUIDE

How to format and validate JSON

Make a JSON payload readable, fix common syntax problems, and understand when to use formatted or minified output.

Start with valid JSON

JSON represents structured data using objects, arrays, strings, numbers, booleans, and null. Object keys and string values must use double quotes. Comments, trailing commas, undefined, and single-quoted strings are not valid JSON.

For example, {"name":"ADEMN","free":true} is a valid object. A JavaScript object literal such as {name: 'ADEMN'} looks similar, but it is not valid JSON.

Format for reading; minify for compact output

Paste the payload into JSON Formatter and choose Format. Indentation puts nested objects and arrays on separate lines, making it easier to find a field or compare values. Two spaces is a compact choice; four spaces makes each level more distinct.

Use Minify when you need the same data with unnecessary whitespace removed. Whitespace inside strings remains part of the value. Use Validate when you only need a syntax check, and keep your original input until you have checked the output.

Fix the first error before chasing the rest

A missing quote or comma can cause an error to be reported later in the text. Inspect the reported location and the characters just before it. Check that every opening brace or bracket has a matching closing character, and that values are separated by commas.

Escape a double quote inside a string with a backslash. A literal line break must also be escaped inside a JSON string. After fixing a problem, validate again: one correction can make the next issue easier to locate.

Know what syntax validation does not check

Valid JSON is not necessarily valid data for your application. A syntax check will not tell you whether a required field is missing or whether a field has the type your API expects. Use your application's validation rules or a JSON Schema validator for those checks.

This formatter preserves the original numeric text and key order. Other JavaScript tools can round large numbers when parsing them, so use strings for identifiers when exact characters must survive across systems. Avoid duplicate object keys: this formatter preserves them, but another parser may keep only the last value. Formatting alone does not verify data integrity.

Put it into practice