这个 JSON 格式化模式有一个名称,前导逗号吗?

Is there a name for this JSON formatting pattern, with leading commas?

我见过有效的JSON这样写:

{ "version": 1
, "object":
  { "one": 1
  , "two": 2
  , "three": 3
  , "four": 4,
  , "five": 5
  }
, "array":
  [ 1
  , 2
  , 3
  ]
, "people":
  [ { "firstname": "Jacob",
    , "lastname": "Ford"
    }
  , { "firstname": "Marcin"
    , "lastname": "Wichary"
    }
  ]
}

我猜测主要优点是,添加或删除一行数据(除了少数例外)将被区分为:单行添加或删除。与更典型的 JSON 表示相反,尾随逗号,其中将项目附加到数组或对象的末尾需要编辑它之前的行,以添加逗号。

此 JSON 演示文稿约定是否有 名称,前导逗号,逗号与 opening/closing 括号放在同一列中?

它似乎通常被称为逗号优先符号(虽然有时也被称为前导 逗号),并且可以应用于 more than just JSON. SQL commands are another good example.

npm 的代码风格指南requires it for all comma-separated lists. Airbnb's forbids it.

我关于这种风格产生更清晰差异的假设是正确的;然而,有些人更喜欢通过坚持使用尾随逗号来实现相同的目标,但总是在最后一项之后包含一个(不必要的)悬空逗号。前面提到的 Airbnb 代码风格指南,在禁止逗号优先符号之后的部分中,requires 列表后悬挂逗号,明确表示差异。

支持者还指出了一个额外的优势,即在逗号优先的表示法中,印刷错误变得更加明显。 This gist npm 的发明者经常被引用,我将在这里摘录:

// error in standard style
var a = "ape",
  b = "bat",
  c = "cat",
  d = "dog"
  e = "elf",
  f = "fly",
  g = "gnu",
  h = "hat",
  i = "ibu";

// error in comma-first style
var a = "ape"
  , b = "bat"
  , c = "cat"
  , d = "dog"
  e = "elf"
  , f = "fly"
  , g = "gnu"
  , h = "hat"
  , i = "ibu"
  ;