Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/samzhangjy/ts-json-parser

A JSON parser written with TypeScript type system.
https://github.com/samzhangjy/ts-json-parser

Last synced: 9 days ago
JSON representation

A JSON parser written with TypeScript type system.

Awesome Lists containing this project

README

        

# Type-level JSON Parser

A JSON parser written in TypeScript, and only TypeScript.

## Usage

First install `ts-json` with a package manager:

```bash
$ npm i ts-json-parser
```

Example:

```ts
import type { JSON } from 'ts-json-parser';

type Parsed = JSON<`{
"title": "My Awesome Title",
"description": "My awesome description."
}`>;

/*
type Parsed = {
title: "My Awesome Title";
description: "My awesome description.";
}
*/
```

To primitive types:

```ts
import type { JSONPrimitive } from 'ts-json-parser';

type Parsed = JSONPrimitive<`{
"title": "My Awesome Title",
"description": "My awesome description.",
"price": 10,
"inStock": true
}`>;

/*
type Parsed = {
title: string;
description: string;
price: number;
inStock: boolean;
}
*/
```

## TODO

- Support floating numbers
- Support `stringify`