UNPKG

pure-parse

Version:

Strongly typed validation library that decouples type aliases from validation logic

25 lines (24 loc) 749 B
import { JsonValue } from '../common'; import { Parser } from './Parser'; /** * Parses a JSON value from a JSON string. * @example * ```ts * parseJson('{"key": "value"}') // -> ParseSuccess<JsonValue> * parseJson('123') // -> ParseSuccess<JsonValue> * ``` * The value must be a JSON-string: * ```ts * parseJson('not a json string') // -> ParseFailure * parseJson(123) // -> ParseFailure * parseJson(null) // -> ParseFailure * ``` * @example * You can chain together `parseJson` with other parsers: * ```ts * const parseUserJson = chain(parseJson, parseUser) * parseUserJson('{"name": "John", "age": 30}') // -> ParseSuccess<{ name: string, age: number }> * ``` * @param data */ export declare const parseJson: Parser<JsonValue>;