Web APIs & Utilities
Safe JSON Parser (No Throw)
easyJS SpecificJS / TS3 tests
Problem Statement
Implement `safeJsonParse(text, fallback)` that parses a JSON string. If parsing succeeds, returns the parsed value; if parsing throws a SyntaxError, returns `fallback` (default: `null`) without throwing.
Examples
Example 1:
safeJsonParse('{"a":1}'); // { a: 1 }
Example 2:
safeJsonParse('invalid-json', { error: true }); // { error: true }JavaScript & TypeScript starter code included
Run this as a live interviewPractice solo
3 test cases. No second person needed.