JSON5 → JSON Converter

Paste JSON5 (with comments, trailing commas, unquoted keys) and convert it to standard JSON.

JSON5 Input
Standard JSON Output

JSON5 vs JSON — The Bottom Line

Use JSON5 for configuration files that humans edit — where comments explaining options and trailing commas reducing diff noise genuinely improve the developer experience. Use standard JSON for everything else: API responses, data storage, machine-generated data, and anything consumed programmatically.

JSON5 is a superset of JSON — every valid JSON document is also valid JSON5. JSON5 adds features from ECMAScript 5 that make it more comfortable for humans to write and read.

Side-by-Side Example

JSON5

json5
// JSON5 — A superset of JSON for human-written config files
{
  // Application settings
  name: "my-app",       // unquoted keys are allowed
  version: '1.0.0',     // single-quoted strings

  server: {
    host: "localhost",
    port: 8080,
    debug: true,        // trailing comma in object
  },

  // Arrays with trailing commas
  features: [
    "auth",
    "logging",
    "metrics",          // trailing comma in array
  ],

  // Numeric literals
  maxInt:   0xFF,       // hex number
  pi:       .5,         // leading decimal point
  timeout:  +Infinity,  // special float

  // Multi-line string
  description: "This is a long description that spans multiple source lines",
}

Standard JSON equivalent

json
{
  "name": "my-app",
  "version": "1.0.0",
  "server": {
    "host": "localhost",
    "port": 8080,
    "debug": true
  },
  "features": [
    "auth",
    "logging",
    "metrics"
  ],
  "maxInt": 255,
  "pi": 0.5,
  "timeout": null,
  "description": "This is a long description that spans multiple source lines"
}

What JSON5 Adds Over JSON

FeatureJSONJSON5Example
CommentsNot supported// and /* */// This is a comment
Trailing commasNot allowedAllowed{ "a": 1, } and ["x",]
Unquoted keysMust be quotedValid identifiers{ name: "value" }
Single-quoted stringsNot allowedAllowed{ name: 'John' }
Multiline stringsEscaped \nBackslash escape"line1 \ line2"
Hex numbersNot supported0x prefixport: 0x1F90
Leading decimal0.5 required.5 allowedpi: .5
Trailing decimal0.0 required1. allowedprice: 100.
+InfinityNot supportedAllowedmax: +Infinity
-InfinityNot supportedAllowedmin: -Infinity
NaNNot supportedAllowedresult: NaN
Positive signNot supported+N allowedoffset: +5

JSON5 in the Real World

ESLint uses JSON5 for its configuration file (.eslintrc), which allows developers to add comments explaining why rules are configured a certain way:

json5
// .eslintrc (uses JSON5 syntax — comments allowed)
{
  // This is a comment explaining the config
  extends: ["eslint:recommended"],
  rules: {
    "no-unused-vars": "warn",
    "no-console": "off",    // trailing comma OK
  },
  env: {
    browser: true,
    node: true,
  },
}

Using JSON5 in Your Project

javascript
// Node.js — parsing JSON5
const JSON5 = require("json5");

const config = JSON5.parse(`{
  name: "my-app",
  // comment
  version: '1.0.0',
}`);

// Browser — CDN
import JSON5 from "https://unpkg.com/json5/dist/index.min.mjs";

// Webpack / Babel
// Use json5-loader for .json5 files in webpack

When to Use JSON5

  • Config files humans edit — .eslintrc, .babelrc, TypeScript tsconfig.json (which already accepts JSON5-like syntax with comments)
  • Annotated configuration — when you need comments to explain each option to future developers
  • Reduced diff noise — trailing commas mean adding a new last item changes only one line, not two
  • Build tool configs — some build tools natively support JSON5 config files

When NOT to Use JSON5

  • API responses — consumers expect standard JSON; JSON5 will break native JSON.parse()
  • Data storage — databases, files, and caches should use standard JSON for universal compatibility
  • Machine-generated data — tools that serialize objects should use standard JSON
  • Public-facing configuration — if external tools or users read your config, standard JSON is safer
  • Performance-critical parsing — JSON5 parsing is slower than native JSON.parse() (which is implemented in C++)

Alternatives to JSON5

FormatCommentsTrailing CommasBest For
JSONNoNoAPIs, data storage, machine-generated
JSON5YesYesHuman-edited config files
JSONCYesYesVS Code settings, TypeScript tsconfig
YAMLYesN/ADevOps config (K8s, CI/CD, Ansible)
TOMLYesN/ARust/Python project config files
HCLYesYesTerraform, HashiCorp tooling

Frequently Asked Questions

No — browsers only support standard JSON natively via JSON.parse(). To use JSON5 in a browser, you need the json5 npm package (about 10 KB minified). This adds a small overhead, so consider whether the benefits outweigh the cost for browser-side configs.

JSONC is a variant of JSON that allows // and /* */ comments but does not include the other JSON5 extensions (trailing commas vary by implementation). VS Code uses JSONC for settings.json and keybindings.json. TypeScript's tsconfig.json also uses a JSON5-like syntax that allows comments and trailing commas.

Yes — JSON5 is a superset, so it supports all JSON types: strings, numbers, booleans, null, arrays, and objects. JSON5 additionally supports special float values (Infinity, NaN) and some numeric literal formats (hex, leading/trailing decimal point).

JSON5 is inspired by ES5 object literal syntax and looks very similar, but they are not identical. JSON5 does not support arbitrary JavaScript expressions, function values, undefined, or template literals. It is a subset of JavaScript object literal syntax.

Since JSON5 is a superset of JSON, any valid JSON file is already valid JSON5. Migration means switching your parser from JSON.parse() to JSON5.parse() and optionally adding comments and trailing commas to your files. No structural changes are required.

Related Tools