Skip to main content
# pycson

[![Build Status](https://travis-ci.org/avakar/pycson.svg?branch=master)](https://travis-ci.org/avakar/pycson)

A python parser for the Coffeescript Object Notation (CSON).

## Installation

The parser is tested on Python 2.7 and 3.5.

pip install cson

The interface is the same as for the standard `json` package.

>>> import cson
>>> cson.loads('a: 1')
{'a': 1}
>>> with open('file.cson', 'rb') as fin:
... obj = cson.load(fin)
>>> obj
{'a': 1}

## The language

There is not formal definition of CSON, only an informal note in [one project][1]'s readme.
Informally, CSON is a JSON, but with a Coffeescript syntax. Sadly [Coffescript][2] has no
format grammar either; it instead has a canonical implementation.

This means that bugs in the implementation translate into bugs in the language itself.

Worse, this particular implementation inserts a "rewriter" between the typical
lexer/parser pair, purporting that it makes the grammar simpler. Unfortunately, it adds
weird corner cases to the language..

This parser does away with the corner cases,
in exchange for changing the semantics of documents in a few unlikely circumstances.
In other words, some documents may be parsed differently by the Coffescript parser and pycson.

Here are some important highlights (see the [formal grammar][3] for details).

* String interpolations (`"#{test}"`) are allowed, but are treated literally.
* Whitespace is ignored in arrays and in objects enclosed in braces
(Coffeescripts requires consistent indentation).
* Unbraced objects greedily consume as many key/value pairs as they can.
* All lines in an unbraced object must have the same indentation. This is the only place
where whitespace is significant. There are no special provisions for partial dedents.
For two lines to have the same indent, their maximal sequences of leading spaces and tabs
must be the same (Coffescript only tracks the number of whitespace characters).
* Unbraced objects that don't start on their own line will never span multiple lines.
* Commas at the end of the line can always be removed without changing the output.

I believe the above rules make the parse unambiguous.

This example demonstrates the effect of indentation.

# An array containing a single element: an object with three keys.
[
a: 1
b: 2
c: 3
]

# An array containing three elements: objects with one key.
[
a: 1
b: 2
c: 3
]

# An array containing two objects, the first of which having one key.
[ a: 1
b: 2
c: 3 ]

Note that pycson can parse all JSON documents correctly (Coffeescript can't because
of whitespace and string interpolations).

[1]: https://github.com/bevry/cson
[2]: http://coffeescript.org/
[3]: grammar.md

Metadata

Release files for cson 0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cson 0.8
File Size Uploaded Provenance Actions
cson-0.8.tar.gz 6.3 kB Without provenance Details for cson-0.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cson 0.8
File Interpreter ABI Platform Actions
cson-0.8-py2.py3-none-any.whl Python 3, Python 2 none any Details for cson-0.8-py2.py3-none-any.whl

Total release size: 13.1 kB

Release files / cson-0.8.tar.gz

Download URL cson-0.8.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ee8c0166fcd1f51789887197e3e8354ac7befa396fc29706bceb5af25edc9e01
BLAKE2b-256 checksum
How to use checksums
8c14461bdde1d712dae3c14e139dd4b37085085fd75f01d44f888767bfc6d313
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.7

Release files / cson-0.8-py2.py3-none-any.whl

Download URL cson-0.8-py2.py3-none-any.whl
Size 6.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
163a18fccbb5bd0911d20f0ef5876ce5a08057b05ba212571579578f292ed100
BLAKE2b-256 checksum
How to use checksums
996f0a83b553bee55baa2ee3a039c6d91c339beca59d250ad742053dcf83ac26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.7

Security for cson 0.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page