Invalid JSON Syntax
Error message
invalid input syntax for type json
Quick summary
The value you provided is not valid JSON — it has a syntax error like a missing quote, trailing comma, or unbalanced brace.
Why this happens
Malformed JSON — missing quotes, trailing commas, unbalanced braces
Application builds JSON by string concatenation instead of using a JSON serializer
Single quotes instead of double quotes in JSON keys or string values
NaN or Infinity values which are not valid JSON
Minimal example
INSERT INTO config (settings) VALUES ('{"name": "Ada",}');
-- Trailing comma after the last property → invalid JSONINSERT INTO config (settings) VALUES ('{"name": "Ada"}');JSON does not allow trailing commas. Removing the trailing comma makes it valid JSON.
How to diagnose
Validate the JSON string with a JSON parser before inserting
Check for common JSON mistakes: single quotes, trailing commas, missing quotes
Log the exact JSON string being inserted to inspect it
How to fix
Fix the JSON syntax — use double quotes, remove trailing commas, balance braces
Use a JSON serializer in your application instead of string concatenation
Use JSON validation before inserting into the database
How to prevent
Always use a JSON serializer (JSON.stringify, json.dumps) to generate JSON
Validate JSON before storing it
Use JSONB columns (PostgreSQL) for better validation and indexing
Related Resources
Related Lessons
- MongoDB Basics
Learn about JSON/document storage.