durian
v0.2.1
Published
make your json support comment
Downloads
2
Readme
durian
Make your json support comment
only support single line comment '//'
Usage
parse
const fs = require('fs');
const durian = require('durian');
const input = fs.readFileSync(path.join(__dirname, './input.json'), 'utf8');
const result = durian.parse(input); // same as JSON.parse, just remove comments before parse;
input.json
// head comment
{
"code": 200,
"message": "success",
"result": {
"list": [
{
"goodsId": 1,
"goodsName": "Nike Kobe 8",
"url": "https://www.kaola.com"
},
// {
// "goodsId": 2,
// "goodsName": "Nike Kobe 9",
// "url": "https://www.kaola.com"
// },
{
"goodsId": 3,
"goodsName": "Nike Kobe 10",
"url": "https://www.kaola.com"
}
],
"total": 100
}
}
// tail comment
And the result is(a javascript variable, not string):
{
"code": 200,
"message": "success",
"result": {
"list": [
{
"goodsId": 1,
"goodsName": "Nike Kobe 8",
"url": "https://www.kaola.com"
},
{
"goodsId": 3,
"goodsName": "Nike Kobe 10",
"url": "https://www.kaola.com"
}
],
"total": 100
}
}
minify
const fs = require('fs');
const durian = require('durian');
const input = fs.readFileSync(path.join(__dirname, './input.json'), 'utf8');
const result = durian.minify(input);
And the result is(a string, remove the whitespaces within input):
{"code": 200,"message": "success","result": {"list": [{"goodsId": 1,"goodsName": "Nike Kobe 8","url": "https://www.kaola.com"},{"goodsId": 3,"goodsName": "Nike Kobe 10","url": "https://www.kaola.com"}],"total": 100}}
Build
$ npm run build
Publish
$ npm run publish