How CommentArray works and how to use it
masterAll arrays within a parsed object are instances of CommentArray. These special arrays automatically handle comment symbol properties when modified using standard array methods like .unshift(), .push(), etc.
Warning: If you reassign a property that was a CommentArray to a standard JavaScript array, all associated comments will be lost. To maintain comments when creating new arrays, you must wrap the new data in a new CommentArray().
const {parse, stringify, CommentArray} = require('comment-json')
const parsed = parse(`{
"foo": [
// bar
"bar",
// baz,
"baz"
]
}`)
// Correct way to reassign while preserving comments:
parsed.foo = new CommentArray('quux').concat(parsed.foo)
stringify(parsed, null, 2)
// {
// "foo": [
// "quux",
// // bar
// "bar",
// // baz
// "baz"
// ]
// }