PythonとJSONの読解・作成4 / 8

JSONの構文

JSONにはobject、array、string、number、true、false、nullがある。objectのkeyとstringは二重引用符で囲む。comment、末尾の余分なcomma、PythonのTrue/False/None、tuple表記は使わない。NaNやInfinityも標準JSONのnumberではない。

{
  "device": "R1",
  "enabled": true,
  "interfaces": [
    {"name": "Gi0/0", "mtu": 1500},
    {"name": "Gi0/1", "mtu": 9000}
  ],
  "description": null
}

rootはこの例ではobject、interfacesはarrayである。interfaces[1]のmtuは9000になる。"1500"はstring、1500はnumberで、parseできることとAPI modelの型へ一致することは別である。二重引用符やbackslashをstringへ含める場合はescapeする。

学習パスへ
参考資料