Chuyển đến nội dung
Skillpedia
Lập trình chung75k · #2907

json-safety

Skill này làm gì

Skill này rà soát mã đọc JSON từ API, bộ nhớ trình duyệt hoặc người dùng, và đảm bảo lỗi phân tích được xử lý. Skill dành cho lập trình viên làm việc với dữ liệu bên ngoài.

Khi nào nên dùng

  • ✓Khi ứng dụng sập sau khi nhận một phản hồi API bị lỗi cấu trúc.
  • ✓Khi giá trị trong bộ nhớ trình duyệt bị hỏng và làm vỡ trang.
  • ✓Khi mã của bạn dùng dữ liệu đã phân tích mà không kiểm tra hình dạng của nó.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/json-safety/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Bạn có thể làm cho việc phân tích JSON của tôi an toàn trong trường hợp dữ liệu bị lỗi không?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent tìm các lệnh gọi JSON.parse và kiểm tra mỗi lệnh có được bọc trong xử lý lỗi không, cũng như kết quả có được xác thực trước khi dùng không. Agent có thể gợi ý thư viện xác thực schema cho dữ liệu bên ngoài.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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

Câu hỏi thường gặp

Điều gì xảy ra khi phân tích JSON thất bại?

Skill nói JSON.parse ném ra lỗi cú pháp, và lỗi này sẽ làm sập ứng dụng nếu không được bắt.

Vì sao cần kiểm tra dữ liệu đã phân tích?

Skill nói việc này phát hiện hình dạng dữ liệu bất thường ngay tại thời điểm phân tích, thay vì gây lỗi về sau.

Những thư viện nào được nhắc đến?

Skill nhắc đến Zod và Valibot là các bộ xác thực an toàn kiểu cho dữ liệu bên ngoài.

Chi tiết

Mô tả gốc của tác giả

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

Độ phổ biến

Sao GitHub
75k
Vị trí xếp hạng
#2907
Giấy phép
MIT
Cập nhật
31/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự