ts-json-decoder
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

Typescript JSON Decoder

The typescript library that helps to decode and check raw json with types.

Install

npm install ts-json-decoder

Example

import { decodeObject, decodeBoolean, decodeNumber, decodeString } from 'ts-json-decoder';

const userData = {
    name: 'Joe',
    age: 30,
    hasJob: true
}

interface User {
    name: string;
    age: number;
    hasJob: boolean;
}

const result = decodeObject<User>(userData, (data) => ({
    name: decodeString(data.name),
    age: decodeNumber(data.age),
    hasJob: decodeBoolean(data.hasJob),
}));

result
    .then(console.log)
    .catch(console.log)

Readme

Keywords

Package Sidebar

Install

npm i ts-json-decoder

Weekly Downloads

4

Version

1.0.5

License

ISC

Unpacked Size

12.3 kB

Total Files

7

Last publish

Collaborators

  • sylorei