CSON to JSON Converter

Parses a simplified CSON document, 2-space indented key: blocks, bare or quoted keys, and inline [a, b, c] arrays, back into equivalent JSON, so a CoffeeScript-style config file can be read or consumed as JSON. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-24

Overview

Introduction

CSON's indentation-based syntax is easy to hand-write but not something most JavaScript/TypeScript tooling understands natively.

This tool parses that CSON subset directly into JSON, so a CoffeeScript-style config file can be inspected, validated, or fed into any JSON-consuming tool.

What Is CSON to JSON Converter?

A line-based parser (modeled after a minimal YAML block parser) that reads 2-space indented key: blocks and key: value leaf lines and reconstructs the equivalent nested JSON object.

It understands the same subset jsonToCson produces: bare or double-quoted keys, block-nested objects, and inline [...] arrays of literals, numbers, strings, and nested arrays.

How CSON to JSON Converter Works

The input is split into lines, blank lines are skipped, and each remaining line's leading-space count becomes its indentation width. A recursive block parser consumes a contiguous run of lines at the same indentation, treating a bare key: line (nothing after the colon) as the start of a nested block formed from the following, deeper-indented lines.

A key: value line's value is parsed by a small recursive value parser that handles literals, numbers, quoted strings, and inline arrays, splitting array contents on top-level commas while correctly skipping over commas inside quoted strings.

When To Use CSON to JSON Converter

Use it to read a CoffeeScript project's CSON config into a JSON-based build script or validation tool.

It's also handy for quickly checking a hand-written CSON snippet's actual structure by seeing it as familiar JSON.

Features

Advantages

  • Reports a specific line number for malformed input, whether it's bad indentation or an unparseable value.
  • Handles quoted strings containing commas or brackets correctly when splitting inline array elements.
  • Treats an empty document as a valid empty object rather than forcing an artificial error.

Limitations

  • Doesn't support CoffeeScript's full executable object-literal syntax, dash-prefixed list arrays, comments, or multi-line strings, only the plain-data subset this site's JSON to CSON converter produces.
  • A line with inconsistent indentation (deeper than expected without a preceding bare key: line, or a level that doesn't match any enclosing block) is reported as an error rather than guessed at.

Examples

Nested block and 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"
  }
}

Each leaf key: value line becomes a JSON property, and the db: block becomes a nested object.

A line with no key/value structure

Input

this is not valid cson

Output

Line 1: expected a "key:" or "key: value" line.

The line doesn't match either the bare-key or quoted-key pattern, so parsing fails at that exact line.

Best Practices & Notes

Best Practices

  • Use exactly 2 spaces per indentation level; mixing tabs and spaces or using inconsistent widths is the most common source of indentation errors.
  • Check the reported line number against the source when parsing fails, most failures come from a stray unindented line or a malformed inline array.
  • Pair with JSON to CSON to round-trip a conversion and confirm it comes back the way you expect.

Developer Notes

The block parser is written as a small recursive-descent function keyed entirely on line indentation rather than building a token stream first: each call consumes a contiguous run of same-indent lines and recurses into any deeper-indented run it finds under a bare key: line, which keeps the implementation close to a one-pass reader while still handling arbitrarily deep nesting correctly.

CSON to JSON Converter Use Cases

  • Reading a hand-written CSON config file's structure from a JavaScript/TypeScript build script
  • Converting a CoffeeScript project's CSON config into JSON for tooling that only accepts JSON
  • Validating that a CSON snippet is well-formed before committing it to a project

Common Mistakes

  • Mixing indentation widths across sibling lines, which the parser reports as an inconsistent-indentation error rather than silently normalizing.
  • Expecting comments (# ...) to be ignored; this parser doesn't strip comments, so a comment line will fail to parse as a key: line.
  • Assuming dash-prefixed list arrays parse; only inline [...] arrays are supported.

Tips

  • If parsing fails, check the reported line first, most issues are either a missing colon or a mismatched indent width.
  • Use JSON to CSON to generate valid input for this converter if you're unsure of the exact grammar it expects.

References

Frequently Asked Questions