Skip to content

BubbleTeam/durian

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 publish

About

Make your json support comments

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published