Unlike XML and YAML, JSON lacks native support for comments which is often missed. In addition, the trailing comma which would make diff on multiline value neat is also not available in JSON. If you are on PHP, then here is a little library adhocore/json-comment to fix it in the userland.
Thanks to this library, a JSON like this will be possible:
{"name":"adhocore/json-comment","description":"JSON comment stripper library for PHP","type":/*Thisiscreepycomment*/"library","keywords":["json","comment",//Singlelinecomment,Noticethecommabelow:"strip-comment",],"license":"MIT",/**Thisisamultilinecomment.*/"authors":[{"name":"Jitendra Adhikari","email":"jiten.adhikary@gmail.com",},],"autoload":{"psr-4":{"Ahc\\Json\\":"src/",},},"autoload-dev":{"psr-4":{"Ahc\\Json\\Test\\":"tests/",},},"require":{"php":">=7.0","ext-ctype":"*",},"require-dev":{"phpunit/phpunit":"^6.5 || ^7.5 || ^8.5",},"scripts":{"test":"phpunit","echo":"echo '// This is not comment'","test:cov":"phpunit --coverage-text",},}
Installation and Usage
composer req adhocore/json-comment
useAhc\Json\Comment;// Only strip and do not decode it already:(newComment)->strip('{
"a":1,
// Hmmm
"b":2,,
}');// Strip comment and decode as JSON:Comment::parse('{
"a":1,
// Hmmm
"b":2,,
}',true);// Read JSON file, strip comments and decode as JSON:Comment::parseFromFile('/path/to/commented.json',true);
PS: A new version 1.1.0 of this library has been just released.
Please use it and let know in the feedback or repo ticket if any issues.