Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kazu69
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazu69/9406422 to your computer and use it in GitHub Desktop.
Save kazu69/9406422 to your computer and use it in GitHub Desktop.
node_modules/json5/lib/cli.js -c data.json5
cat data.json
{
"foo": "bar",
"while": true,
"this": "is a multi-line string",
"here": "is another",
"hex": 3735928559,
"half": 0.5,
"delta": 10,
"to": null,
"finally": "a trailing comma",
"oh": [
"we shouldn't forget",
"arrays can have",
"trailing commas too"
]
}%
{
foo: 'bar',
while: true,
this: 'is a \
multi-line string',
// this is an inline comment
here: 'is another', // inline comment
/* this is a block comment
that continues on another line */
hex: 0xDEADbeef,
half: .5,
delta: +10,
to: Infinity, // and beyond!
finally: 'a trailing comma',
oh: [
"we shouldn't forget",
'arrays can have',
'trailing commas too',
],
}
// json5 をrequireできるようにする
require('json5/lib/require');
var JSON5 = require('json5');
var data = require('./data');
result = JSON5.stringify(data);
console.log(result);
node json5.js
{foo:"bar",while:true,this:"is a multi-line string",here:"is another",hex:3735928559,half:0.5,delta:10,to:null,finally:"a trailing comma",oh:["we shouldn't forget","arrays can have","trailing commas too"]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment