Getting Started with JSON6

Learn JSON6 in 10 minutes. From zero to your first config file.

What you'll learn: What JSON6 is, how to install and use it, and how to create your first JSON6 configuration file with comments and trailing commas.

What is JSON6?

JSON6 is an extension to JSON that makes it easier for humans to write and maintain. It adds features from JavaScript that JSON lacks:

Comments

Add documentation with // and /* */

Trailing Commas

Cleaner diffs when adding/removing items

Unquoted Keys

Less visual noise: name vs "name"

Single Quotes

Choose between 'text' or "text"

Good news: Every JSON file is already valid JSON6! You can adopt JSON6 features gradually without breaking existing files.

Step 1: Install JSON6

Install the official JSON6 library for your programming language.

JavaScript / Node.js

npm install json6

Python

pip install json6

See all language guides: JavaScript, Python, Go, Rust, Java, C#

Step 2: Create Your First JSON6 File

Create a file called config.json6 with the following content:

{ // Application Configuration // This file uses JSON6 for better readability name: 'my-awesome-app', version: '1.0.0', // Server settings server: { host: 'localhost', port: 3000, debug: true, // Enable for development }, // Feature flags features: [ 'authentication', 'notifications', 'dark-mode', // Trailing comma is OK! ], }

What makes this different from JSON?

  • Comments document what each section does
  • Unquoted keys like name instead of "name"
  • Single quotes for strings
  • Trailing commas after the last items

Step 3: Parse Your JSON6 File

Read and parse your config file in your application:

JavaScript / Node.js

import JSON6 from 'json6'; import { readFileSync } from 'fs'; // Read the file const configText = readFileSync('config.json6', 'utf8'); // Parse JSON6 const config = JSON6.parse(configText); // Use the config console.log(`Starting ${config.name} on port ${config.server.port}`); // Output: "Starting my-awesome-app on port 3000"

Python

import json6 # Read and parse the file with open('config.json6', 'r') as f: config = json6.load(f) # Use the config print(f"Starting {config['name']} on port {config['server']['port']}") # Output: "Starting my-awesome-app on port 3000"

That's it! You've just created and parsed your first JSON6 file. The comments are stripped during parsing - they exist only for human readers.

Quick Syntax Reference

Here's what JSON6 allows that JSON doesn't:

Feature JSON JSON6
Comments Not allowed // comment and /* comment */
Trailing commas Syntax error [1, 2, 3,]
Unquoted keys Must quote { name: 'value' }
Single quotes Double only 'single' or "double"
Hex numbers Not allowed 0xFF
Infinity / NaN Not allowed Infinity, NaN

Ready for More?

Explore examples or dive into the complete specification.