JSON to JavaScript Object Converter
Strict JSON can be converted to a JavaScript object with JSON.parse. JavaScript object literals need cleanup before they are valid JSON.
Convert JSON in JavaScript
If the input is already valid RFC 8259 JSON, the safest converter is JSON.parse(jsonText). It returns a normal JavaScript object, array, string, number, boolean, or null — and crucially, it does not evaluate code.
JSON Input
{
"name": "Ada",
"active": true,
"skills": ["math", "notes"]
}
JavaScript Usage
const user = JSON.parse(jsonText);
console.log(user.name); // "Ada"
console.log(user.active); // true
console.log(user.skills[0]); // "math"
What Each JSON Value Becomes
The mapping is deterministic — every JSON value has exactly one JavaScript counterpart after JSON.parse:
| JSON value | JavaScript value after JSON.parse |
|---|---|
{ … } |
plain object (Object.prototype) |
[ … ] |
array (Array.prototype) |
"hello" |
string |
42, 3.14, -1e3 |
number |
true, false |
boolean |
null |
null |
| (nothing) | undefined — never the result of JSON.parse, since JSON has no undefined literal |
Object Literal Input Is Different
A JavaScript object literal such as { name: 'Ada', active: true } is not JSON. Before JSON.parse will accept it, you have to repair the differences: quote the keys, swap single quotes for double quotes, remove comments, and remove trailing commas. See JSON vs JavaScript object literal for the full side-by-side comparison, or paste the snippet into JSON Fix to apply all the fixes in one pass.
When to Avoid eval
Do not use eval to convert unknown text into an object. eval executes code — a malicious payload can run anything in the calling scope. JSON.parse only parses data, with a small fixed grammar; it can produce a value but cannot run a function. That's why strict JSON is the right shape for API payloads, configuration files, log lines, and pasted examples.
Edge Cases: Dates, undefined, and Functions
JSON has no Date, undefined, or function type. Dates round-trip as ISO strings, undefined values are dropped during JSON.stringify, and functions cannot be represented at all. The JSON vs JavaScript guide's round-trip section enumerates every type that gets lost or transformed.
If a JavaScript object contains a Date that you need back as a Date (not a string) after JSON.parse, pass a reviver function:
const user = JSON.parse(jsonText, (key, value) =>
key === 'createdAt' ? new Date(value) : value
);
The reviver runs for every key/value pair and can return a replacement value — useful for restoring types that JSON couldn't carry natively.
TypeScript and Inferred Types
JSON.parse returns any because the parser cannot know the shape ahead of time. For typed access:
- Validate at the boundary with a schema library like Zod or io-ts — the parsed type comes from the schema, so the type system reflects what was actually validated, not what was promised in a comment.
- Generate an interface from a sample using the JSON to TypeScript tool — useful when iterating against an external API whose payloads you don't fully control.
A bare JSON.parse(text) as User cast compiles but doesn't verify anything at runtime; it's a promise to the compiler, not a guarantee.
The Reverse Direction: Object to JSON
JSON.stringify(value, null, 2) produces formatted JSON from a JavaScript value (the third argument 2 is the indent width). It silently drops undefined, functions, and Symbol keys; circular references throw TypeError. Pass a replacer function as the second argument to control which fields survive — useful for stripping internal fields, redacting secrets, or normalizing date formats before sending an object over the wire.
For a hands-on view of what JSON.stringify produces with different options, use the JSON Stringify tool — it shows the output for each indent and replacer choice without writing code.
See also
This guide pairs with JSON vs JavaScript object literal (the syntax-difference reference) and the repair workflow hub (for cleaning JS-style snippets back into valid JSON before parsing). For LLM-produced almost-JSON, see the LLM JSON repair hub.
Sources
- RFC 8259 — the JSON Data Interchange Format (IETF, the canonical JSON grammar)
- MDN —
JSON.parse(the safe parser, including reviver behavior) - MDN —
JSON.stringify(the reverse direction, including replacer behavior) - MDN — Object initializer (the JS object-literal syntax, ECMA-262 §13.2.5)
Last reviewed June 2026.
JSON repair guides
Topic hubs
- JSON Parse Errors: Read the Message, Jump to the Fix
- Fix Invalid JSON: From 'What's Wrong' to a Clean File
- JSON Formatter, Validator, Viewer: Pick the Right Tool
- Repair LLM JSON Output: Handling Almost-JSON from AI
- Privacy: JSON Tools That Don't Leave Your Browser
- JSON Interop: YAML, CSV, XML, JWT, Schema
Specific guides
- How to Decode Base64 Strings (and JWT Payloads)
- URL Encoding: Percent-Encode Query Parameters and Paths
- Convert YAML to JSON (and Avoid Indentation Errors)
- Convert JSON to CSV: Flatten an Array of Objects
- Convert JSON to XML: Root Elements, Attributes, and Arrays
- Escape JSON as a String Literal (and Decode Double-Encoded JSON)
- Fix Trailing Comma in JSON
- Fix Single Quotes in JSON
- Fix Unquoted Keys in JSON
- Repair LLM JSON Output
- Fix JSON Parse Error: Expected Property Name
- JSON vs JS Object Literal: The Key Differences
- Validate JSON Before API Requests
- JSON Formatter vs JSON Repair
- Fix JSON Unexpected Token Errors