Just a little hack project to keep my C skills sharp. I don't intend to maintain this, and while it has tests, no guarantee of it's stability or security 🙃
Converts JSON
{
"pagination": {
"results": 152,
"limit": 2,
"skipped": 0
},
"users": [
{
"firstName": "John",
"lastName": "Smith",
"profileImage": "https://picsum.photos/200",
"recentLogins": [
1631391272,
1631393555
],
"premiumUser": false,
"favouriteProperties": [
{
"address": "123 fake street",
"suburb": "Springfield",
"country": "USA",
"rating": 5
}
]
},
{
"firstName": "Jane",
"lastName": "Doe",
"profileImage": null,
"premiumUser": true,
"favouriteProperties": [
{
"address": "456 second avenue",
"suburb": "Columbus",
"state": "OH",
"country": "USA",
"rating": 4
}
]
}
]
}
To a matching TypeScript type:
export type JsonData = {
pagination: {
results: number;
limit: number;
skipped: number;
};
users: Array<{
firstName: string;
lastName: string;
profileImage: null | string;
recentLogins?: number[];
premiumUser: boolean;
favouriteProperties: Array<{
address: string;
suburb: string;
country: string;
rating: number;
state?: string;
}>;
}>;
};
Designed to be highly performant with a small memory footprint.
Can convert ~135,000 files per second.
For convenience, a build.sh
is present in the repository to configure & build a binary from source.
Once compiled, the binary will take JSON via stdin, and provide typescript vis stdout. e.g.
curl https://api.my-example-app.com/books.json | json-to-ts > Books.ts
Tests are implemented in JavaScript.
The application must be built before tests can run
Run ./test.sh
to build & execute all tests