JavaScript JSON & LocalStorage Debugger

    1

    Fix localStorage crashes and JSON parsing errors with safe fallback logic and schema validation.

    Free

    3 usesSecurity scanned

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+21 more

    JavaScript JSON & LocalStorage Debugger

    Example session with this skill installed

    My app is crashing with 'SyntaxError: Unexpected token u in JSON at position 0' when I try to load the 'user_settings' key from localStorage. Fix this code: JSON.parse(localStorage.getItem('user_settings'));

    • Read your context and instructions
    • Compiled the javascript json

    I have analyzed the parsing failure in your storage logic. **[Storage/JSON Debug Report]** **🔍 Diagnosis:** The error `Unexpected token u in JSON` occurs because `localStorage.getItem('user_settings')` is returning `undefined` or `null`. When `JSON.parse` receives the string `"undefined"` or a literal `null` without a fallback, the parser fails immediately. **️ The Fix:** ```javascript // Retrieve item and provide a stringified empty object as a fallback const rawData = localStorage.getItem('user_settings'); const settings = JSON.parse(rawData || '{}'); /** * Added safe fallback logic (|| '{}'). * This ensures that if the key is missing or null, * JSON.parse receives a valid JSON string, preventing the crash. */ ``` **🛡️ Recommended Validation (Optional but Recommended):** ```javascript // Ensure the parsed data meets your expected schema const requiredKeys = ['theme', 'notifications']; const isValid = settings && typeof settings === 'object' && requiredKeys.every(key => key in settings); if (!isValid) { console.warn('Settings data is missing required keys. Resetting to defaults.'); // Optional: localStorage.setItem('user_settings', JSON.stringify(defaultSettings)); } ``` **[Self-Check]** - [x] Root cause of the parsing/storage error identified - [x] Safe fallback logic (e.g., || '{}') implemented - [x] Code is copy-paste ready and well-commented - [x] Future validation suggestion provided **Next steps** 1. Check if the 'user_settings' key is being cleared by another part of your application. 2. Implement the recommended validation to handle partial or corrupted objects.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    The problem

    Malformed JSON and missing localStorage keys lead to silent application crashes or SyntaxError: Unexpected token errors. Developers often waste time writing repetitive try-catch blocks or forgetting safe fallbacks for browser storage.

    What it does

    • Identifies exact causes of parsing failures like trailing commas or single-quote usage.
    • Generates production-ready JavaScript/TypeScript with safe fallback defaults.
    • Handles localStorage and sessionStorage null-checks automatically.
    • Provides lightweight validation logic to prevent future type mismatches.

    Frameworks & tools

    JavaScript, TypeScript, Browser Web Storage API (localStorage/sessionStorage), and JSON spec.

    Why this beats prompting it yourself

    Generic prompts often miss the subtle nuance of JSON.parse(null) behavior. This skill enforces a strict diagnostic report format that includes both the immediate fix and a validation strategy to harden your frontend against edge cases.

    Use cases

    • Fixing Unexpected token errors in JSON data streams.
    • Migrating storage schemas without breaking existing user sessions.
    • Hardening user profile loading from localStorage.
    • Debugging null returns from missing browser keys.

    Focuses on client-side Web Storage and JSON parsing. Does not handle IndexedDB or server-side database migrations.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before any payment.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    3 uses

    Times used to date

    Free forever

    No account required to browse

    Trust & safety

    Security scan

    Security scan passed 2 months ago

    • Free with an Agensi account

    Permissions

    No special permissions declared or detected

    Listed2 months ago

    What's inside

    Frequently Asked Questions

    This skill diagnoses specific JSON syntax errors (like trailing commas or improper quoting) and generates robust TypeScript/JavaScript code that prevents browser crashes using safe fallbacks and schema validation.

    It is fully compatible with standard JavaScript and TypeScript projects, specifically targeting web applications that utilize the Browser Web Storage API (localStorage and sessionStorage).

    The skill provides a specialized diagnostic report that includes the root cause of the crash, a production-ready code fix, and a custom validation strategy to prevent future data corruption.

    Yes, it is designed to handle schema migrations by providing logic that checks for existing keys and safely updates or resets them without interrupting the user experience.

    The skill functions within any AI agent that supports custom instructions or tool calls, allowing you to integrate its debugging logic directly into your existing development workflow.

    Purchasing gives you full access to the skill's logic for your AI agent, including any future performance optimizations and updates to handle emerging browser storage edge cases.

    New in Testing & Debugging