Loading tool, please wait…
While JSON was originally derived from JavaScript object literal syntax, JSON is a serialized text interchange specification with strict rules. This reference maps all syntax and runtime differences.
| Feature | JSON (RFC 8259) | JavaScript Object Literal |
|---|---|---|
| Format Nature | Serialized Text String | In-Memory Heap Object |
| Key Quotes | Double quotes mandatory ("id") | Optional for valid identifiers (id) |
| String Literals | Double quotes only ("val") | Single ('), double ("), or backticks (`) |
| Trailing Commas | Forbidden (SyntaxError) | Allowed in arrays and objects |
| Comments | Forbidden (// or /* */) | Allowed anywhere in source code |
| Functions & Methods | Not supported (omitted by stringify) | Fully supported |
| undefined | Not supported (omitted from objects) | Fully supported |
| NaN and Infinity | Not supported (converted to null) | Supported as numeric values |
| Symbols | Not supported (omitted from keys) | Supported as keys and values |
| Date Objects | Serialized to ISO 8601 string | Supported as Date instances |
When converting a JS object to JSON via JSON.stringify(), several JavaScript data types are transformed silently: • undefined, Function, and Symbol values inside objects are completely omitted. • undefined, Function, and Symbol values inside arrays are converted to null. • NaN and Infinity numbers are converted to null. • Objects with toJSON() methods (like Date) use the return value of that method.
const data = {
fn: () => "hello",
missing: undefined,
list: [undefined, NaN, () => {}],
time: new Date("2026-08-30T00:00:00Z")
};
console.log(JSON.stringify(data));
// {"list":[null,null,null],"time":"2026-08-30T00:00:00.000Z"}Format and inspect clean JSON structures in browser memory.
{
"title": "Config",
"active": true,
"count": 42
}