parse-json-comments
v1.0.10
Published
Extract comments from a JSON.
Downloads
9
Readme
parse-json-comments
Extract comments from a JSON.
Install
npm install parse-json-comments
Usage
import parse from 'parse-json-comments';
const codeWithComments = `
{
"name": "John",
//Comment for name
"age": 32, // Comment for agew
"nocomment":123,
"dashi":1,
//大事大事
"city": false, //bool comment
"null": null, //null comment
"string": "我是字符串//串", //string comment
"list": [
{
"age222": 30, // age222age222age222age222
"city333": "New YorkLodash " // city Additional comment3
},
{
"name111": "John", // dasdasddassdsadsa
"age222": 30,
"city333": " " // city Additional comment3
},
]
}
`
console.log(parse(codeWithComments));
上述结果输出:
[
{
"key": "name",
"value": "John",
"description": "Comment for name",
"not_null": 1,
"field_type": "String",
"type": "Text",
"is_checked": 1,
"param_id": "38048587b89000"
},
{
"key": "age",
"value": "32",
"description": "Comment for agew",
"not_null": 1,
"field_type": "Number",
"type": "Text",
"is_checked": 1,
"param_id": "38048587f89001"
},
{
"key": "nocomment",
"value": "123",
"description": "",
"not_null": 1,
"field_type": "Number",
"type": "Text",
"is_checked": 1,
"param_id": "38048587f89002"
},
{
"key": "dashi",
"value": "1",
"description": "",
"not_null": 1,
"field_type": "Number",
"type": "Text",
"is_checked": 1,
"param_id": "38048587f89003"
},
{
"key": "email",
"value": "1",
"description": "Email address, for example, [email protected]",
"not_null": 1,
"field_type": "Number",
"type": "Text",
"is_checked": 1,
"param_id": "38048587f89004"
},
{
"key": "obj",
"value": "",
"description": "",
"not_null": 1,
"field_type": "Object",
"type": "Text",
"is_checked": 1,
"param_id": "38048587f89005"
},
{
"key": "obj.obj_id",
"value": "123",
"description": "我是对象",
"not_null": 1,
"field_type": "Number",
"type": "Text",
"is_checked": 1,
"param_id": "38048587f89006"
},
{
"key": "city",
"value": "false",
"description": "bool comment",
"not_null": 1,
"field_type": "Boolean",
"type": "Text",
"is_checked": 1,
"param_id": "38048587f89007"
},
{
"key": "null",
"value": "",
"description": "null comment",
"not_null": 1,
"field_type": "Null",
"type": "Text",
"is_checked": 1,
"param_id": "38048587f89008"
},
{
"key": "string",
"value": "我是字符串//串",
"description": "串",
"not_null": 1,
"field_type": "String",
"type": "Text",
"is_checked": 1,
"param_id": "38048587f89009"
},
{
"key": "list",
"value": "",
"description": "For lists desc",
"not_null": 1,
"field_type": "Array",
"type": "Text",
"is_checked": 1,
"param_id": "38048587f8900a"
},
{
"key": "list.age222",
"value": "30",
"description": "age222age222age222age222",
"not_null": 1,
"field_type": "Number",
"type": "Text",
"is_checked": 1,
"param_id": "38048587f8900b"
},
{
"key": "list.city333",
"value": "New YorkLodash ",
"description": "city Additional comment3",
"not_null": 1,
"field_type": "String",
"type": "Text",
"is_checked": 1,
"param_id": "38048587f8900c"
},
{
"key": "list.name111",
"value": "John",
"description": "dasdasddassdsadsa",
"not_null": 1,
"field_type": "String",
"type": "Text",
"is_checked": 1,
"param_id": "38048587f8900d"
},
{
"key": "list.age222",
"value": "30",
"description": "age222age222age222age222",
"not_null": 1,
"field_type": "Number",
"type": "Text",
"is_checked": 1,
"param_id": "38048587f8900e"
},
{
"key": "list.city333",
"value": " ",
"description": "city Additional comment3",
"not_null": 1,
"field_type": "String",
"type": "Text",
"is_checked": 1,
"param_id": "38048587f8900f"
},
{
"key": "qiantao",
"value": "",
"description": "",
"not_null": 1,
"field_type": "Object",
"type": "Text",
"is_checked": 1,
"param_id": "38048587f89010"
},
{
"key": "qiantao.lists",
"value": "",
"description": "For lists desc",
"not_null": 1,
"field_type": "Array",
"type": "Text",
"is_checked": 1,
"param_id": "38048587f89011"
},
{
"key": "qiantao.lists.qiantao1",
"value": "30",
"description": "qiantao1 desc",
"not_null": 1,
"field_type": "Number",
"type": "Text",
"is_checked": 1,
"param_id": "38048587f89012"
},
{
"key": "qiantao.lists.qiantao2",
"value": "New YorkLodash ",
"description": "qiantao2 desc",
"not_null": 1,
"field_type": "String",
"type": "Text",
"is_checked": 1,
"param_id": "38048587f89013"
},
{
"key": "qiantao.lists.qiantao3",
"value": "John",
"description": "qiantao3 desc",
"not_null": 1,
"field_type": "String",
"type": "Text",
"is_checked": 1,
"param_id": "38048587f89014"
},
{
"key": "qiantao.lists.qiantao4",
"value": "30",
"description": "qiantao4 desc",
"not_null": 1,
"field_type": "Number",
"type": "Text",
"is_checked": 1,
"param_id": "38048588389015"
}
]
License
MIT