parseJson #

Parses JSON text and names label in the error when the text is invalid.

Usage #

TypeScript
import { 
parseJson
} from 'kawapress'
const
data
=
parseJson
<{
name
: string }>('{"name":"a"}')

Parameters

sourcestring

The JSON text.

optionsoptionalPick<JsonOperationOptions, 'label'>

label names the data in the error message.

default {}

Returns The parsed value, typed as T.

Full type signature
TypeScript
function parseJson<T>(source: string, options?: Pick<JsonOperationOptions, 'label'>): T

Edit this page

Comments