本文へスキップ
Skillpedia
一般的なプログラミング75k · #2907

json-safety

できること

このスキルは、APIやブラウザーの保存領域、ユーザーから読み込むJSONを扱うコードを確認し、解析エラーが適切に処理されているか確かめます。外部データを扱う開発者向けです。

使う場面

  • ✓不正な形式のAPI応答を受け取った後にアプリが停止するとき。
  • ✓ブラウザーの保存値が壊れてページが動かなくなるとき。
  • ✓解析したデータの形を確認せずに使っているとき。

スキルのリンク

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/json-safety/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/json-safety/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“JSONの形式が不正な場合にも備えて、私のJSON解析を安全にしてください。”

毎週5つの新しいスキル。1分で読めます。

仕組み

エージェントはJSON.parseの呼び出しを見つけ、それぞれがエラー処理で囲まれているか、使用前に結果が検証されているかを確認します。外部データにはスキーマ検証ライブラリを提案することがあります。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

Parse JSON safely with error handling

JSON.parse() on invalid input throws a SyntaxError that will crash your application if uncaught. API responses, localStorage values, and user-provided data can all be malformed. Safe parsing with validation catches these errors at the point of parsing, not deep in your application logic when a missing property causes an unexpected error.

Quick Reference

  • JSON.parse() throws a SyntaxError on invalid input — always use try/catch
  • Validate the shape of parsed data before accessing its properties
  • JSON.stringify() can return undefined for values that can't be serialized
  • Use a type-safe parser (Zod, Valibot) for data from external sources

Check

Find all JSON.parse() calls in this file and check whether each one is wrapped in try/catch and whether the result is validated before use.

Fix

Add try/catch error handling to all JSON.parse() calls and add shape validation to protect against unexpected data structures.

Explain

Explain why JSON.parse can throw, what safe JSON parsing looks like, and when to use schema validation libraries.

Code Review

Review scripts, client components, and browser execution paths related to Parse JSON safely with error handling. Flag exact imports, event handlers, runtime side effects, or blocking operations that violate the rule, and state how the change should be verified in the browser.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/rules/javascript/json-safety

よくある質問

JSONの解析が失敗すると何が起きますか?

このスキルによると、JSON.parseは構文エラーを投げ、捕捉されなければアプリが停止します。

解析したデータを検証するのはなぜですか?

このスキルによると、後でエラーが起きるのではなく、解析の時点で想定外の形を見つけられます。

どのライブラリが挙げられていますか?

このスキルは、外部データ向けの型安全なバリデーターとして、ZodとValibotに触れています。

詳細

作者による元の説明

Use when reviewing scripts, client components, bundles, or runtime behavior related to Parse JSON safely with error handling. Inspect both source code and the browser execution path so fixes target the real bottleneck or bug.

repo: thedaviddias/Front-End-Checklist

人気

GitHubのスター
75k
ランキング
#2907
ライセンス
MIT
更新日
2026/10/31

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル