Overview
Introduction
CSON strips the braces and commas out of JSON in favor of indentation, the same trade CoffeeScript makes for JavaScript, and shows up in CoffeeScript source, some Atom editor package configs, and hand-written config files where a lighter-weight syntax than JSON is preferred.
This tool renders a JSON object as that indentation-based CSON subset directly, without requiring a CoffeeScript runtime.
What Is JSON to CSON Converter?
A converter that walks a parsed JSON object and prints each key on its own line, either key: value for a scalar or an inline array, or a bare key: line followed by a deeper-indented block for a nested object.
It only covers the CSON subset needed to represent plain JSON data: bare/quoted keys, block-nested objects, and inline arrays, not CoffeeScript's full executable-code object literal syntax.
How JSON to CSON Converter Works
For every key in the object, the tool decides whether the key can be written bare (a valid identifier) or needs double quotes, then branches on the value's type: objects recurse into a new indented block, arrays render inline as [a, b, c], and everything else renders as a scalar (numbers as-is, strings double-quoted with backslashes/quotes/newlines escaped, true/false/null as keywords).
Indentation is exactly two spaces per nesting level, applied consistently so the output can be parsed back by a line-based indentation reader like this site's own CSON to JSON tool.
When To Use JSON to CSON Converter
Use it when you're hand-editing a CoffeeScript project's config or package file and want to start from JSON data you already have.
It's also useful for producing a more compact, punctuation-light view of a JSON object for documentation or a config template.
Often used alongside CSON to JSON Converter, JSON to YAML Converter and JSON Formatter & Beautifier.
Features
Advantages
- Produces valid, readable CSON with correct 2-space block nesting for arbitrarily deep objects.
- Automatically quotes only the keys that actually need it, keeping most output free of unnecessary quote noise.
- Round-trips cleanly back to the original JSON through this site's CSON to JSON tool for the common object/array/scalar cases.
Limitations
- Only objects are valid at the top level; a top-level JSON array or scalar is rejected since CSON documents are objects at the root.
- Arrays containing objects fall back to compact inline JSON syntax for those items rather than CoffeeScript's indented dash-list array style, which this converter doesn't implement.
Examples
Best Practices & Notes
Best Practices
- Keep source JSON objects reasonably shallow; very deep nesting produces CSON that's harder to scan even without braces.
- Avoid keys that need quoting where possible, since bare keys are what make CSON read more cleanly than JSON in the first place.
- Use CSON to JSON afterward to confirm a conversion round-trips the way you expect before committing it to a config file.
Developer Notes
The renderer treats arrays as always-inline by design, deferring to compact JSON syntax for any object elements inside them, which trades away CoffeeScript's optional dash-list array style for a single, simpler, always-parseable grammar that this site's own CSON to JSON parser can read back without ambiguity.
JSON to CSON Converter Use Cases
- Converting a JSON config into CSON for a CoffeeScript or Atom-style project
- Producing a lighter-weight, punctuation-free view of a JSON object for docs
- Hand-authoring CSON test fixtures starting from JSON data
Common Mistakes
- Expecting a top-level JSON array to convert; CSON documents must be objects at the root.
- Assuming arrays of objects render as indented dash-lists; this converter always renders arrays inline instead.
- Forgetting that an empty top-level object produces empty output, not literal {} text.
Tips
- If a key comes out double-quoted, check it for spaces, dashes, or a leading digit, those are what trigger quoting.
- Pair with CSON to JSON to verify a round trip before relying on the output in a real project.