Web Utility Desk
Blog Guides JSON URL Resources Search

Resources ยท Cheat Sheets

JSON Syntax Cheat Sheet & Quick Reference

Overview

JavaScript Object Notation (JSON), specified by RFC 8259, is the ubiquitous text-based data interchange format for modern REST APIs, configuration files, and document databases. While lightweight and human-readable, JSON enforces strict syntax rules where even a single misplaced comma or unescaped character causes catastrophic parser exceptions.

This reference sheet organizes core data types, strict formatting rules, code examples, common pitfalls, and API best practices for immediate lookup during coding and code reviews.

Syntax Tables & Core Data Types

JSON supports exactly six primitive and structured data types. Every value in a valid JSON document must conform strictly to one of these types:

Data Type Syntax Rule Valid Example
Object Unordered collection of key/value pairs enclosed in curly braces `{}`. Keys must be double-quoted strings. `{"name": "Alice", "role": "admin"}`
Array Ordered list of zero or more values enclosed in square brackets `[]`. Elements are comma-separated. `["read", "write", "delete"]`
String Unicode character sequence enclosed in double quotes `" "`. Backslash `\` is used for escaping. `"Hello, world!\nStatus: OK"`
Number Signed decimal number (integer or floating point). Cannot have leading zeros (`01`) or represent `NaN`/`Infinity`. `42`, `-17.5`, `1.2e+10`
Boolean Literal lowercase keywords only. Quoted values `"true"` become strings. `true` or `false`
Null Literal lowercase keyword representing absence of value. Cannot be capitalized (`Null` or `NULL`). `null`

Practical Examples

Below is a production-grade API response payload combining nested objects, arrays of objects, ISO 8601 timestamp strings, and nullable fields:

{
  "status": "success",
  "data": {
    "user": {
      "id": "usr_9b8c7d6e",
      "username": "jaytech",
      "isActive": true,
      "deletedAt": null,
      "roles": ["developer", "reviewer"],
      "metadata": {
        "lastLogin": "2026-07-03T10:30:00Z",
        "loginCount": 142
      }
    }
  }
}

Common Mistakes & How to Avoid Them

  • Trailing Commas: Placing a comma after the final key/value pair (`{"id": 1,}`) causes immediate parser failures in strict JSON parsers. Always verify list terminations.
  • Single Quotes: Using single quotes for keys or values (`{'user': 'alice'}`) violates RFC 8259. Use double quotes consistently.
  • Unescaped Control Characters: Literal line breaks, tabs, or unescaped double quotes inside string values break lexical scanning. Escape them (`\n`, `\t`, `\"`).
  • Comments: Adding `//` or `/* */` comments inside JSON files fails standard parsing. Remove all comments before sending payloads over the wire.

Best Practices for APIs

  • Consistent Naming Conventions: Standardize on `camelCase` or `snake_case` across all API endpoints (e.g., `createdAt` vs `created_at`).
  • ISO 8601 Timestamps: Serialize dates in UTC ISO format (`YYYY-MM-DDTHH:mm:ssZ`) rather than ambiguous locale strings or arbitrary epoch integers.
  • Enveloping Responses: Wrap lists or root payloads inside a structured object (`{"data": [...]}`) to allow future extensibility without breaking client parsing.

Related Interactive Tools

JF

JSON Formatter

Beautify, indent, and organize raw JSON data with instant syntax error highlighting.

Open tool
JV

JSON Validator

Validate strict RFC compliance and pinpoint exact line numbers for syntax failures.

Open tool
JC

JSON Compare Tool

Compare two JSON payloads side by side to identify key additions, removals, and value diffs.

Open tool
C2J

CSV to JSON Converter

Convert tabular CSV spreadsheet exports into structured JSON objects or arrays.

Open tool

Related Engineering Guides

DOC

What Is JSON?

Complete beginner and intermediate walkthrough of JSON syntax, history, and core architecture.

Read guide
DBG

How to Debug Invalid JSON

Actionable diagnostic workflow to track down parser failures in multi-megabyte payloads.

Read guide
API

JSON Best Practices for APIs

Design durable request and response schemas with cleaner error handling contracts.

Read guide
FIX

Common JSON Errors & Fixes

Pinpoint and resolve trailing commas, single quote anomalies, and unescaped characters.

Read guide

Frequently Asked Questions

Why does JSON reject single quotes or trailing commas?

RFC 8259 strictly mandates double quotes for all property keys and string values, and forbids trailing commas after the final element in arrays or objects to ensure deterministic parser behavior.

Does JSON support comments or date data types?

No. JSON does not natively support comments or first-class date types. Dates should be serialized as ISO 8601 strings (e.g., '2026-07-03T12:00:00Z').

How can I instantly format and check invalid JSON syntax?

Paste your payload into our browser-based JSON Formatter or JSON Validator to highlight exact syntax error line numbers and beautify formatting.

Web Utility Desk

Free web utility tools for everyday technical work.

Tools JSON Formatter JSON Validator CSV to JSON Converter Regex Tester Regex Generator SQL Formatter JSON Compare Tool HTML Minifier CSS Minifier JavaScript Minifier
Site About Blog Guides Resources Contact Privacy Terms