Uses esprima, escodegen
or shift-{parser, codegen}
to parse and stringify an JavaScript values.
Do you think, that JSON is a bit verbose? restrictive? hard to comment?
Remember, you wrote something like the text below, gave it to JSON.parse()
and got 30 errors? one by one?
{
unquoted_key: "keys must be quoted",
a1: ["extra comma",],
a2: ["double extra comma",,],
// single line comment
"Illegal expression": 1 + 2,
"Illegal invocation": alert(),
"Numbers cannot have leading zeroes": 013,
"Numbers cannot be hex": 0x14,
a3: [
"Illegal backslash escape: \x15",
"Illegal backslash escape: \017",
[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]],
"Bad value", truth,
'single quote',
/* multi-line comment */
" tab character in string ",
"tab\ character\ in\ string\ ",
"line\
break"
],
"Extra comma": true,
}
So, now you can use jsof.parse()
, and everything is fine!
JSON.stringify(obj, null, 2);
{
"a": [
{"b": [
[
"string"
]
]}
],
"c": 42
}
jsof.stringify(obj);
{
a: [{b: 'string'}],
c: 42
}
colors
References
no eval()
no Yaml
Better error messages.
npm i jsof --save
var jsof = require('jsof');
The jsof.parse()
method parses a JS value string and returns a JavaScript value. Passes all 3 JSON pass tests. Also passes 18 of 33 JSON fail tests.
value = jsof.parse(text)
The jsof.stringify()
method converts a JavaScript value to a JS string.
text = jsof.stringify(value)
The same as jsof.parse()
but using shift-*
tools.
The same as jsof.stringify()
but using shift-*
tools.
npm test
MIT LICENSE.