Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »

json-comments

0.2.1 • Public • Published

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

Keywords

none

install

npm i json-comments

Downloadsweekly downloads

244

version

0.2.1

license

none

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability