Guide
JSON vs JavaScript Object Literal
JSON looks like a JavaScript object literal, but it is a smaller data format with stricter syntax and no executable values.
The short version
A JavaScript object literal is source code. JSON is a data interchange format. The overlap is large enough to be confusing, but the rules are different: JSON keys and strings require double quotes, JSON has no comments, and JSON cannot represent functions, undefined, NaN, Infinity, Date objects, or regular expressions.
Valid JSON values
A JSON document can contain an object, array, string, number, boolean, or null. Strings must use double quotes. Object keys must also be strings in double quotes. Numbers cannot include JavaScript-only forms such as hex notation, NaN, Infinity, or numeric separators.
- Valid JSON string: "hello"
- Valid JSON boolean: true
- Valid JSON null: null
- Valid JSON object key: "name"
Valid JavaScript but invalid JSON
{ name: 'Ada', active: true, createdAt: new Date(), onSave() { return true }, tags: ['dev',], }
Valid JSON version
{ "name": "Ada", "active": true, "createdAt": "2026-05-13T00:00:00.000Z", "tags": ["dev"] }
Why APIs reject JavaScript-looking data
API servers generally parse request bodies with a JSON parser, not a JavaScript engine. That is a security and interoperability feature: every language can parse the same data without executing code. If a request body includes comments, methods, undefined, or new Date(), the server cannot safely treat it as plain data.
How to convert safely
Replace executable or language-specific values with plain data. Dates should become strings, missing values should become null or omitted keys, comments should move into documentation, and functions should be represented by explicit data fields such as a strategy name or type value.