{"data":{"slug":"github-thedaviddias-front-end-checklist-skills-json-safety-a8445292255a","title":"Parse JSON Safely with Error Handling","summary":"Prevent application crashes by safely parsing JSON data with error handling and validation, ensuring malformed input is caught early.","url":"https:\/\/skillshunter.net\/skills\/github-thedaviddias-front-end-checklist-skills-json-safety-a8445292255a","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-thedaviddias-front-end-checklist-skills-json-safety-a8445292255a","markdown_url":"https:\/\/skillshunter.net\/skills\/github-thedaviddias-front-end-checklist-skills-json-safety-a8445292255a.md","download_url":"https:\/\/skillshunter.net\/skills\/github-thedaviddias-front-end-checklist-skills-json-safety-a8445292255a\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Ensure the JSON input is validated using try\/catch blocks and shape validation before accessing any properties. Use type-safe parsers like Zod or Valibot for external data sources.","instructions":"---\nname: json-safety\ndescription: \"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.\"\nmetadata:\n  category: javascript\n  priority: medium\n  difficulty: beginner\n  estimatedTime: \"10\"\n  source: frontendchecklist.io\n  url: https:\/\/frontendchecklist.io\/rules\/javascript\/json-safety\n---\n\n# Parse JSON safely with error handling\n\nJSON.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.\n\n## Quick Reference\n\n- JSON.parse() throws a SyntaxError on invalid input \u2014 always use try\/catch\n- Validate the shape of parsed data before accessing its properties\n- JSON.stringify() can return undefined for values that can't be serialized\n- Use a type-safe parser (Zod, Valibot) for data from external sources\n\n## Check\n\nFind 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.\n\n## Fix\n\nAdd try\/catch error handling to all JSON.parse() calls and add shape validation to protect against unexpected data structures.\n\n## Explain\n\nExplain why JSON.parse can throw, what safe JSON parsing looks like, and when to use schema validation libraries.\n\n## Code Review\n\nReview 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.\n\n---\n\nFor full implementation details, code examples, and framework-specific guidance,\nsee `references\/rule.md`.\n\nRule page: https:\/\/frontendchecklist.io\/rules\/javascript\/json-safety\n","use_cases":["Reviewing scripts that parse API responses","Validating user-provided data stored in localStorage","Inspecting browser execution paths for JSON parsing errors"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/thedaviddias\/Front-End-Checklist\/blob\/e8d14d049010e2ce25afcd5e8609dfcbbe63e47e\/skills\/json-safety\/SKILL.md","source_commit":"e8d14d049010e2ce25afcd5e8609dfcbbe63e47e","license":null,"version":null,"listing_approved_at":"2026-11-23","created_at":"2026-11-22T16:46:56.000000Z","updated_at":"2026-11-23T04:55:22.000000Z","seo_title":"Parse JSON safely with error handling","seo_description":"Ensure safe JSON parsing with error handling to prevent application crashes from malformed data.","seo_keywords":["safe JSON parsing","JSON error handling","prevent JSON crashes","validate parsed data","JSON parsing best practices"]}}