CoffeeScript-Object-Notation Parser. Same as JSON but for CoffeeScript objects.


CoffeeScript-Object-Notation. Same as JSON but for CoffeeScript objects.

Projects using CSON.

Projects using CSON Parser directly.


  • Use: require('cson')
  • Install: npm install --save cson

Everyone knows JSON, it's the thing that looks like this:

  "greatDocumentaries": [
  "importantFacts": {
    "emissions": "Livestock and their byproducts account for at least 32,000 million tons of carbon dioxide (CO2) per year, or 51% of all worldwide greenhouse gas emissions.\nGoodland, R Anhang, J. “Livestock and Climate Change: What if the key actors in climate change were pigs, chickens and cows?”\nWorldWatch, November/December 2009. Worldwatch Institute, Washington, DC, USA. Pp. 10–19.\nhttp://www.worldwatch.org/node/6294",
    "landuse": "Livestock covers 45% of the earth’s total land.\nThornton, Phillip, Mario Herrero, and Polly Ericksen. “Livestock and Climate Change.” Livestock Exchange, no. 3 (2011).\nhttps://cgspace.cgiar.org/bitstream/handle/10568/10601/IssueBrief3.pdf",
    "burger": "One hamburger requires 660 gallons of water to produce – the equivalent of 2 months’ worth of showers.\nCatanese, Christina. “Virtual Water, Real Impacts.” Greenversations: Official Blog of the U.S. EPA. 2012.\nhttp://blog.epa.gov/healthywaters/2012/03/virtual-water-real-impacts-world-water-day-2012/\n“50 Ways to Save Your River.” Friends of the River.\nhttp://www.friendsoftheriver.org/site/PageServer?pagename=50ways",
    "milk": "1,000 gallons of water are required to produce 1 gallon of milk.\n“Water trivia facts.” United States Environmental Protection Agency.\nhttp://water.epa.gov/learn/kids/drinkingwater/water_trivia_facts.cfm#_edn11",
    "more": "http://cowspiracy.com/facts"

Now let's write the same thing in CSON:

# Comments!!! 
# An Array with no commas! 
greatDocumentaries: [
# An Object without braces! 
    # Multi-Line Strings! Without Quote Escaping! 
    emissions: '''
        Livestock and their byproducts account for at least 32,000 million tons of carbon dioxide (CO2) per year, or 51% of all worldwide greenhouse gas emissions.
        Goodland, R Anhang, J. “Livestock and Climate Change: What if the key actors in climate change were pigs, chickens and cows?”
        WorldWatch, November/December 2009. Worldwatch Institute, Washington, DC, USA. Pp. 10–19.
    landuse: '''
        Livestock covers 45% of the earth’s total land.
        Thornton, Phillip, Mario Herrero, and Polly Ericksen. “Livestock and Climate Change.” Livestock Exchange, no. 3 (2011).
    burger: '''
        One hamburger requires 660 gallons of water to produce – the equivalent of 2 months’ worth of showers.
        Catanese, Christina. “Virtual Water, Real Impacts.” Greenversations: Official Blog of the U.S. EPA. 2012.
        “50 Ways to Save Your River.” Friends of the River.
    milk: '''
        1,000 gallons of water are required to produce 1 gallon of milk.
        “Water trivia facts.” United States Environmental Protection Agency.
    more: 'http://cowspiracy.com/facts'

Which is far more lenient that JSON, way nicer to write and read, no need to quote and escape everything, has comments and readable multi-line strings, and won't fail if you forget a comma.

Use CSON with the command line with:

# Convert a JSON file into a CSON file
json2cson in.json > out.cson
# Same thing via piping
cat in.json | json2cson > out.cson
# Convert a CSON file into a JSON file
cson2json in.cson > out.json
# Same thing via piping
cat in.cson | cson2json > out.json

Requires a global CSON install: npm install -g cson

Each method can be executed without a callback like so:

result = require('CSON').createCSONString({a:{b:'c'}}, {/* optional options argument */})
if ( result instanceof Error ) {
} else {

Or via a callback like so:

CSON.createCSONString({a:{b:'c'}}, {/* optional options argument */}, function(err,result){
    console.log(err, result)

Executing the method with a callback still executes the method synchronously.

Click the below function names to open more detailed documentation.

Discover the change history by heading on over to the HISTORY.md file.

Discover how you can contribute by heading on over to the CONTRIBUTING.md file.

These amazing people are maintaining this project:

  • Benjamin Lupton b@lupton.cc (https://github.com/balupton)

No sponsors yet! Will you be the first?

These amazing people have contributed code to this project:

Become a contributor!

Unless stated otherwise all works are:

  • Copyright © 2012+ Bevry Pty Ltd us@bevry.me (http://bevry.me)
  • Copyright © 2011 Benjamin Lupton b@lupton.cc (http://balupton.com)

and licensed under: