Save Parse Json
A wrapper for 'JSON.parse()' to support 'undefined' value. If parsing fails, it silently returns 'undefined'.
| Category | Parsers |
| Author | Pol Gubau |
| Since | 1.0.0 |
| Last Updated | 2025-03-15 |
| Type | Sync |
| Compatibility | Universal |
Example
Input
saveParseJson('{"name":"John"}')Output:
{"name": "John"}Input
saveParseJson('null')Output:
undefined
Input
saveParseJson('undefined')Output:
undefined
Return
Parsed object of type T or undefined if the input is null or an error occurs.
Type: T | undefined
Props
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| value | string | null | null | Yes | The string to be parsed as JSON. |
Notes
This function parses a JSON string and returns 'undefined' for null or non-parsable values, without throwing errors.
Errors
No error is thrown, it silently returns 'undefined' in case of failure.
Tags
- JSON
- parse
- wrapper
- undefined
- error handling