package.json comments - Can comments be used in JSON?

newtonsoft json comments / json / comments

Can I use comments inside a JSON file? If so, how?

Steve Chambers



Answer #1

If you are using Jackson as your JSON parser then this is how you enable it to allow comments:

ObjectMapper mapper = new ObjectMapper().configure(Feature.ALLOW_COMMENTS, true);

Then you can have comments like this:

{
  key: "value" // Comment
}
mapper.configure(Feature.ALLOW_YAML_COMMENTS, true);