Skip to content
All guides

How to Validate and Format JSON: Common Errors Explained

Fix trailing commas, quote errors, invalid literals, duplicate keys, and structural mistakes using the JSON standard.

Developer basicsBy Pexlii3 min read1 cited source
Structured code pages being inspected for punctuation errors
In this guide

Formatting adds whitespace and indentation; validation checks whether the text follows JSON grammar. Pretty-looking text can still be invalid, and valid JSON can still contain unexpected or unsafe data.

RFC 8259 defines JSON as a text-based, language-independent data interchange format with objects, arrays, strings, numbers, booleans, and null.

RFC Editor / Internet Engineering Task Force
Ready to try it?JSON Formatter & Validator

Check structural punctuation

Objects use braces and contain name-value pairs separated by commas. A colon separates each name from its value. Arrays use brackets and contain comma-separated values. Standard JSON does not allow a trailing comma after the final member or array item.

Strings and object names use double quotes. Literal names are lowercase true, false, and null. RFC 8259 lists the six structural characters and requires those three literal names to be lowercase.

RFC Editor / Internet Engineering Task Force

Do not ignore duplicate names

RFC 8259 says object member names should be unique. When duplicate names appear, receiving software can disagree: some keep the last value, some report an error, and some expose all duplicates.

RFC Editor / Internet Engineering Task Force

A syntax validator may accept duplicate names because the grammar can still parse them. Treat a duplicate-key warning as an interoperability problem and resolve the intended value explicitly.

  • Use double quotes for names and strings.
  • Remove comments and trailing commas for strict JSON.
  • Use lowercase true, false, and null.
  • Resolve duplicate object names.

Format only after successful parsing

A formatter normally parses the input and serializes it with indentation. If parsing fails, use the reported line and column as a starting point, then inspect the character immediately before the highlighted location; a missing comma or quote often surfaces on the next token.

Validation proves syntax, not business rules. An API can require specific fields, value types, formats, or ranges that plain JSON validation does not check. Use a schema or application-level validation for those constraints.

Key takeaways

  • Formatting and validation are different operations.
  • Duplicate keys are an interoperability risk even when parsing succeeds.
  • Valid JSON can still violate an application’s expected schema.

Sources

References for factual claims and further reading.

  1. 01

    RFC Editor / Internet Engineering Task Force

    RFC 8259: The JavaScript Object Notation Data Interchange Format

Educational information only. Follow the requirements of the receiving organization, product label, applicable standard, or qualified professional for your situation.