Skip to content

samzhangjy/ts-json-parser

Repository files navigation

Type-level JSON Parser

A JSON parser written in TypeScript, and only TypeScript.

Usage

First install ts-json with a package manager:

$ npm i ts-json-parser

Example:

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:

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

About

A JSON parser written with TypeScript type system.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published