Writing interfaces can be annoying.
You can save a lot of time when you have to define Typescript interfaces for data that you are loading from a webservice.
Instead of typing all the interfaces yourself you can just use a nice service in the web: json2ts
Just paste in your json code and it generates the corresponding interfaces in Typescripts.
Example JSON:
[
{
"city": "Berlin",
"country": "Germany",
"currencies": [{"code":"EUR"}]
},
{
"city": "Paris",
"country": "France",
"currencies": [{"code":"EUR"}]
}
]
Generated code:
declare module namespace {
export interface Currency {
code: string;
}
export interface RootObject {
city: string;
country: string;
currencies: Currency[];
}
}
Now you just have to rename the 'RootObject' to a name you like.
Check it out here: http://json2ts.com/
For the case you need c# code try this http://json2csharp.com/. Both services are based on the JSON C# Class Generator.
Thanks to Timmy Kokke and Jonathan Keith for giving that to the community.
You can save a lot of time when you have to define Typescript interfaces for data that you are loading from a webservice.
Instead of typing all the interfaces yourself you can just use a nice service in the web: json2ts
Just paste in your json code and it generates the corresponding interfaces in Typescripts.
Example JSON:
[
{
"city": "Berlin",
"country": "Germany",
"currencies": [{"code":"EUR"}]
},
{
"city": "Paris",
"country": "France",
"currencies": [{"code":"EUR"}]
}
]
Generated code:
declare module namespace {
export interface Currency {
code: string;
}
export interface RootObject {
city: string;
country: string;
currencies: Currency[];
}
}
Now you just have to rename the 'RootObject' to a name you like.
Check it out here: http://json2ts.com/
For the case you need c# code try this http://json2csharp.com/. Both services are based on the JSON C# Class Generator.
Thanks to Timmy Kokke and Jonathan Keith for giving that to the community.
Comments
Post a Comment