Software Development

JSON Validation: Common Syntax Errors and How to Prevent Them

Understand the strict specification of JSON format, common syntax pitfalls that crash parsers, and practical strategies for safe serialization in production.

Sunny SharmaSunny Sharma
Aug 21, 2026
6 min read
Code editor showing JSON syntax highlighting on a dark screen

JSON Validation: Common Syntax Errors and How to Prevent Them

JavaScript Object Notation (JSON) is the universal data interchange format of the web. Despite its simplicity, JSON is much stricter than JavaScript object literals. A single misplaced trailing comma or unescaped quote can break an API request, crash a build step, or corrupt a configuration file.

This guide reviews the most frequent JSON syntax errors, explains why JSON parsers reject them, and provides techniques for foolproof JSON handling.


1. The Strict Rules of the JSON Specification (RFC 8259) #

Unlike JavaScript source code:

  • Keys must always be enclosed in double quotes ("key"), never single quotes ('key') or bare words (key).
  • Strings must use double quotes ("value"), never single quotes or backticks.
  • Trailing commas are strictly prohibited after the last element of an array or object.
  • Comments are not supported (neither // nor /* */).
  • Values are limited to six primitive types: string, number, boolean, null, object, and array. undefined, functions, and NaN are not valid JSON.

2. Common JSON Syntax Mistakes #

Mistake 1: Trailing Commas #

JSON
// ❌ INVALID: Trailing comma on line 4
{
  "name": "Burnjet",
  "version": "1.0.0",
}
JSON
// ✅ VALID: No trailing comma
{
  "name": "Burnjet",
  "version": "1.0.0"
}

Mistake 2: Single Quotes on Keys or String Values #

JSON
// ❌ INVALID: Single quotes
{
  'status': 'active'
}
JSON
// ✅ VALID: Double quotes everywhere
{
  "status": "active"
}

Mistake 3: Unescaped Special Characters #

When strings contain double quotes, backslashes, or newlines, they must be escaped with a backslash (\):

JSON
// ❌ INVALID: Unescaped internal quotes
{
  "quote": "He said "Hello" to the team"
}
JSON
// ✅ VALID: Properly escaped quotes
{
  "quote": "He said \"Hello\" to the team"
}

3. Safe JSON Handling in TypeScript & Node.js #

When parsing user input or external API payloads, always wrap JSON.parse in a safe helper or use schema validation (such as Zod) to prevent unhandled runtime exceptions:

TYPESCRIPT
export function safeJsonParse<T>(raw: string, fallback: T): T {
  try {
    return JSON.parse(raw) as T;
  } catch (error) {
    console.warn('JSON parse error, using fallback value:', error);
    return fallback;
  }
}

4. Frequently Asked Questions #

Why does JSON forbid comments? #

Douglas Crockford, who specified JSON, intentionally omitted comments to prevent developers from using comments to hold parsing instructions or environment-specific directives, ensuring the format remained strictly portable.

How do I format large JSON strings quickly? #

You can use the browser-based Burnjet JSON Formatter & Validator to validate syntax, format with custom indentation, and spot errors with line-by-line feedback without transmitting any sensitive data to a server.

Related Engineering Publications