- Home
- Skills
- Testing & Debugging
- JavaScript JSON & LocalStorage Debugger
JavaScript JSON & LocalStorage Debugger
Fix localStorage crashes and JSON parsing errors with safe fallback logic and schema validation.
Free
Works with the AI Agents you already use
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
localStorageandsessionStoragenull-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 tokenerrors in JSON data streams. - Migrating storage schemas without breaking existing user sessions.
- Hardening user profile loading from
localStorage. - Debugging
nullreturns 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
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
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 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