Safely parses JSON string with type validation.
The JSON string to parse
Type guard function to validate the parsed value
The parsed and validated value, or null if parsing/validation fails
const jsonStr = '{"user_address": "0x123...", "identity": {}}';const result = safeParseJSON(jsonStr, isAPIResponse);if (result) { console.log('Parsed server output:', result.user_address);} else { console.log('Invalid JSON or type mismatch');} Copy
const jsonStr = '{"user_address": "0x123...", "identity": {}}';const result = safeParseJSON(jsonStr, isAPIResponse);if (result) { console.log('Parsed server output:', result.user_address);} else { console.log('Invalid JSON or type mismatch');}
Safely parses JSON string with type validation.