このページは FormatArc のブログ記事が引用している実測の生データです。検索結果には表示されません (noindex)。
| File | Size |
|---|---|
| README.md | 4.0 KB |
| check.mjs | 2.8 KB |
| results.json | 1.9 KB |
# json-parse-error のエラーメッセージ実測
`json-parse-error` 記事 (ja/en/es/pt) が引用する `JSON.parse()` のエラー文字列の一次ソース。
記事は長らく Node の旧いバージョン (V8 が `SyntaxError: Unexpected token X in JSON at
position N` 形式を返していた頃) のメッセージを引用したままだったが、現行 V8 は同じ壊れた
JSON に対して異なる文言を返す。本ベンチマークはその差分を実測で確定する。
## 測定環境
| 項目 | 値 |
| --- | --- |
| Node | v26.3.1 |
| V8 | 14.6.202.34-node.20 |
| platform | darwin arm64 |
`results.json` の `generatedAt` / `node` / `v8` / `platform` フィールドが実行時の実測値。
## 再現手順
```bash
cd scripts/benchmarks/json-parse-error-messages
node check.mjs
```
`check.mjs` は記事本文と同一の「壊れた JSON」入力 9 ケースを `JSON.parse()` に渡し、
実際にスローされる `SyntaxError.message` を収集して `results.json` に書き出す。
## ケース一覧
| id | 記事内の対応箇所 | 入力 |
| --- | --- | --- |
| `intro-single-quote-value` | 冒頭の "Unexpected token" 説明例 | オブジェクト値がシングルクォート |
| `trailing-comma-object` | 原因1 (末尾カンマ): オブジェクト | `}` の直前にカンマ |
| `trailing-comma-array` | 原因1 (末尾カンマ): 配列 | `]` の直前にカンマ |
| `unquoted-keys` | 原因3: クォートなしキー | `name:` のようにキーを裸で書く |
| `comments` | 原因4: コメント | `//` `/* */` を含む |
| `bom` | 原因5: BOM | 先頭に `U+FEFF` |
| `undefined-value` | 症状別: token u | `JSON.parse(undefined)` |
| `object-value` | 症状別: token o | `JSON.parse({ name: "Alice" })` |
| `html-response` | 環境別表: HTML が返る | `<!DOCTYPE html>` |
## 確定したこと
- **引用符付きトークン形式 (`Unexpected token 'X', "..." is not valid JSON`) は position
の数値を出さない。** 旧メッセージの `at position N` に相当する情報が無い
- **`Expected double-quoted property name in JSON at position N (line L column C)` /
`Expected property name or '}' in JSON at position N (line L column C)` 形式は
`(line L column C)` を併記する。** 旧メッセージにはこの併記が無かった
- **原因1 (オブジェクトの末尾カンマ) は現行 V8 では `Unexpected token` ではなく
`Expected double-quoted property name` になる。** 「閉じ波括弧が unexpected token に
なる」という記事の従来の説明はこのケースでは成立しない
- **配列の末尾カンマは `Unexpected token ']'` のまま**で、こちらは旧来の "unexpected
token" 系の説明が引き続き成立する
- **クォートなしキーとコメントは、現行 V8 では同一のメッセージ
(`Expected property name or '}' in JSON at position 4 (line 2 column 3)`) になる。**
原因が違っても文言だけでは区別できない
- `JSON.parse(undefined)` / `JSON.parse({ name: "Alice" })` は、どちらも
「`undefined` / オブジェクトが暗黙に文字列化され、その文字列が JSON として不正」という
経路を通る点は旧メッセージ時代と変わらないが、出力される文言自体は
`"undefined" is not valid JSON` / `"[object Object]" is not valid JSON` に変わった
## 確定していないこと
- **V8 のどのバージョンからこの形式に変わったかは未検証。** 本ベンチマークは「現行 V8 で
実際に出る文言」を確定するものであり、変更履歴 (V8 の changelog やコミット) までは
追っていない。記事本文にもバージョン境界は書いていない
- Node 以外のランタイム (ブラウザの V8 / Firefox の SpiderMonkey / Python /
Java) は本ベンチマークの対象外。ブラウザ環境別表の Firefox 行は MDN のドキュメント
(`developer.mozilla.org/.../Errors/JSON_bad_parse`) を出典とし、本ベンチマークでは実行
検証していない
{
"generatedAt": "2026-08-14T01:43:27.384Z",
"node": "v26.3.1",
"v8": "14.6.202.34-node.20",
"platform": "darwin arm64",
"cases": [
{
"id": "intro-single-quote-value",
"label": "冒頭例: オブジェクト値がシングルクォート",
"threw": true,
"message": "Unexpected token ''', ...\" \"city\": 'Tokyo'\n}\" is not valid JSON"
},
{
"id": "trailing-comma-object",
"label": "原因1: オブジェクトの末尾カンマ",
"threw": true,
"message": "Expected double-quoted property name in JSON at position 53 (line 5 column 1)"
},
{
"id": "trailing-comma-array",
"label": "原因1: 配列の末尾カンマ",
"threw": true,
"message": "Unexpected token ']', ...\"\", \"blue\",]\n}\" is not valid JSON"
},
{
"id": "unquoted-keys",
"label": "原因3: クォートなしキー",
"threw": true,
"message": "Expected property name or '}' in JSON at position 4 (line 2 column 3)"
},
{
"id": "comments",
"label": "原因4: コメント",
"threw": true,
"message": "Expected property name or '}' in JSON at position 4 (line 2 column 3)"
},
{
"id": "bom",
"label": "原因5: BOM 付き JSON",
"threw": true,
"message": "Unexpected token '', \"{\n \"name\"... is not valid JSON"
},
{
"id": "undefined-value",
"label": "JSON.parse(undefined)",
"threw": true,
"message": "\"undefined\" is not valid JSON"
},
{
"id": "object-value",
"label": "JSON.parse({ name: \"Alice\" })",
"threw": true,
"message": "\"[object Object]\" is not valid JSON"
},
{
"id": "html-response",
"label": "HTML エラーページを JSON.parse に渡す",
"threw": true,
"message": "Unexpected token '<', \"<!DOCTYPE html>\" is not valid JSON"
}
]
}