jc

json-comments

comments support for json in node.js

Showing:

Popularity

Downloads/wk

543

GitHub Stars

19

Maintenance

Last Commit

8yrs ago

Contributors

1

Package

Dependencies

0

Size (min+gzip)

0.6KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

JSON Comments NPM version

Make your json config support comments.

Installation

$ npm install json-comments

Syntax:

// require `json-comments` in your main module only once
require('json-comments');

Examples:

config.json

{
  // this is host
  "host" : "localhost",

  "port" : 3000, //port

  "url" : "https://github.com/numbcoder", /* url */

  /*
  * comments support for json
  */
  "username": "abc"
}

app.js

require('json-comments');
var config = require('./config');

console.log(config);
// ...

Parse JSON string

var JSONC = require('json-comments');
var fs = require('fs');

var content = fs.readFileSync('./config.json', 'utf8');
// parse JSON String
var config = JSONC.parse(content);

console.log(config);

Minify the JSON string

var JSONC = require('json-comments');
var fs = require('fs');

var content = fs.readFileSync('./config.json', 'utf8');

// remove comments and spaces from JSON String
var JsonStr = JSONC.minify(content);

License

MIT

Bitdeli Badge

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial