JSON has become the universal format for configuration files, API payloads, and data interchange. Its apparent simplicity is deceptive: JSON is a strict format with no tolerance for deviation, and a single misplaced comma or unclosed bracket will cause a parse failure. In a production environment, that failure can be silent, cascading, and expensive.
How JSON Failures Actually Manifest
Unlike syntax errors in application code, JSON parse errors often do not surface immediately. A configuration file loaded at service startup silently fails to parse, and the service uses default values or cached values instead. The application appears to function normally until a code path that relies on the missing configuration is exercised — which might be hours or days later, in a completely different context.
API payloads with invalid JSON fail at the consumer, not the producer. Your service successfully sends the response; the downstream consumer fails to parse it and returns a generic error. Debugging that error requires tracing back through multiple service boundaries to find the malformed payload.
The Most Common JSON Errors
Trailing commas: JSON does not allow a comma after the last element in an object or array. JavaScript (with modern parsers) is lenient about this, which means developers writing JSON by hand often add trailing commas out of habit. Standard JSON parsers will reject the file.
Unquoted keys: JSON object keys must always be double-quoted strings. JavaScript object notation allows unquoted keys; JSON does not. A configuration file edited by a developer familiar only with JavaScript objects will commonly contain unquoted keys that fail JSON parsing.
Single quotes: JSON requires double quotes for strings. Single quotes are not valid JSON regardless of how readable they look.
Comments: JSON does not support comments. Adding a // description line to a JSON configuration file will break any standards-compliant parser. Use JSON5 or a different format if you need comments.
Undefined and NaN: JSON supports null, true, false, strings, numbers, objects, and arrays. undefined and NaN are not valid JSON values and will cause a parse error or be silently dropped depending on the serializer.
Validation as a Deploy Gate
The simplest and most effective approach is to include JSON validation in your CI pipeline as a required step before merging or deploying. Any JSON configuration file that changes in a pull request should be validated automatically. A failing validation blocks the merge, not the production deploy — where the cost of discovery is much higher.
For API payloads, schema validation extends beyond syntax to structure: validating that required fields are present, that values are the expected types, and that enumerated fields contain permitted values. Tools like JSON Schema enable this level of validation and can be integrated into API test suites.
Validating Manually and in Development
Before committing a JSON file you have edited by hand, validate it explicitly. Use the JSON Validator to paste your JSON and identify exactly which line and character the error occurs on. The tool also provides formatting (prettify) and minification so you can normalize your JSON to a consistent style before committing it.
A Duplicate Key Bug That Passed Code Review
JSON technically allows duplicate keys in an object, but parsers disagree on what to do with them — most silently keep the last occurrence and discard the earlier ones, with no warning. A configuration file with a duplicate "timeout" key, one set to 30 and a later one set to 3000, parses without error in most environments, silently applying whichever value the specific parser happens to keep. The bug is invisible in the file itself, since both lines look like valid, intentional JSON.
This class of error is exactly what a validator catches that a human reviewer reading the file top to bottom usually misses — a linter or schema validator checking for duplicate keys flags it immediately, before the file ever reaches production, where the wrong timeout value might not surface as a visible problem for weeks.
Adding Validation to a CI Pipeline
The cheapest place to catch a malformed JSON file is before it merges, not after it deploys. A single CI step running a JSON schema validator against every changed .json file in a pull request catches syntax errors, missing required fields, and type mismatches automatically, without requiring a human reviewer to parse the file mentally during code review.
Most CI platforms support this with a few lines of configuration — a validation step that fails the build on invalid JSON, run before any deployment step. The cost is near zero in build time; the benefit is that a malformed configuration file, API response schema, or data export never reaches a stage where it can cause a production incident.
Frequently Asked Questions
Does JSON support comments for documenting configuration files?
No — the JSON specification does not include comments, and a strict parser will reject a file containing them. JSON5 and JSONC extend the format to allow comments for cases where documentation inside the file matters, at the cost of no longer being validated by a strict JSON parser.
What is the most common JSON syntax error?
A trailing comma after the last item in an array or object — valid in JavaScript object literals, invalid in strict JSON, and a frequent source of "works in my JavaScript file, fails when parsed as JSON" confusion.
Can invalid JSON cause a security issue, not just a functional bug?
Indirectly, yes — an application that fails to validate JSON input and instead tries to work around parsing errors can end up processing partially-parsed or unexpected data structures, which is a real attack surface in APIs accepting user-supplied JSON.
Should I validate JSON on the client side, server side, or both?
Both, for different reasons. Client-side validation gives immediate feedback to a user or developer; server-side validation is the actual security and correctness boundary, since client-side checks can always be bypassed by whoever is sending the request.
What tools exist for validating JSON quickly during development?
Command-line JSON validators, IDE extensions that flag syntax errors as you type, and browser-based validators all work well for quick checks — the right choice depends on whether you are validating during editing or as part of an automated pipeline.
Validate your own JSON instantly with the JSON validator.
The habit of validating JSON before committing takes seconds and eliminates an entire class of production incidents. It is one of the cheapest deploy checklists items available.