sample.json5をfetchで読み込んだサンプル

Consoleで結果を確認できます。

<script src="https://unpkg.com/json5@2/dist/index.min.js"></script>
fetch('sample.json5')
  .then(response => response.text())
  .then(json5 => JSON5.parse(json5))
  .then(data => console.log(data))
{
  /*
    複数行コメント
    キーは引用符を省略できます。
  */

  // シングルクォートが使用可能
  string: '文字列の\
改行文字をエスケープできる。',

  // 16進数が使用可能
  num: 0xFF,

  // 末尾カンマが使用可能
  object: {
    "キー": "値",
  },

  // NaNやInfinityも入れられる
  arr: [
    NaN,
    Infinity,
  ],
}

元記事を表示する