Skip to content
Skillpedia
General coding75k · #2907

json-safety

What it does

This skill reviews code that reads JSON from APIs, browser storage or users, and makes sure parsing errors are handled. It is for developers who handle external data.

When to use it

  • ✓When your app crashes after receiving a malformed API response.
  • ✓When a browser storage value is corrupted and breaks the page.
  • ✓When your code uses parsed data without checking its shape.

Skill link

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

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/json-safety/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute →

Example of what to ask your AI

“Can you make my JSON parsing safe in case the data is malformed?”

5 new skills a week. 1 minute to read.

How it works

The agent finds JSON.parse calls and checks that each one is wrapped in error handling and that the result is validated before use. It can suggest a schema validation library for external data.

Technical content (original SKILL.md)

Original text by the author, straight from 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

FAQ

What happens when JSON parsing fails?

The skill says JSON.parse throws a syntax error, which will crash the app if it is not caught.

Why validate parsed data?

The skill says it catches unexpected shapes at the point of parsing, instead of causing errors later.

Which libraries are mentioned?

The skill mentions Zod and Valibot as type-safe validators for external data.

Details

Original description by the author

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

Popularity

GitHub stars
75k
Ranking position
#2907
License
MIT
Updated
10/31/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills