Skip to content
yutils
Example

Input (JS object literal)

{
  // comments OK
  id: 1,
  name: 'Alice',
  active: true,
  tags: ['admin', 'user',],
}

Output (standard JSON)

{
  "id": 1,
  "name": "Alice",
  "active": true,
  "tags": [
    "admin",
    "user"
  ]
}

Note

Four-step transform — strip comments, single → double quotes, add quotes around bare keys, strip trailing commas. No `eval` / `new Function` — safe.

Usage / FAQ

When to use

  • Convert an object literal copied from JS code into API-ready JSON
  • Clean up JSON5 / JSONC config files into strict JSON
  • Turn `console.log` debug output into pasteable JSON
  • Prepare input for Postman / Insomnia and similar API tools
  • Tidy 'loose JSON' with comments / trailing commas

FAQ

Q.Does this use `eval`?
A.Never — for security reasons. A custom token scanner strips comments, swaps quote styles, adds key quotes, removes trailing commas, then validates with `JSON.parse`.
Q.What about function values or regex literals?
A.Unsupported — JSON has no such concept, so parsing errors out. Remove functions, regexes, or `undefined` from the input first.
Q.How is this different from JSON5?
A.JSON5 formalizes unquoted keys, trailing commas, etc. as a superset. This tool accepts JSON5-compatible input and emits strict JSON — no JSON5 library dependency, just a self-contained transformer.
Fun facts
  • JSON was defined by Douglas Crockford in 2001 — born from web APIs needing something lighter than XML for data interchange. The 2013 ECMA-404 spec is short enough to fit on a single page.

    JSON.org
  • JSON is a *strict* subset of JavaScript object literals — keys must be double-quoted, trailing commas are forbidden, comments aren't allowed, function values aren't allowed. The two most common gotchas when copying JS objects into JSON: trailing commas and unquoted keys.

    RFC 8259 — JSON
  • JSON5 (Aseem Kishore, 2012) is the ergonomic cousin — comments, trailing commas, single quotes, and unquoted keys are all allowed. It's not a standard, but it's familiar from VS Code's `settings.json` and patterns in npm's `package.json`.

    JSON5