vs CSON: Indentation, Atom and Safety
CoffeeScript's data syntax, born with Atom, against a format that never needs a CoffeeScript parser.
CSON writes objects with indentation, comments with # and multiline text with triple quotes. It has no specification: the format is whatever the CoffeeScript compiler accepts, which is why evaluating it carries real risks.
Here you will find the history, the state of the cson and cson-parser packages, tested syntax differences, what a data-only parser still lets through, and a migration script that turns .cson files into .json5 without losing data.
TL;DR: CSON is a convenient way to hand-write settings if you already live in the CoffeeScript or Atom world, but it has no spec, whitespace changes its meaning, and the common parser depends on a 2017 CoffeeScript release. For new files choose JSON5. To move existing files, use a data-only parser to read them, check for duplicates, and write them out with json5; a tested script is below.
Where CSON Came From
CSON, CoffeeScript Object Notation, is "the same as JSON but for CoffeeScript objects," in the words of the README of the cson npm package. That README is the nearest thing the format has to a definition. The author of the Python parser notes that CSON has no formal definition, and that CoffeeScript itself has no formal grammar either, only a canonical implementation, so quirks of the compiler become quirks of the format.
The cson package was first published to npm on June 2, 2011, and its history file records a synchronous interface in version 0.2 on August 10, 2011. Early versions evaluated files with CoffeeScript. A 2012 release sandboxed CSON files by default and made the sandbox optional, and a later release changed how CoffeeScript files were evaluated, telling users who parse untrusted ones to set up the sandbox themselves. Version 2.0.0, released February 6, 2015, rewrote the package to parse and write CSON with the separate cson-parser package, which reads data without running it. That split is why two package names exist today.
The format's largest deployment came from Atom. The Atom Flight Manual says its configuration files are written in CSON, apart from the style sheet and the init script, and that for duplicate keys the last one wins. Atom's own source chooses config.json if one exists and config.cson otherwise, and its config file code uses season, which reads and writes both. GitHub announced the sunset of Atom on June 8, 2022 and archived the repositories on December 15, 2022. The community fork Pulsar keeps CSON: its documentation says all of its config files are CSON, and its package.json still depends on season and CoffeeScript 1.12.7. See the Atom guide for JSON5 editor tooling.
The Same Settings in Both Formats
An Atom-style settings file in CSON. Keys that contain a dot or a star are quoted, and structure comes from indentation:
# editor settings
'*':
core:
# indent with two spaces
telemetry: false
themes: [
'one-dark-ui'
'one-dark-syntax'
]
editor:
tabLength: 2
softWrap: yes # wrap long lines
scrollPastEnd: on
autosaveMs: 5 * 1000
banner: '''
Welcome.
Be kind.
'''
'.python.source':
editor:
tabLength: 4Read with cson-parser 4.0.9 and written with json5 2.2.3 on Node.js 24.22.1, the equivalent JSON5 file is:
{
'*': {
core: {
telemetry: false,
themes: [
'one-dark-ui',
'one-dark-syntax',
],
},
editor: {
tabLength: 2,
softWrap: true,
scrollPastEnd: true,
autosaveMs: 5000,
banner: 'Welcome.\nBe kind.',
},
},
'.python.source': {
editor: {
tabLength: 4,
},
},
}Three things changed beyond punctuation. The comments are gone, because a parser returns data and comments are not data. The words yes and on became true. And the arithmetic 5 * 1000 became the number 5000, computed during parsing. The migration section shows how to find the comments before they vanish.
Syntax Compared
CSON results below come from cson-parser 4.0.9, which uses CoffeeScript 1.12.7 to parse; JSON5 results come from json5 2.2.3.
| Feature | JSON5 | CSON |
|---|---|---|
| Defined by | Specification 1.0.0, March 2018 | No specification; the CoffeeScript compiler |
| Comments | // and /* */ | # and ### block ### |
| Structure | Braces and brackets only | Indentation, braces or both |
| Commas | Required; one trailing comma allowed | A newline can replace them; trailing comma allowed |
| Root braces | Required for an object | Optional |
| Unquoted keys | ECMAScript identifier names | Identifiers only; my-key must be quoted, as must '*' |
| Unquoted string values | ||
| Single and double quotes | ||
| Multiline strings | Backslash line continuation | ''' or """ blocks with indentation stripped; a plain quoted string spanning lines joins them with a space |
| Booleans | true, false | Also yes, no, on, off (lowercase only) |
| Numbers | Hex, .5, +1, Infinity, NaN | Hex, octal (0o17), binary (0b101), .5; not +1, Infinity, NaN or 010 |
| Expressions | Arithmetic and string + in cson-parser | |
| Regular expressions | Accepted by cson-parser as a value | |
| Duplicate keys | Last wins in json5 | Last wins, silently |
| Reads all of JSON | Partly (see below) |
The last row surprises people. {"a": "#{x}"} is valid JSON and parses to the string #{x} in JSON5, but cson-parser rejects it with Unexpected StringWithInterpolations, because a double-quoted CoffeeScript string treats #{...} as interpolation. Conversely, no CSON file that uses indentation, # comments or bare structure is readable by a JSON5 parser, and JSON5 comments are errors in cson-parser: // c fails with unexpected // and /* c */ with regular expressions cannot begin with *. A file is one format or the other.
Indentation, Comments and Gotchas
Whitespace carries meaning in CSON, and some wrong inputs do not fail. Each row shows an input (with \n for line breaks) and what cson-parser 4.0.9 returned:
| Input | Result |
|---|---|
a:\n b: 1\n c: 2 | {a:{b:1,c:2}} |
a:\n b: 1\n c: 2 | {a:{b:1},c:2}, no error: the uneven dedent quietly ends the object |
a:\n b: 1\n c: 2 | Error: unexpected : |
a: 1\n b: 2 | Error: unexpected : |
a: 1\na: 2 | {a:2}, duplicate dropped silently |
a: hello | Error: Unexpected IdentifierLiteral |
a: Yes | Error; only lowercase yes is a boolean |
color: #FF00AA | Error: unexpected end of input (the # began a comment) |
my-key: 1 | Error: the hyphen needs quotes |
a: 010 | Error: octal literal must be written 0o10 |
a: 1 / 0 | {a:Infinity}, computed |
| An empty file, or only comments | Error: One top level value expected |
x = 1\na: x | Error: variables are not data |
The same uneven-dedent text compiles in CoffeeScript 2.7.1 as a nested object plus a sibling, so the behavior comes from the language, not from one parser. The Python cson 0.8 package, which has its own grammar and documents that it differs from CoffeeScript in corner cases, raised a parse error on it, and also returned the literal text #{x} for "#{x}", where the JavaScript parser refuses. Different parsers, different files.
Atom's season works around two of these. It returns null for a file that is empty or only whitespace (cson-parser 4.0.9 rejects a comments-only file), and accepts an allowDuplicateKeys: false option that throws on a repeated key with a different value. Plain cson-parser does neither. Comments in both formats are lost when data is parsed and rewritten; see the comments tutorial for what that means for JSON5 files.
The Packages and Their Maintenance
Facts read from the npm registry, PyPI and GitHub on November 29, 2026. Weekly downloads cover November 22 to 28 and include installs pulled in by other packages.
| Package | Latest | License | Weekly downloads | Notes |
|---|---|---|---|---|
cson | 8.4.0, December 29, 2023 | Artistic-2.0 | 91,322 | High-level wrapper with CLI; depends on cson-parser; repository pushed October 2026 |
cson-parser | 4.0.9, March 26, 2021 | BSD-3-Clause | 206,581 | Data-only parser; pins coffeescript 1.12.7; the repository URL in its metadata returned 404 |
season | 6.0.2, October 23, 2017 | MIT | 7,058 | Atom's CSON file library; repository archived; depends on cson-parser ^1.3.0 |
coffeescript | 2.7.1, October 25, 2026 | MIT | 1,641,809 | The language itself is active, though the parser above uses the 1.x line |
cson (PyPI) | 0.8, January 22, 2019 | MIT | n/a | Python parser with its own grammar; repository last pushed in 2020 |
For comparison, json5 had 303,643,299 downloads in the same week. The honest summary: the CSON packages are small and stable, but not actively developed. cson-parser froze its CoffeeScript dependency in version 4.0.7 in November 2020. The open-source vulnerability database OSV returned no advisories for cson, cson-parser, season, coffeescript or coffee-script when we queried it.
Other tools that read CSON, per the cson-parser README, include grunt helpers, fetcher and csonschema. For JSON5 the implementations page lists parsers by language.
Security: Parsing Versus Evaluating
Because CSON is CoffeeScript, there are two very different ways to read it. A data-only parser such as cson-parser asks the compiler for a syntax tree and converts only whitelisted node types. Its README says it does not run the code and that "even when ran in a proper sandbox, while(true) is still possible," which is why you should not simply evaluate data files. An evaluating loader compiles the text and executes it.
The cson wrapper exposes both. CSON.parse goes through cson-parser, but CSON.parseCSString calls CoffeeScript's eval. We ran this with cson 8.4.0 on Windows:
const CSON = require('cson');
CSON.parse('a: process.exit()') // an Error object, nothing ran
CSON.parseCSString('platform: process.platform')
// { platform: 'win32' } the code ran
// Files: by default only json and cson are enabled
CSON.parseFile('x.coffee').message
// 'CSON.parseFile: Desired format is CoffeeScript however CoffeeScript is disabled by an option'
CSON.parseFile('y.coffee', { coffeescript: true })
// { from: 'win32' } enabled by the caller, so it ranThe defaults are safe, but a single option, or a call to the wrong method, turns a settings file into a program. Anything that lets a user choose a file name, format or options must not reach those paths. Never run requireFile, parseCSFile or .coffee loading on files you do not control.
What the data-only parser accepts
| Input | cson-parser 4.0.9 |
|---|---|
a: process.exit() | Rejected: Unexpected Call |
a: "#{process.platform}" | Rejected: Unexpected StringWithInterpolations |
a: -> 1 | Rejected: Unexpected Code |
| A backtick JavaScript block | Rejected: Unexpected PassthroughLiteral |
x = 1\na: x | Rejected: one top-level value expected |
a: 5 * 60 * 1000 | Accepted: 300000 |
a: /ab+c/i | Accepted: a RegExp object, not JSON data |
__proto__: with an object value | Accepted, and sets the result's prototype |
The last row is the one to remember. Here cson-parser and json5 2.2.3 read a document that tries to smuggle a field in through the special key:
const CSON = require('cson-parser');
const JSON5 = require('json5');
const a = CSON.parse("user:\n __proto__:\n admin: true\n name: 'x'");
console.log(a.user.admin, Object.keys(a.user));
// true [ 'name' ]
const b = JSON5.parse("{user:{__proto__:{admin:true}, name:'x'}}");
console.log(b.user.admin, Object.keys(b.user));
// undefined [ '__proto__', 'name' ]In the CSON result, user.admin is true even though it is not an own property. Code like if (user.admin) would be fooled. The global Object.prototype was not changed, since the check ({}).admin stayed undefined, so the damage is limited to that object. In JSON5 the same key is an ordinary own property and no inherited field appears. Whatever format you read, validate the shape with a schema and reject unexpected keys. The security tutorial goes further.
Writing CSON
Both packages can write CSON, and both drop information without telling you. With cson-parser, strings that contain a line break become triple-quoted blocks and braces on the root disappear. Infinity and NaN, though, are written as null:
const data = { name: 'api', nested: { 'my-key': 'a\nb', inf: Infinity, nan: NaN } };
console.log(CSON.stringify(data, null, 2));
// name: 'api'
// nested:
// 'my-key': '''
// a
// b
// '''
// inf: null
// nan: null
console.log(CSON.parse(CSON.stringify(data, null, 2)).nested.inf);
// nullThe JSON5 writer in json5 2.2.3 writes Infinity and NaN literally, so the round trip keeps them. The cson wrapper's stringify indents with tabs by default, while the lower-level package takes the indent you pass. Neither preserves comments.
Migrating .cson to .json5
The goal is a safe conversion: read with the data-only parser, refuse anything that cannot survive, prove the output equals the input, and never overwrite. This script does that. It needs npm install cson-parser json5 and Node.js 16.9 or later (it uses Object.hasOwn):
const fs = require('node:fs');
const { isDeepStrictEqual } = require('node:util');
const CSON = require('cson-parser');
const JSON5 = require('json5');
function strict(key, value) {
if (key === '__proto__') throw new Error('__proto__ key found');
if (Object.hasOwn(this, key) && this[key] !== value) {
throw new Error(`duplicate key "${key}"`);
}
if (value instanceof RegExp) {
throw new Error(`regular expression at key "${key}"`);
}
return value;
}
let failed = 0;
for (const file of process.argv.slice(2)) {
try {
let source = fs.readFileSync(file, 'utf8');
if (source.charCodeAt(0) === 0xfeff) source = source.slice(1);
const data = CSON.parse(source, strict);
const text = JSON5.stringify(data, null, 2) + '\n';
if (!isDeepStrictEqual(JSON5.parse(text), data)) {
throw new Error('round trip changed the data');
}
const out = file.replace(/\.cson$/i, '') + '.json5';
fs.writeFileSync(out, text, { flag: 'wx' }); // never overwrite
console.log(`ok ${file} -> ${out}`);
source.split(/\r?\n/).forEach((line, i) => {
if (/^\s*#/.test(line)) console.log(` comment, line ${i + 1}: ${line.trim()}`);
});
} catch (error) {
failed++;
console.error(`FAIL ${file}: ${error.message}`);
}
}
process.exitCode = failed ? 1 : 0;Run as node cson2json5.js config.cson dup.cson re.cson code.cson, it produced exactly the JSON5 file shown earlier, then:
ok config.cson -> config.json5
comment, line 1: # editor settings
comment, line 4: # indent with two spaces
FAIL dup.cson: duplicate key "a"
FAIL re.cson: regular expression at key "r"
FAIL code.cson: Syntax error on line 1, column 4: Unexpected IdentifierLiteralRunning it a second time on config.cson failed with EEXIST, as intended. The script lists full-line comments with their line numbers so you can re-add them by hand; trailing comments such as softWrap: yes # wrap long lines are lost without a listing, so search the source for them. Duplicate detection uses the same rule as Atom's season, which means a repeated key with an identical primitive value is not reported.
Migration checklist
- Convert with a data-only parser. Never evaluate the file just to read it.
- Review every converted value that came from
yes,no,on,offor an expression. - Fix duplicate keys and regular expressions in the source, then rerun.
- Check that the application you are migrating actually accepts the new extension. Atom and Pulsar document
config.cson, and Atom's source looks forconfig.jsonas its only alternative, so editor configs may need to stay CSON. - Re-add comments, validate against a schema, and commit the old file's removal separately so history shows the move. The JSON migration tutorial covers the general process.
Choosing Between Them
| Your situation | Lean toward | Why |
|---|---|---|
| Configuring Atom or Pulsar | CSON | It is the documented format for those editors |
| New project settings | JSON5 | A specification, many parsers, no indentation traps |
Existing .cson files in your own tools | Migrate to JSON5 | Removes the CoffeeScript 1.x dependency |
| Files edited by non-programmers | Neither without validation | Both let typos through in different ways |
| Untrusted input | JSON or JSON5, validated | No language runtime near the parser |
| Readers in several languages | JSON5 | CSON parsers disagree with each other on edge cases |
CSON's attractions are real: no braces, no commas, tidy multiline text. JSON5 keeps the explicit structure that makes copy, paste and diff predictable and keeps the syntax JavaScript developers already know. If readability of long text is your main concern, compare Hjson and YAML as well, and see the comparison hub.
Common Questions
Is CSON the same as CoffeeScript?
It is a subset of CoffeeScript syntax used for data. A good parser accepts only literals; the CoffeeScript compiler accepts functions and calls as well.
Is CSON safe to parse?
With cson-parser or CSON.parse, code is not executed, though arithmetic, regular expressions and a __proto__ key are still accepted. Evaluating loaders such as parseCSString run the file as a program.
Is the cson package abandoned?
Its last release was December 29, 2023 and its repository saw a push in October 2026. It is maintained lightly. cson-parser, which does the parsing, last released in March 2021.
Can JSON5 replace CSON in Atom?
Not on documented grounds. Atom and Pulsar document CSON configuration files, so use CSON there and JSON5 elsewhere.
Does JSON5 allow # comments?
No. JSON5 uses // and /* */, taken from ECMAScript. A # in a JSON5 file is a syntax error.
Sources
(16)
- bevry/cson README and HISTORY
- cson on npm
- cson-parser on npm (README, CHANGELOG and source in the package)
- season on npm
- atom/season repository
- atom/atom repository, main process source
- GitHub: Sunsetting Atom
- Atom Flight Manual: basic customization
- Pulsar documentation: configuring with CSON
- pulsar-edit/pulsar repository
- cson on PyPI
- avakar/pycson README
- coffeescript on npm
- OSV open-source vulnerability database
- The JSON5 Data Interchange Format, 1.0.0
- json5 on npm
Last reviewed: November 29, 2026.
JavaScript
Python
TypeScript
Node.js
Rust
Java
C#
Ruby
Kotlin
Lua
Babel
Vite
webpack
ESLint
Prettier
VS Code
JetBrains 
