Can comments be used in JSON?

后端 未结 30 1647
别跟我提以往
别跟我提以往 2020-11-22 02:16

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

30条回答
  •  感情败类
    2020-11-22 02:42

    We are using strip-json-comments for our project. It supports something like:

    /*
     * Description 
    */
    {
        // rainbows
        "unicorn": /* ❤ */ "cake"
    }
    

    Simply npm install --save strip-json-comments to install and use it like:

    var strip_json_comments = require('strip-json-comments')
    var json = '{/*rainbows*/"unicorn":"cake"}';
    JSON.parse(strip_json_comments(json));
    //=> {unicorn: 'cake'}
    

提交回复
热议问题