SmartJson.io
← Back to Articles

JSON Syntax Guide: Rules and Best Practices

By Santhi · Published February 8, 2026 · Updated July 12, 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,]}

What Chrome, Firefox, Safari, Node and Python each print for this: trailing comma error messages.

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: true or false (lowercase)
  • Null: null represents 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: 01 is 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:

{"firstName": "John", "lastName": "Doe", "emailAddress": "john@example.com"}

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

Got a specific error message? Paste it into JSON Error Messages, Decoded, or fix the input with JSON Repair.

❌ Single Quotes Instead of Double Quotes

Chrome and Node: Expected property name or '}' in JSON at position 1 (line 1 column 2) (other runtimes)

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

All Tools & Converters

JSON Tools

  • JSON Hub
  • JSON Formatter
  • JSON Validator
  • JSON Repair
  • JSON Error Messages
  • JSON Viewer
  • JSON Minify
  • JSON Stringify
  • JSON Sorter
  • JSON Compare
  • JSON to CSV
  • JSON to XML
  • JSON to YAML

XML Tools

  • XML Hub
  • XML Formatter
  • XML Validator
  • XML Compare
  • SOAP Formatter
  • WSDL Formatter
  • XML to JSON
  • XML to CSV

CSV Tools

  • CSV Hub
  • CSV Formatter
  • CSV Validator
  • CSV to JSON
  • CSV to XML
  • Compare Tools

    • JSON Compare
    • XML Compare
    • YAML Compare
    • CSV Compare
    • Text Compare

YAML Tools

  • YAML Hub
  • YAML Formatter
  • YAML Validator
  • YAML to JSON
  • Other Tools

    • Converters Hub
SmartJson.io

JSON, XML, CSV and YAML tools that run in your browser. Nothing you paste is uploaded.

Sitemap

Company

  • About Us
  • Contact
  • How We Test
  • Changelog
  • Privacy Policy
  • Terms of Service
  • Cookie Policy
  • Disclaimer

© 2026 SmartJson.io. All rights reserved.

Report a problem with this page
Made withfor developers