Learn
Step-by-step tutorials to get you up and running in minutes.
Getting Started
JSON6 is a superset of JSON that adds modern ES6+ features. Here's what you need to know to start using it.
Understand what JSON6 is
JSON6 extends JSON with features borrowed from ECMAScript 5.1. It's designed for configuration files and other human-edited data.
Key insight: Every JSON file is already valid JSON6. You can adopt features gradually.
Install the JSON6 library
To parse JSON6 in your code, you need the json6 package. Install it via npm:
npm install json6Create your first JSON6 file
Create a file named config.json6 with developer-friendly features:
{ // App configuration name: 'my-app', version: '1.0.0', debug: true, // Enable for development }Parse it in your code
Use the JSON6 library to read your config file:
import JSON6 from 'json6'; import { readFileSync } from 'fs'; const configText = readFileSync('config.json6', 'utf8'); const config = JSON6.parse(configText); console.log(config.name); // 'my-app'Syntax Fundamentals
Master the core JSON6 syntax features that make configuration files more readable.
Comments
Add explanations with // or /* */
// Single-line comment /* Multi-line comment */Trailing Commas
Safe to leave commas after the last item
{ a: 1, b: 2, } // OK! [ 1, 2, 3, ] // OK!Unquoted Keys
Skip quotes on valid identifiers
{ name: 'value' } // Instead of {"name": "value"}Single Quotes
Use single or double quotes for strings
{ msg: 'Hello "World"' } // No escaping neededExtended Numbers
Hex, Infinity, NaN, and flexible decimals
{ hex: 0xFF, inf: Infinity, half: .5 }Multi-line Strings
Continue strings across lines with backslash
{ text: 'Line 1 \ Line 2' }Using JSON6 in Node.js
Complete guide to integrating JSON6 in your Node.js applications.
Installation
npm install json6Basic Usage (ES Modules)
import JSON6 from 'json6'; // Parse JSON6 string const obj = JSON6.parse(`{ name: 'app', // comment version: '1.0', }`); // Stringify to JSON6 const str = JSON6.stringify(obj, null, 2);CommonJS Syntax
const JSON6 = require('json6'); const config = JSON6.parse(configString);Reading JSON6 Files
import JSON6 from 'json6'; import { readFileSync } from 'fs'; function loadConfig(path) { const content = readFileSync(path, 'utf8'); return JSON6.parse(content); } const config = loadConfig('./config.json6'); console.log(config);With TypeScript
import JSON6 from 'json6'; interface AppConfig { name: string; version: string; debug: boolean; } const config = JSON6.parse<AppConfig>(configString);the json6 package includes TypeScript definitions.
Using JSON6 in Browsers
Load and parse JSON6 files directly in web applications.
Via CDN (Quick Start)
<script src="https://unpkg.com/json6@2/dist/index.min.js"></script> <script> const config = JSON6.parse(`{ theme: 'dark', sidebar: true, // Show sidebar }`); console.log(config.theme); // 'dark' </script>With a Bundler (Vite, Webpack, etc.)
// Install first: npm install json6 import JSON6 from 'json6'; // Fetch and parse JSON6 async function loadConfig() { const response = await fetch('/config.json6'); const text = await response.text(); return JSON6.parse(text); } loadConfig().then(config => { console.log(config); });ES Module Import
<script type="module"> import JSON6 from 'https://unpkg.com/json6@2/dist/index.min.mjs'; const config = JSON6.parse(`{ debug: true }`); </script>Converting JSON to JSON6
Migrate your existing JSON files to JSON6 format.
Good news: Your JSON files are already valid JSON6! You can rename them to .json6 and start adding features gradually.
Before & After Example
package.json (Original)
{ "name": "my-app", "version": "1.0.0", "scripts": { "start": "node index.js", "test": "jest" } }package.json6 (Enhanced)
{ name: 'my-app', version: '1.0.0', scripts: { // Start the development server start: 'node index.js', // Run test suite test: 'jest', }, }Conversion Checklist
Quick Reference Card
Print this or keep it handy for fast lookups.
Objects
{ unquoted: 'key', 'quoted': 'key', trailing: 'comma', }Arrays
[ 1, 2, 3, // trailing OK ]Strings
"double quotes" 'single quotes' 'multi \ line'Numbers
42 // integer 0xFF // hex .5 // leading decimal Infinity // specialComments
// single line /* multi line */Special Values
true false null Infinity NaNReady to Practice?
Check out real-world examples or explore the complete syntax comparison.