1.0.0 • Published 1 year ago

ts-json-parser v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

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