Skip to content

mathiasrw/lazyjson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LazyJSON

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.

Example

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"
//    ]
//  }

Install

Use via Bun, npm or yarn:

bun add lazyjson

yarn add lazyjson

npm install lazyjson

Comments

LazyJSON supports single-line comments using // ... and multi-line comments with /* ... */.

Quotes

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
  */
`);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published