Guide

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 JSON, the safest converter is JSON.parse(jsonText). It returns a normal JavaScript object, array, string, number, boolean, or null without evaluating code.

JSON input

{ "name": "Ada", "active": true, "skills": ["math", "notes"] }

JavaScript usage

const user = JSON.parse(jsonText); console.log(user.name);

Object literal input is different

A JavaScript object literal such as { name: 'Ada', active: true } is not JSON. Before converting it with JSON.parse, repair missing quotes in JSON keys, convert single quotes to double quotes, remove comments, and remove trailing commas.

When to avoid eval

Do not use eval to convert unknown text into an object. eval executes code. JSON.parse only parses data, which is why strict JSON is safer for API payloads, configuration, logs, and pasted examples.