Complete JSON Guide
Complete JSON guide for beginners. Learn JSON syntax, data types, structure, and examples. Reference for developers, students, and anyone working with JSON.
Last updated: March 2026 • JSON Version: RFC 8259
What is JSON?
JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format. Despite the name, JSON is language-independent and works with virtually every programming language.
JSON was created by Douglas Crockford in the early 2000s as a simpler alternative to XML. Today, JSON is the standard for APIs, configuration files, and data storage.
Key Facts:
- Human-readable and writable
- Machine-parsable and -generable
- Language-independent
- Based on JavaScript object literals
- Supports complex data structures
JSON Syntax Basics
JSON is built on two structures:
- Collection of key/value pairs (object)
- Ordered list of values (array)
Syntax Rules
- Data in key/value pairs
- Separated by commas
- Curly braces
{}hold objects - Square brackets
[]hold arrays - Keys must be strings (in double quotes)
- String values must be in double quotes
- No trailing commas allowed
- No comments allowed
Example JSON Object
JSON Data Types
JSON supports six data types:
1. String
Text data, enclosed in double quotes:
Valid String Characters:
- Letters:
a-z,A-Z - Digits:
0-9 - Symbols:
!@#$%^&*()_+-=[]{}|;:',.<>? - Spaces and whitespace
- Unicode characters:
\uXXXX
Escape Sequences:
\"- Double quote\\- Backslash\/- Forward slash\b- Backspace\f- Form feed\n- New line\r- Carriage return\t- Tab\uXXXX- Unicode character
2. Number
Numeric values, can be integer or floating-point:
Valid Number Formats:
- Integers:
42,-7,0 - Floats:
3.14,-0.001,1.0 - Scientific notation:
1.23e4,1.23E-4 - No leading zeros:
0.42(not.42)
3. Boolean
Logical values, either true or false:
4. Array
Ordered list of values, enclosed in square brackets:
5. Object
Unordered collection of key/value pairs, enclosed in curly braces:
6. Null
Represents empty or non-existent value:
Note: null is different from false, 0, or empty string "".
JSON Structure Examples
Simple Object
Nested Objects
Array of Objects
Complex Structure
JSON vs. JavaScript Object
Example - Valid JSON:
Example - Valid JavaScript Object (Not JSON):
JSON vs. XML vs. CSV
Parsing JSON in Different Languages
JavaScript
Python
PHP
Java
Common JSON Use Cases
API Responses
REST APIs return JSON as the standard response format:
Configuration Files
Application settings in JSON format:
Data Storage
NoSQL databases like MongoDB store data as JSON-like documents:
JSON Best Practices
- Use camelCase for keys:
"firstName", not"first_name" - Use meaningful key names:
"createdAt", not"date1" - Keep structure consistent: All user objects should have same fields
- Use appropriate data types: Numbers for numeric values, not strings
- Format for readability: Pretty-print for human readers
- Validate JSON: Use validators before using in production
- Handle nulls gracefully: Don't send empty strings when null is appropriate
- Use ISO 8601 for dates:
"2026-03-04T12:00:00Z" - Limit nesting depth: Very deep structures are hard to parse
- Document your JSON: Provide schema or examples
JSON Tools & Resources
- JSON Validator:
- Official Spec:
- JSON Schema:
- Online Testers: JSONLint, JSON Editor Online
Practice your JSON skills with our free online editor. Features include real-time validation, tree view, and formatting tools—all without registration.
References: RFC 8259 (JSON specification), ECMA-404, MDN JSON documentation.