JSON to CSON Converter

Converts a JSON object into CSON, the indentation-based, low-punctuation object notation used by CoffeeScript projects and some Atom/config files: bare unquoted keys where valid, 2-space nested blocks instead of braces, and scalar arrays rendered inline. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-24

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.

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

Object with a nested block and an inline array

Input

{"name":"api","port":3000,"debug":false,"tags":["web","api"],"db":{"host":"localhost"}}

Output

name: "api"
port: 3000
debug: false
tags: ["web", "api"]
db:
  host: "localhost"

Scalars render as key: value, the tags array renders inline, and db opens an indented nested block.

Non-object input is rejected

Input

[1, 2, 3]

Output

CSON documents must have an object at the top level.

A top-level array has no valid CSON representation from this converter, since CSON documents are objects at the root.

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.

References

Frequently Asked Questions