A dynamic JSON parser that isn't strict and can be customized.
npm install @jsonic/jsonic-nextNOTE: PREVIEW VERSION OF NEXT RELEASE
*A JSON parser for JavaScript that isn't strict.
Also, it's very __very__ extensible.*
a:1,foo:bar → {"a": 1, "foo": "bar"}
Site |
Docs |
FP Guide |
Contributing |
Wiki |
Code of Conduct |
Twitter |
Chat


Install:
```
> npm install jsonic
Node.js:
``
const Jsonic = require('jsonic')
console.log(Jsonic('a:b')) // prints {a:'b'}
TypeScript:
``
import { Jsonic } from 'jsonic'
console.log(Jsonic('a:b')) // prints {a:'b'}
Browser:
``
(Although in the real world you'll probably be packaging _jsonic_ as a dependency with _webpack_ or similar.)
All of the examples below parse beautifully to {"a": 1, "b": "B"}.
short and sweet
``
a:1,b:B
no commas, no problem
``
a:1
b:B
comments are cool
`
a:1
// a:2a:3
/* b wants
* to B
*/
b:B
`
strings and things
`\x42
{ "a": 100e-2, '\u0062':, }`
The syntax of _jsonic_ is just easy-going JSON:
* simple no-quotes-needed property names: {a:1} → {"a": 1}a:1,b:2
* implicit top level (optional): → {"a": 1, "b": 2}, a,b → ["a", "b"]a:1,b:2,
* graceful trailing commas: → {"a": 1, "b": 2}, a,b, → ["a", "b"]1e1 === 0xa === 0o12 === 0b1010
* all the number formats:
But that is not all! Oh, no. That is not all...
This:
`Merge, baby, merge!
cat: { hat: true }
cat: { fish: null }
cat: who: ['sally', 'me']
Who needs quotes anyway?
holds up: [
cup and a cake,
TWO books!
the fish!,
'''
ship!
dish!
ball!
'''
]
}
`
parses into this:
``
{
"cat": {
"hat": true,
"fish": null,
"who": ["sally","me"]
},
"holds up": [
"cup and a cake",
"TWO books!\n the fish!",
"ship!\ndish!\nball!"
]
}
Meaning you also get:
* quotes can be single or double ': 'a',"b" → ['a', 'b']{a: cup cake }
* quotes are optional, even with spaces: → {"a": "cup cake"}a:{b:1},a:{c:2}
* object merging: → {"a": {"b": 1, "c": 2}}a:b:1,a:c:2
* object construction: → {"a": {"b": 1, "c": 2}}`
* multi-line strings: a
b ` "a\nb"
→ `
* indent-adjusted strings: `
'''
a
b
''' "a\nb"`
→
And we haven't even begun to talk about all the fun stuff you can do
with options and plugins, including support for multiple files,
CSV (or TSV), and dynamic content.
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
* unterminated strings?