downlink
v0.0.5
Published
A TypeScript module for converting JSON data (strings) into TypeScript interfaces.
Downloads
3
Maintainers
Readme
downlink (v0.0.5)
A TypeScript module for converting JSON data (strings) into TypeScript interfaces.
Example
const someJson: string = `
{
"foo": true,
"bar": 3.14,
"hype": "beast",
"favorites": [
"breakfast",
"lunch",
"dinner"
],
"clients": [
{
"id": 1,
"name": "Stan",
"contact-info": {
"phone": "+1 (111) 111-1111",
"email": "[email protected]"
}
},
{
"id": 2,
"name": "Beth",
"contact-info": {
"phone": "+1 (222) 222-2222",
"email": "[email protected]"
}
},
{
"id": 3,
"name": null,
"contact-info": {
"phone": "+1 (333) 333-3333",
"email": "[email protected]"
},
"isAdmin": true
}
],
"yikes": [
true,
2,
"three"
]
}
`
console.log(downlink(someJson))
Output
interface IRootClientContactInfo {
phone: string;
email: string;
}
interface IRootClient {
id: number;
name?: string;
"contact-info": IRootClientContactInfo;
isAdmin?: boolean;
}
interface IRoot {
foo: boolean;
bar: number;
hype: string;
favorites: string[];
clients: IRootClient[];
yikes: (boolean|number|string)[];
}
export {IRoot}