NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
npm · #2530 most downloaded on npm
Parse and stringify JSON with comments. It will retain comments even after saved!
Last release 5 months ago
12 Apr 2026
Release timing varies
gaps range from 2 weeks to 1.9 years
Rarely documented
notes for 14 of the last 60 stable releases
1 version withdrawn
withdrawn after publishing
12 years old
64 releases · first in 2014
This release may introduce breaking changes for consumers who directly inspect or mutate comment tokens:
MAJOR: blank lines are now modeled explicitly instead of being inferred from loc and historical line-break logic.
BlankLine comment tokens and use them during parse() / stringify().parse(code, reviver, { no_comments, no_blank_lines }).removeBlankLines() for removing blank lines globally or at a specific comment location.This release may introduce breaking changes for consumers who directly inspect or mutate comment tokens:
CommentToken is now a union type. A token may be { type: 'BlankLine', inline: false }, so value and loc are no longer guaranteed on every token.stringify() no longer uses loc or the old internal blank-line history to infer empty lines. Blank lines are rendered only from explicit BlankLine tokens.If your existing usage includes business logic related to blank lines, you may notice behavior differences:
loc-based blank-line rendering may now produce different output unless it preserves BlankLine tokens explicitly.BlankLine.{ no_blank_lines: true } now provides an explicit way to drop blank lines, while default parsing preserves them as first-class tokens.An upgrade review is recommended for dependents that have custom comment-token processing or formatting logic around blank lines.
One column per quarter.
4.6.2: #60
4.6.2: #60
bump version 4.6.1: #29 , #36 , #42
Nothing published for this version
Nothing published for this version
MINOR : the new moveComments and removeComments to help you to manipulate comments
moveComments and removeComments to help you to manipulate commentsAn upgrade is recommended for all dependents
MINOR : #39 , implemented the tc39 proposal of https://github.com/tc39/proposal-json-parse-with-source (only the context.source ), so that it is possi
context.source), so that it is possible to handle BigInts.const {parse, stringify} = require('comment-json')
const parsed = parse(
`{"foo": 9007199254740993}`,
// The reviver function now has a 3rd param that contains the string source.
(key, value, {source}) =>
/^[0-9]+$/.test(source) ? BigInt(source) : value
)
console.log(parsed)
// {
// "foo": 9007199254740993n
// }
stringify(parsed, (key, val) =>
typeof value === 'bigint'
// Pay attention that
// JSON.rawJSON is supported in node >= 21
? JSON.rawJSON(String(val))
: value
)
// {"foo":9007199254740993}An upgrade is recommended for all users.
4.4.0: fixes #39
4.4.0: fixes #39
CI: improves github action
CI: improves github action
Nothing published for this version
Nothing published for this version
Nothing published for this version
MINOR: #33, symbol support for typescript definitions. Since new version of typescript eventually supports symbol object properties, this update uses
symbol type instead of any for comment propertiesAn upgrade is recommended for all users.
Nothing published for this version
Nothing published for this version
Nothing published for this version
MINOR: #19, CommentArray::sort will now maintain comments
CommentArray::sort will now maintain commentsAn upgrade is recommended for all users.
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
4.0.0 brings breaking changes, but however, logically but not programmatically.
after-comma:${prop} and after symbol properties, and introduce after:${prop}Object.keys to get the keys of the parsed object as the normal ones4.0.0 brings breaking changes, but however, logically but not programmatically.
So for most scenarios, you need NOT to change your code, and an upgrade is recommended.
assign instead of object spreadingconst parsed = parse(`{
// comment
"foo": "bar"
}`)
In 3.x, it is ok to do as following
stringify({...parsed}, null, 2)
// {
// // comment
// "foo": "bar"
// }
But with comment-json@4.0.0, the code above will print
{
"foo": "bar"
}
Because since 4.0.0, symbol properties of comments are non-enumerable, so object spreading will not work for this case, and you should use assign function to copy those properties.
const {assign} = require('comment-json')
stringify(assign({}, parsed), null, 2)
TL;NR
{
"foo": "bar" /* after value */, // after foo
"bar": "baz" // after bar
}
In 3.x
after foo is marked as Symbol.for('after-comma:foo') after bar is marked as Symbol.for('after-value:bar')But in 4.x
after foo is marked as Symbol.for('after:foo') after bar is marked as Symbol.for('after:bar')And in both 3.x and 4.x after value is marked as Symbol.for('after-value:foo')
Nothing published for this version
Nothing published for this version
Nothing published for this version
3.0.0 brings a breaking change, but however, logically but not programmatically.
In 2.x, inline comments after comma(,) are not belong to the current prop, see #17
const {parse, stringify, assign} = require('comment-json')
// Just insert a new property `baz` into the parsed object and return a new object
// TL;NR
const insert_baz = (origin, value) => {
const obj = {}
assign(obj, origin, ['foo'])
obj.baz = value
assign(obj, origin, ['bar'])
return obj
}
// 2.x
const parsed = parse(`{
"foo": "foo", // foo
"bar": "bar"
}`)
const obj = insert_baz(parsed, 'baz')
console.log(stringify(obj, null, 2))
// {
// "foo": "foo",
// "baz": "baz", // foo
// "bar": "bar"
// }
Because, in 2.x, inline comment ' foo' is a before:bar comment token of property bar.
And, in the new MAJOR version 3.0.0, we introduce a new comment token type after-comma:${prop} to fix this issue.
If the code above is executed with comment-json 3.0.0, the result will be
{
"foo": "foo", // foo
"baz": "baz",
"bar": "bar"
}
3.0.0 brings a breaking change, but however, logically but not programmatically.
So for most scenarios, you need not to change your code.
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
FEATURE: Support trailing commas for objects and arrays
parse(`{
// comment
foo: 'bar',
}`)
FEATURE: Introduce the CommentArray to auto deal with comments when modified. See here for details
2.1.0CommentArray to auto deal with comments when modified. See here for detailsThis major version fixes several issues and provides new features:
2.0.9This major version fixes several issues and provides new features:
1.xThe new version uses Symbols to store comments so that they will never conflict with normal JSON property fields, so the structure of the return value of method parse() changes.
For details, see the document
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Your coding agent can read these notes before it upgrades. Set up the MCP server →