JSON Syntax Guide: Rules and Best Practices
Published February 8, 2026
Understanding JSON Structure
JSON (JavaScript Object Notation) is a lightweight, human-readable data format based on two fundamental structures: objects and arrays. Unlike XML's tag-based approach or CSV's tabular nature, JSON represents data through nested key-value pairs and ordered lists, making it ideal for APIs, configuration files, and data interchange between systems.
The beauty of JSON lies in its simplicity—it has only a few syntax rules that, when followed correctly, ensure your data can be parsed by any programming language's JSON library.
Core Syntax Rules
1. Objects Must Use Double Quotes
All keys in JSON objects must be enclosed in double quotes, never single quotes or unquoted.
✓ Correct:
{"name": "John", "age": 30}
✗ Incorrect:
{name: 'John', age: 30}
2. Strings Must Be Quoted
All string values must be enclosed in double quotes. Numbers, booleans, and null do not require quotes.
✓ Correct:
{"status": "active", "count": 42, "active": true, "data": null}
3. No Trailing Commas
The most common JSON error: trailing commas after the last item in objects or arrays.
✓ Correct:
{"items": [1, 2, 3]}
✗ Incorrect:
{"items": [1, 2, 3,]}
4. Special Characters Must Be Escaped
Characters like quotes, backslashes, and control characters need escaping with a backslash.
✓ Correct:
{"message": "He said \\"Hello\\""}
Data Types in JSON
JSON supports six data types. Understanding their proper representation prevents type conversion errors:
- String: Text enclosed in double quotes:
"hello" - Number: Integer or decimal without quotes:
42,3.14 - Boolean:
trueorfalse(lowercase) - Null:
nullrepresents absence of value - Array: Ordered list:
[1, 2, 3] - Object: Unordered key-value pairs:
{...}
⚠️ Important Type Notes
1(number) and"1"(string) are different types- Leading zeros in numbers are not allowed:
01is invalid - Dates have no native JSON type—use ISO 8601 strings:
"2026-02-08T10:30:00Z"
Best Practices for Clean JSON
Use Consistent Naming Conventions
Choose either camelCase or snake_case for keys and maintain consistency throughout. camelCase is common in JavaScript/web development:
Keep Nesting Reasonable
While JSON supports deep nesting, excessive levels become hard to read and navigate. Generally, limit nesting to 3-4 levels in most cases.
Use Descriptive Key Names
Avoid single-letter keys or cryptic abbreviations. Clear, descriptive names make your JSON self-documenting.
"createdDate" vs ✗ "cd"Handle Empty Values Explicitly
Be intentional about nulls vs empty strings vs empty arrays. They communicate different meanings in your domain.
Common Mistakes and How to Fix Them
❌ Single Quotes Instead of Double Quotes
JSON parser: "Unexpected token"
Solution: Replace all single quotes with double quotes. This is especially common when copying JSON from JavaScript objects.
❌ Unquoted Keys
Valid in JavaScript objects but invalid in JSON
Solution: Always quote object keys. Use SmartJson's validator to identify these issues instantly.
❌ Undefined or Functions
JavaScript-only concepts that crash JSON parsers
Solution: Convert to null, strings, or remove the property entirely.
❌ Line Breaks in Strings Without Escaping
Raw newlines break JSON validity
Solution: Use \\n for newlines, \\t for tabs.
Validation and Tools
Rather than manually checking your JSON, use automated validation tools. SmartJson's JSON Validator can identify syntax errors, suggest fixes, and show you the exact line causing problems. This approach catches 99% of issues instantly.
Try pasting problematic JSON into SmartJson's JSON Validator to see detailed error messages with line numbers and descriptions.
Key Takeaways
- Always use double quotes for keys and string values
- No trailing commas in objects or arrays
- Escape special characters properly
- Use lowercase for booleans and null
- Keep JSON readable with consistent formatting
- Use a validator when unsure about syntax