Developer Tools & Data Formats

How to Format, Validate, and Fix Common JSON Syntax Errors (Trailing Commas & Quotes)

Diagnose and fix SyntaxError: Unexpected token in JSON at position, trailing commas, unescaped newlines, single quotes, and 64-bit integer precision loss in JavaScript.

By Cometflow Developer Experience Team • Updated 2026-10-19

Although JSON (JavaScript Object Notation, RFC 8259) derived its syntax from JavaScript object literals, its grammar is significantly stricter. A payload that compiles inside a .js or .ts file will often fail with a SyntaxError when passed to JSON.parse() or sent as an HTTP API request body.

1. The 5 Most Common JSON Syntax Errors & Fixes

Error Pattern Invalid JSON Example Valid RFC 8259 Fix
Trailing Comma { "a": 1, "b": 2, } { "a": 1, "b": 2 }
Single Quotes or Unquoted Keys { name: 'Alice' } { "name": "Alice" }
Unescaped Multiline Strings { "bio": "Line 1 Line 2" } { "bio": "Line 1\nLine 2" }
Undefined / NaN / Infinity { "score": NaN, "ref": undefined } { "score": null, "ref": null }

2. Generating TypeScript Interfaces from Validated JSON

Once you have formatted and verified your raw API response in the JSON Formatter & Validator, paste the payload into our JSON to TypeScript Interface Generator to create strict compile-time types automatically.

Frequently Asked Questions

Why does JSON.parse throw "Unexpected token } in JSON" when my object looks fine?

According to RFC 8259, strict JSON forbids trailing commas after the last property in an object or the last element in an array. Removing the trailing comma before } or ] resolves the error.

Why do large 64-bit database IDs change their last two digits when parsed in JavaScript?

JavaScript numbers use IEEE 754 double-precision floats, which only safely represent integers up to Number.MAX_SAFE_INTEGER (9,007,199,254,740,991). Always serialize 64-bit Snowflake or BigInt IDs as JSON strings ("id": "9223372036854775807").