https://github.com/tani/jsonup
compile-time json-parser
https://github.com/tani/jsonup
Last synced: 4 months ago
JSON representation
compile-time json-parser
- Host: GitHub
- URL: https://github.com/tani/jsonup
- Owner: tani
- License: mit
- Created: 2022-07-08T07:16:54.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-11T02:31:04.000Z (9 months ago)
- Last Synced: 2024-10-17T23:49:49.652Z (4 months ago)
- Language: TypeScript
- Size: 18.6 KB
- Stars: 58
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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' // Denoconst 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