Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/tani/jsonup

compile-time json-parser
https://github.com/tani/jsonup

Last synced: about 2 months ago
JSON representation

compile-time json-parser

Awesome Lists containing this project

README

        

# jsonup

https://jsr.io/@tani/jsonup

This is a zero dependency compile-time JSON parser written in TypeScript.

## Usage

```typescript
import { JSONUP, ObjectLike } from 'jsonup' // Node
import { JSONUP, ObjectLike } from 'jsr:@tani/jsonup' // Deno

const src = `{ "name": "jsonup" }`

type Str = typeof src // Type: `'{ "name": "jsonup" }'`
type Obj = ObjectLike // Type: `{ name: string }`

/**
* JSONUP.parse infers the type from a given object.
* The type parameter is optional.
*/
// Type: `{ name: string }` the inferred record type
// Value: `{ name: "jsonup" }` the generated object
let obj = JSONUP.parse(src)
let obj = JSONUP.parse(src)

/**
* JSONUP.stringify guarantees the semantic equality between
* the generated string and the given literal type.
* The type parameter is required (maybe).
*/
// Type: `'{ "name": "jsonup" }'` the given literal type
// Value: `'{ "name": "jsonup" }'` the generated string
const str = JSONUP.stringify(obj)
```

## Copyright and License

(c) 2022 TANIGUCHI Masaya. https://git.io/mit-license