quicktype
quicktype copied to clipboard
[Feature request] TypeScript: allow to use already parsed JSON
Currently quicktype generates converter function in the following form:
public static toMyClass(json: string): MyClass {
return cast(JSON.parse(json), r("MyClass"));
}
If I already have a JSON object from somewhere I have no way to cast it to MyClass.
I have to use toMyClass(JSON.stringify(alreadyParsedObject)), which is a bit ridiculous.
It would be nice to have a function like this:
public static castToMyClass(json: any): MyClass {
return cast(json, r("MyClass"));
}
Try --raw-type any flag
generated code:
// Converts JSON types to/from your types
// and asserts the results at runtime
export class Convert {
public static toMockEventSchema(json: any): MockEventSchema {
return cast(json, r("MockEventSchema"));
}
}