If your formatter says “invalid JSON”, it usually means the input isn’t strict JSON. Here’s how to spot and fix the most common issues.
In JSON, both keys and string values must use double quotes.
// ❌ Not JSON
{a: 'hello'}
// ✅ Valid JSON
{"a": "hello"}
Trailing commas are common when copying from languages like JavaScript.
// ❌ Not JSON
{"a": 1,}
// ✅ Valid JSON
{"a": 1}
// ❌ Not JSON
{
// comment
"a": 1
}
// ✅ Valid JSON
{
"a": 1
}
JSON supports null, true, false, numbers, strings, arrays, and objects. Values like undefined are not valid JSON.
Different whitespace/indentation makes diffs noisy. Format both JSON inputs first, then compare.