Easy to type JSON, skip the quotes, add them comments, great for config.
LazyJSON is a superset of JSON with a reduced syntax overhaed allowing configurations in scripts and files to remain clean, readable and easier to type.
ES6 import the lib and use parse
and stringify
as normal:
import LJSON from "lazyjson";
let config = LJSON.parse('foo:bar, abc:[a,b,c]');
console.log(config);
// {
// "foo": "bar",
// "abc": [
// "a",
// "b",
// "c"
// ]
// }
Use via Bun, npm or yarn:
bun add lazyjson
yarn add lazyjson
npm install lazyjson
LazyJSON supports single-line comments using // ...
and multi-line comments with /* ... */
.
Quotes are generally not required. However, if a string includes any of the following it must be enclosed in quotes:
//
/*
"
'
`
You can use "
, '
, or `
as quotes.
Example:
LJSON.parse(`
path: /usr/local/bin, // No quotes needed for paths
message: "Hello, world!", // Quotes required for strings with special characters
notes: 'Use "single quotes" if preferred',
notes2: \`Or use a 'backtick'\`,
/*
Yep,
trailing commas are also OK
*/
`);