JSON to JS Converter — Generate JS Object Literal Free
Convert JSON to JavaScript object literal with cleaner syntax: unquoted keys, single quotes, optional const/var prefix. Free.
About JSON to JavaScript Converter
A JSON-to-JS converter transforms strict JSON into a JavaScript object literal — unquoted keys (where valid identifier), single quotes (more idiomatic JS), optional `const x = {...}` wrapper, and configurable indentation. Useful for: pasting JSON config into a JS file with cleaner syntax, generating mock data fixtures from JSON API responses, and producing easier-to-read JS source from JSON. The ZTools JSON to JS Converter handles unicode keys properly (only valid JS identifiers go unquoted), optionally promotes ISO date strings to `new Date(...)` calls, and emits ESLint-friendly output.
Use cases
- JSON config → JS module. A `.json` config promoted to `.js` module to allow comments and computed values: tool generates `export const config = {...}` from JSON.
- API response → mock fixture. Captured a JSON API response; want JS-format fixture for tests. Cleaner syntax + comments support after conversion.
- JSON-blob doc → readable JS. A 200-line JSON config is hard to read. JS object literal with unquoted keys + single quotes is friendlier.
- Migration: JSON → CommonJS module. `module.exports = require("./config.json")` → just import-as-JS for a richer module.
How it works
- Paste JSON. Strict valid JSON.
- Pick output style. Single quotes (default JS idiom) or double; unquote valid-identifier keys; wrap in `const x = {...}`.
- Date promotion (optional). Detected ISO 8601 strings (`"2026-05-06T..."`) become `new Date("2026-05-06T...")` calls.
- Convert. AST-driven; output is ESLint-friendly.
- Copy / download. .js file or clipboard.
Examples
Input: `{"name":"Alice","age":30,"active":true}`
Output: `{ name: 'Alice', age: 30, active: true }` — keys unquoted, single quotes, idiomatic JS.
Input: `{"created":"2026-05-06T10:00:00Z"}`
Output: `{ created: new Date('2026-05-06T10:00:00Z') }` — ISO promoted to Date.
Input: JSON with `"2nd-key": ...`
Output: `"2nd-key"` stays quoted (not a valid JS identifier).
Frequently asked questions
When does a key stay quoted?
When it's not a valid JS identifier: starts with digit, contains hyphens/spaces, is a reserved word, or is non-ASCII. Tool quotes those automatically.
Single vs double quotes?
Both valid JS. Single quotes are more idiomatic in modern JS / TS codebases (+ standard ESLint rule). Tool defaults to single; configurable.
Will output be ESLint-clean?
Generally yes — unquoted-when-possible keys + single quotes + 2-space indent matches default ESLint config.
Can the JS be parsed back?
Yes — output is valid JS and `eval` or `(...)`-wrap evaluates to the same object. For round-trip, use the JS-to-JSON converter.
Date promotion safe?
Mostly — but ISO format detection is heuristic. Strings that look like dates but aren't may be wrongly promoted. Disable for safety in those cases.
Comments on output?
Optional toggle: insert "// generated from JSON" header. Useful for tracking provenance.
Pro tips
- Single quotes + unquoted keys + 2-space indent = idiomatic modern JS.
- Use date promotion only when you need actual Date objects; otherwise strings are simpler.
- For TypeScript output, pair this tool with the JS-to-TS converter — gets you typed JS from JSON.
- For very large JSON (10k+ lines), consider keeping JSON-as-is and `import json from "./data.json"`.
- For dynamically-keyed objects, output may have many quoted keys — that's normal, JS rules.
Reviewed by Ahsan Mahmood · Last updated 2026-05-06 · Part of ZTools.
For the full,
formatted version of this page, please enable JavaScript and reload
https://ztools.zaions.com/json-to-js.