Developer Tools 7 min read • Updated 2026-10-09

JSON Syntax, Validation & Best Practices: A Developer Reference

A comprehensive reference for JSON syntax rules, common validation errors, strict specification requirements, and practical comparisons with YAML and XML serialization formats.

By Dhaval Joshi, Lead Engineer & Founder of FreeToolkit

What Is JSON?

JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format. Despite its name, JSON is language-independent and is the dominant serialization format for REST APIs, configuration files, NoSQL databases (MongoDB, Firestore), and web application state management.

JSON was formally specified in RFC 8259 (formerly RFC 7159) and ECMA-404. Understanding the strict specification prevents parsing errors across different languages and platforms.

The 6 JSON Data Types

JSON supports exactly six data types:

  1. String: Unicode text enclosed in double quotes. "hello world"
  2. Number: Integer or floating-point. No leading zeros, no hex, no NaN/Infinity. 42, 3.14, -7, 2.5e10
  3. Boolean: Exactly true or false (lowercase only).
  4. Null: Exactly null (lowercase only). Represents absence of value.
  5. Object: An unordered collection of key-value pairs. Keys must be strings. {"name": "FreeToolkit", "version": 1}
  6. Array: An ordered list of values. [1, "two", true, null]

Everything in a valid JSON document must be one of these six types or a nested combination of them.

The 5 Most Common JSON Validation Errors

These are the errors that trip up developers most frequently:

  1. Trailing commas: JavaScript allows trailing commas in arrays and objects, but JSON does NOT.
    {"a": 1, "b": 2,} ← INVALID. Remove the comma after the last value.
  2. Single quotes: JSON requires double quotes for all strings and keys.
    {'name': 'test'} ← INVALID. Use {"name": "test"}.
  3. Unquoted keys: JavaScript objects allow unquoted keys, but JSON requires every key to be a double-quoted string.
    {name: "test"} ← INVALID. Use {"name": "test"}.
  4. Comments: JSON does not support comments of any kind — no //, no /* */.
    If you need comments in configuration files, consider JSON5 or JSONC (non-standard extensions).
  5. Undefined and NaN: JavaScript's undefined, NaN, and Infinity are not valid JSON values. Use null instead.

JSON vs YAML vs XML: When to Use Which

FeatureJSONYAMLXML
ReadabilityGoodExcellent (indentation-based)Verbose (tag-heavy)
CommentsNot supportedSupported (#)Supported (<!-- -->)
Data types6 typesRich (dates, timestamps)All text (typed via schema)
File sizeCompactCompactLarge (30–50% bigger)
Parsing speedVery fastSlower (complex spec)Moderate
Primary useAPIs, web apps, configConfig files (Docker, K8s)Enterprise, SOAP, legacy

Rule of thumb: Use JSON for API communication and web application data. Use YAML for human-edited configuration files where comments are valuable. Avoid XML for new projects unless interfacing with legacy enterprise systems.

Formatting and Minifying JSON

Pretty-printing (formatting) adds indentation and line breaks to make JSON human-readable during development and debugging. This is essential when inspecting API responses, debugging database documents, or reviewing configuration files.

Minifying removes all unnecessary whitespace to produce the smallest possible payload. Minified JSON is used in production API responses and stored data to minimize bandwidth and storage costs.

FreeToolkit's JSON Formatter and JSON Validator run entirely in your browser's V8 engine — your API keys, tokens, and confidential data never leave your device.

Written by Dhaval Joshi. Have feedback or questions? Contact us at support@freetoolkit.online.