Link Search Menu Expand Document

Comment-json

const {
  parse,
  stringify,
  assign 
} = require('comment-json')
const fs = require('fs')
 
const obj = parse(fs.readFileSync('package.json').toString())
 
console.log(obj.name) // comment-json
 
stringify(obj, null, 2)

API

assign(target: object, source?: object, keys?: Array)

const parsed = parse(`// before all
{
  // This is a comment
  "foo": "bar"
}`)
 
const obj = assign({
  bar: 'baz'
}, parsed)
 
stringify(obj, null, 2)
// // before all
// {
//   "bar": "baz",
//   // This is a comment
//   "foo": "bar"
// }