Skip to content
100% local

JS object to JSON

Convert a JavaScript object literal into strict, valid JSON.

Input

JS object to JSON

Paste a JavaScript object literal and this tool converts it into strict JSON you can use in an API response, a config file, or a test fixture. It accepts the syntax real JS code actually uses: unquoted keys, single-quoted strings, trailing commas, line and block comments, and plain template strings without ${…} expressions — none of which are valid in JSON on their own.

The indentation option formats the result with 2 spaces, 4 spaces, a tab, or a single minified line. Undefined values have no JSON equivalent, so the undefined-values option lets you either omit those keys entirely or convert them to null, whichever your consumer expects. Turning off "Remove comments" makes stray comments a reported error instead of silently discarding them, useful when you want to confirm the input is otherwise clean. Sort keys arranges every object's properties alphabetically at every nesting level, which makes two JSON payloads easier to diff. Switching the direction to JSON → JS object reverses the conversion, producing a JS literal with quotes dropped from any key that is a valid identifier — handy for pasting config straight into source code.

Malformed input — a missing colon, an unterminated string, a template expression — is reported with the line and column where parsing stopped, so you can find the problem instead of guessing. Output is capped at 10 MB to keep the tab responsive; extremely large objects should be split into smaller pieces first.

Everything runs locally in your browser — nothing you paste is uploaded anywhere. When you're done, copy the result, download it as a .txt file, or send it straight to another tool's input to keep working on it.

FAQ

What JavaScript syntax does it understand?
Objects and arrays with unquoted or quoted keys, single- and double-quoted strings, plain template strings, numbers (including negatives, decimals and underscores), true/false/null/undefined, trailing commas, and // and /* */ comments.
What happens to undefined values?
By default a key whose value is undefined is left out of the JSON entirely, since JSON has no undefined. Switch "Undefined values" to "Convert to null" if you need the key to stay present.
Can it convert JSON back into a JS object literal?
Yes — switch Direction to "JSON → JS object". Keys that are valid JavaScript identifiers are printed without quotes; the rest keep single quotes.
Does it evaluate the object as code?
No. Your input is parsed as text by a dedicated parser — it is never executed, so functions, variables and template expressions like ${…} aren't supported and are reported as errors rather than run.
Is my data uploaded anywhere?
No. The conversion runs entirely in your browser — your object never leaves your device.