JSON Formatting Basics: How to Read and Write JSON
A beginner-friendly guide to JSON syntax, formatting, and common use cases in web development.
JSON (JavaScript Object Notation) is the most popular data format for web APIs and configuration files. Understanding JSON is essential for web developers, data analysts, and anyone working with modern applications.
JSON Syntax
JSON supports six data types:
- Strings — enclosed in double quotes: “hello”
- Numbers — integers or decimals: 42 or 3.14
- Booleans — true or false
- Null — null
- Arrays — ordered lists: [1, 2, 3]
- Objects — key-value pairs: {“key”: “value”}
Formatting Rules
- Keys must be strings in double quotes
- Strings must use double quotes (not single quotes)
- No trailing commas after the last item
- No comments allowed in standard JSON
- Unicode characters are supported
Common Mistakes
- Using single quotes instead of double quotes
- Adding a trailing comma after the last element
- Including comments (JSON does not support them)
- Using undefined (use null instead)
- Forgetting to quote property names
Working with JSON
In JavaScript, use JSON.parse() to convert a JSON string to an object, and JSON.stringify() to convert an object to a JSON string. The second parameter of JSON.stringify can add formatting.
Validating JSON
Always validate your JSON before using it. A single missing comma or mismatched bracket can cause parsing errors. Use online validators or our text tools to check your JSON syntax.
Need text tools?
Try our free online text tools for instant results.