Skip to content

ParseJSON ​

Since 1.4.0

Parse JSON string to type.

Signature ​

typescript
type ParseJSON<S extends string> = S extends `"${infer Content}"` ? Content : ...

Parameters ​

ParameterDescription
SJSON string to parse

Description ​

Type-level JSON parser with limited support for primitive types.

Examples ​

Basic Usage ​

typescript
import type { ParseJSON } from 'uni-types'

type String = ParseJSON<'"hello"'>
// 'hello'

type Number = ParseJSON<'123'>
// 123

type Boolean = ParseJSON<'true'>
// true

type Null = ParseJSON<'null'>
// null

Released under the MIT License.