CoffeeScript-Object-Notation Parser. Same as JSON but for CoffeeScript objects
- Use:
require('cson')
- Install:
npm install --save cson
- Use:
require('cson')
- Install:
ender add cson
Everyone knows JSON, it's the thing that looks like this:
{
"abc": [
"a",
"b",
"c"
],
"a": {
"b": "c"
}
}
But with the invention of CoffeeScript you can also write the same thing in CSON which looks like this:
{
# an array
abc: [
'a'
'b'
'c'
]
# an object
a:
b: 'c'
}
Which is far more lenient than JSON, nicer to write and read, you don't have to quote everything, you have comments, and won't fail if you forget a comma.
-
Install CSON
npm install --save cson
-
With Node.js in JavaScript
// Include CSON CSON = require('cson'); // Parse a file path CSON.parseFile('data.cson', function(err,obj){}); // async result = CSON.parseFileSync('data.cson'); // sync // Parse a String CSON.parse(src, function(err,obj){}); // async result = CSON.parseSync(src); // sync // Stringify an object to CSON CSON.stringify(obj, function(err,str){}); // async result = CSON.stringifySync(obj); // sync
-
With Node.js in CoffeeScript
# Include CSON CSON = require('cson') # Parse a file path CSON.parseFile 'data.cson', (err,obj) -> # async result = CSON.parseFile('data.cson') # sync # Parse a string CSON.parse src, (err,obj) -> # async result = CSON.parseSync(src) # sync # Stringify an object to CSON CSON.stringify data, (err,str) -> # async result = CSON.stringifySync(obj) # sync
-
Via the command line (requires a global installation of CSON via
npm install -g cson
)# JSON file to CSON String json2cson filePath > out.cson # CSON file to JSON String cson2json filePath > out.json
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 [email protected] (https://github.com/balupton)
No sponsors yet! Will you be the first?
These amazing people have contributed code to this project:
- Benjamin Lupton [email protected] (https://github.com/balupton) - view contributions
- Joel Perras [email protected] (https://github.com/jperras) - view contributions
- Linus G Thiel [email protected] (https://github.com/linus) - view contributions
- Nicolae Claudius [email protected] (https://github.com/clyfe) - view contributions
- Ryan LeFevre [email protected] (https://github.com/meltingice) - view contributions
- Zhang Cheng [email protected] (https://github.com/zhangcheng) - view contributions
Licensed under the incredibly permissive MIT license
Copyright © 2012+ Bevry Pty Ltd [email protected] (https://bevry.me)
Copyright © 2011 Benjamin Lupton [email protected] (https://balupton.com)