Developer

JSON Formatter Guide: Validate and Fix JSON Errors

By AllConvertor ยท ยท 2 min read

JSON (JavaScript Object Notation) is the default data format for web APIs, configuration files and many databases. It is simple, but a single misplaced comma can break an entire request. A good JSON formatter and validator makes problems easy to see.

JSON syntax rules in brief

  • Data is stored in key and value pairs inside curly braces for objects, and in square brackets for arrays
  • Keys must be strings wrapped in double quotes
  • Strings use double quotes only; single quotes are invalid
  • Allowed value types are string, number, boolean, null, object and array
  • No comments and no trailing commas are allowed in standard JSON

Pretty-print vs minify

Pretty-printing adds indentation and line breaks so humans can read nested data. Minifying removes all unnecessary whitespace so the payload is smaller for transfer or storage. Use pretty-printed JSON while developing and debugging, and minified JSON for production responses when size matters.

Most common JSON errors and how to fix them

  • Trailing comma after the last item: remove the final comma
  • Single quotes around keys or strings: replace with double quotes
  • Unquoted keys such as {name: "A"}: wrap each key in double quotes
  • Comments (// or /* */): remove them, or switch to a format that supports comments such as JSONC for configs
  • Missing or mismatched brackets: check that every opening brace or bracket has a closing partner
  • Special characters in strings: escape quotes, backslashes and control characters, for example \" and \n
  • Using undefined, NaN or Infinity: these are not valid JSON values, so use null or a string instead

How to validate JSON step by step

  1. Paste your JSON into the formatter.
  2. Run validation and read the error message, which usually shows the line and position of the first problem.
  3. Fix that issue and validate again, because later errors can be hidden behind the first one.
  4. Pretty-print the valid result to confirm the structure is what you expect.
  5. Minify the final version if you need a compact payload.

Working safely with JSON

Never paste secrets such as API keys or personal data into online tools you do not trust. Our JSON formatter runs in your browser, so the content you paste is not uploaded to a server. When working with large numbers, remember that JavaScript represents them as 64-bit floating-point values, so integers above 9,007,199,254,740,991 can lose precision; send them as strings if exact values matter.

Related encodings you will meet alongside JSON

APIs often wrap JSON in other encodings. Base64 is used to embed binary data in JSON strings, and URL encoding is used when JSON is placed in a query parameter. Having an encoder and decoder at hand speeds up debugging.

โ† All articles