Last updated
Basic JSON Validation
Paste any JSON string into the validator to instantly check if it is syntactically correct. The following is a valid JSON object representing a user profile:
{
"id": 1,
"name": "Alice Johnson",
"email": "alice@example.com",
"active": true,
"roles": ["admin", "editor"],
"address": {
"city": "New York",
"zip": "10001"
}
}
The validator confirms this is valid JSON and displays a formatted view with statistics: 1 object, 1 nested object, 1 array, and a nesting depth of 2.
Catching a Missing Comma Error
One of the most common JSON mistakes is forgetting a comma between properties. The validator catches this immediately:
{
"name": "Alice"
"email": "alice@example.com"
}
Error output:
SyntaxError: Expected ',' or '}' after property value
Line 3, Column 3
Found: "email"
Expected: ',' or '}'
The fix is to add a comma after the first property value:
{
"name": "Alice",
"email": "alice@example.com"
}
Trailing Comma Detection
Trailing commas are valid in JavaScript but not in JSON. This is a frequent source of errors when copying code from a JS file:
{
"host": "localhost",
"port": 5432,
"database": "mydb",
}
Error output:
SyntaxError: Trailing comma in object literal
Line 5, Column 1
JSON does not allow trailing commas after the last property.
Remove the trailing comma after "mydb" to fix it.
Single Quotes Instead of Double Quotes
JSON requires double quotes for all strings. Single quotes cause a parse failure:
{
'username': 'bob',
'score': 42
}
Error output:
SyntaxError: Unexpected token '
Line 2, Column 3
JSON keys and string values must use double quotes.
Corrected version:
{
"username": "bob",
"score": 42
}
Unquoted Property Names
Unlike JavaScript object literals, JSON requires all keys to be quoted strings:
{
name: "Carol",
age: 30
}
Error output:
SyntaxError: Unexpected token 'n'
Line 2, Column 3
Property names must be double-quoted strings in JSON.
Corrected version:
{
"name": "Carol",
"age": 30
}
Comments Are Not Allowed in JSON
Developers sometimes add comments to JSON config files, but JSON does not support comments:
{
// Database configuration
"host": "localhost",
"port": 5432 /* default port */
}
Error output:
SyntaxError: Unexpected token '/'
Line 2, Column 3
JSON does not support comments. Remove // and /* */ style comments.
If you need comments in config files, consider using JSONC (JSON with Comments) format or YAML instead.
Validating a Large API Response
After receiving a large API response, paste it into the validator to confirm it is well-formed before processing:
{
"status": "success",
"data": {
"users": [
{ "id": 1, "name": "Alice", "active": true },
{ "id": 2, "name": "Bob", "active": false },
{ "id": 3, "name": "Carol", "active": true }
],
"total": 3,
"page": 1,
"pageSize": 10
},
"timestamp": "2024-01-15T10:30:00Z"
}
The validator confirms this is valid and shows: 4 objects, 1 array, nesting depth 3, 12 total properties.
Schema Validation Example
Beyond syntax checking, validate JSON against a schema to ensure correct structure and types. Define a schema for a product object:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": ["id", "name", "price"],
"properties": {
"id": { "type": "integer" },
"name": { "type": "string", "minLength": 1 },
"price": { "type": "number", "minimum": 0 },
"inStock": { "type": "boolean" }
}
}
Then validate this data against it:
{
"id": "abc",
"name": "Widget",
"price": -5
}
Schema validation errors:
Error 1: /id — Expected integer, got string
Error 2: /price — Value -5 is less than minimum 0
Validating a Kubernetes ConfigMap
Before committing a JSON-format Kubernetes manifest, validate it to catch typos:
{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": {
"name": "app-config",
"namespace": "production"
},
"data": {
"DATABASE_URL": "postgres://localhost:5432/mydb",
"CACHE_TTL": "300",
"LOG_LEVEL": "info"
}
}
Valid JSON confirmed. Safe to commit and apply to the cluster.
Debugging Programmatically Generated JSON
When building JSON via string concatenation, errors are common. Paste the output to find the issue:
{"items": [{"id": 1, "value": "a"}, {"id": 2, "value": "b"} {"id": 3, "value": "c"}]}
Error output:
SyntaxError: Expected ',' or ']' after array element
Line 1, Column 47
Missing comma between array elements at index 1 and 2.
The string concatenation loop forgot to add a comma between the second and third array elements.
Unclosed Bracket Detection
Deeply nested JSON makes it easy to miss a closing bracket:
{
"config": {
"server": {
"host": "localhost",
"port": 8080
},
"database": {
"host": "db.example.com",
"port": 5432
}
}
Error output:
SyntaxError: Expected '}' to close object
Line 11, Column 1
Unclosed object starting at line 7 (database object is missing closing brace).
Add the missing } after line 10 to close the database object.
Validating Environment Configuration Files
Many applications use JSON for environment-specific configuration. Validate before deploying:
{
"environment": "production",
"features": {
"darkMode": true,
"betaFeatures": false,
"maxUploadSizeMB": 50
},
"integrations": {
"analytics": true,
"errorTracking": true
}
}
Valid JSON. The validator also shows the structure at a glance, confirming all expected sections are present before the config is deployed.