我能否在以下发言中发表一些意见?Json Json (Json Json) (Json Json Json) (Json Json) Json Json (Json Json) Json (Json) Json (Json) Json (Json) Json (Json) Json (Json) Json (Json) Json(Json) Json (Json) Json (Json) Json(Json) Json (Json) Json如果有,如何处理?


当前回答

我们正在使用strip-json-comments支持我们的项目。 它支持一些东西,比如:

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

简简npm install --save strip-json-comments安装和使用它如下:

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

其他回答

特意将JSON的评论删除。

我删除了JSON的评论,因为我看到有人利用他们来维持分解指令,这种做法会破坏互操作性。 我知道,缺乏评论会让一些人感到悲哀,但不应该。

假设您正在使用 JSON 保存配置文件, 您想要对此进行注释 。 请继续插入您想要的所有评论 。 然后通过 JSMIN 管道将其传送给您的 JSON 分析员 。

资料来源:Douglas Crockford在G+上的公开声明

你应该写一个杰森计划JSON Schema是目前提议的因特网规格草案,除了文件以外,还可以使用这一规格来验证你的JSON数据。

示例:

{
  "description": "A person",
  "type": "object",
  "properties": {
    "name": {
      "type": "string"
    },
    "age": {
      "type": "integer",
      "maximum": 125
    }
  }
}

您可以使用以下工具提供文档:描述说明说明说明说明说明说明schema 属性 。

在JSON的输出之前,我需要将评论用于调试目的。所以我把调试信息放进HTTP 信头为了避免客户被打破:

header("My-Json-Comment: Yes, I know it's a workaround ;-) ");

Enter image description here

我们正在使用strip-json-comments支持我们的项目。 它支持一些东西,比如:

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

简简npm install --save strip-json-comments安装和使用它如下:

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

原为:JSON发明家说:

JSON没有评论。 JSON 编码器必须输入输出评论。 JSON 编码器可能接受和忽略评论。

功用包含一个解码器, 它允许“ #” 式的评论, 所以jq 是一种工具, 可以与 JSON 与注释文件一起使用, 只要这些文件被当作“ jq 程序” 处理, 而不是作为 JSON 文件处理 。 例如 :

$ jq -ncf <(echo $'[1, # one\n2 ] # two') 
[1,2]

更重要的是,jq可以处理庞大的JSON与评论文件作为程序;这可以用众所周知的JSON文件加以说明:

$ ls -l JEOPARDY_QUESTIONS1.json
-rw-r--r--  2 xyzzy  staff  55554625 May 12  2016 JEOPARDY_QUESTIONS1.json

$ jq -nf JEOPARDY_QUESTIONS1.json | jq length
216930