bevry/cson


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

License: Other

Language: CoffeeScript

Keywords: coffeescript, cson, data-format, executable, json, nodejs


CSON

Travis CI Build Status NPM version NPM downloads Dependency Status Dev Dependency Status
GitHub Sponsors donate button Patreon donate button Flattr donate button Liberapay donate button Buy Me A Coffee donate button Open Collective donate button crypto donate button PayPal donate button Wishlist browse button

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

Projects using CSON.

Projects using CSON Parser directly.

Since v2, this CSON package is a higher-level wrapper around the lower-level CSON Parser.

Install

npm

Install Globally

  • Install: npm install --global cson
  • Executables: cson2json, json2cson

Install Locally

  • Install: npm install --save cson
  • Executables: npx cson2json, json2cson
  • Require: require('cson')

Editions

This package is published with the following editions:

  • cson/source/index.coffee is coffeescript source code with require for modules
  • cson aliases cson/edition-esnext/index.js
  • cson/edition-esnext/index.js is coffeescript compiled for Node.js with require for modules

Environments older than Node.js v8 may need Babel's Polyfill or something similar.

What is CSON?

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

{
  "greatDocumentaries": [
    "earthlings.com",
    "forksoverknives.com",
    "cowspiracy.com"
  ],
  "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: [
	'earthlings.com'
	'forksoverknives.com'
	'cowspiracy.com'
]

# An Object without braces!
importantFacts:
	# 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.
		http://www.worldwatch.org/node/6294
		'''

	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).
		https://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.
		Catanese, Christina. “Virtual Water, Real Impacts.” Greenversations: Official Blog of the U.S. EPA. 2012.
		http://blog.epa.gov/healthywaters/2012/03/virtual-water-real-impacts-world-water-day-2012/
		“50 Ways to Save Your River.” Friends of the River.
		http://www.friendsoftheriver.org/site/PageServer?pagename=50ways
		'''

	milk: '''
		1,000 gallons of water are required to produce 1 gallon of milk.
		“Water trivia facts.” United States Environmental Protection Agency.
		http://water.epa.gov/learn/kids/drinkingwater/water_trivia_facts.cfm#_edn11
		'''

	more: 'http://cowspiracy.com/facts'

Which is far more lenient than 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.

Using CSON

Via the Command Line

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

Via the API

Include CSON:

var CSON = require('cson')

Each method can be executed without a callback like so:

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

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.

Create Strings

Parse Strings

Parse Files

Require Files

History

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

Contribute

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

Backers

Maintainers

These amazing people are maintaining this project:

Sponsors

No sponsors yet! Will you be the first?

GitHub Sponsors donate button Patreon donate button Flattr donate button Liberapay donate button Buy Me A Coffee donate button Open Collective donate button crypto donate button PayPal donate button Wishlist browse button

Contributors

These amazing people have contributed code to this project:

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

License

Unless stated otherwise all works are:

and licensed under:

Project Statistics

Sourcerank 15
Repository Size 389 KB
Stars 1,213
Forks 56
Watchers 19
Open issues 3
Dependencies 95
Contributors 11
Tags 31
Created
Last updated
Last pushed

Top Contributors See all

Benjamin Lupton dependabot-preview[bot] Rob Loach Attila Oláh Linus Gustav Larsson Thiel ZHANG Cheng Jason Karns Joël Perras clyfe Tushar Kant Ryan LeFevre

Packages Referencing this Repo

cson
CoffeeScript-Object-Notation Parser. Same as JSON but for CoffeeScript objects.
Latest release 6.9.0-next.1576603916.6dd6652dd2626070252f4ce0bcc1ccbbdd42dadd - Updated - 1.21K stars

Recent Tags See all

v6.9.0 December 17, 2019
v6.8.0 December 09, 2019
v6.7.0 December 01, 2019
v6.6.0 November 30, 2019
v6.6.0 November 30, 2019
v6.5.0 November 30, 2019
v6.4.0 November 18, 2019
v6.3.0 November 17, 2019
v6.2.0 November 12, 2019
v6.1.0 November 12, 2019
v6.0.0 November 10, 2019
v5.1.0 January 25, 2018
v5.0.0 January 25, 2018
v4.1.0 April 10, 2017
v4.0.0 October 20, 2016

Interesting Forks See all

xgqfrms/cson
CoffeeScript-Object-Notation. Same as JSON but for CoffeeScript objects.
CoffeeScript - Other - Updated - 2 stars - 1 forks
me6iaton/cson
CoffeeScript-Object-Notation Parser. Same as JSON but for CoffeeScript objects.
CoffeeScript - MIT - Last pushed - 1 stars

Something wrong with this page? Make a suggestion

Last synced: 2019-12-17 17:39:11 UTC

Login to resync this repository