Converting JSON into typesafe code for any language using QuickType-Core in Angular
QuickType-Core
infers types from sample data (JSON, JSON Shema, TypeScript), then outputs typed code in your desired programming language
3 min readAug 9, 2020
Hi there In this tutorial, I am going to explain how to use QuickType-Core package and convert JSON into C# Class(types) in Angular
To achieve this feat we need QuickType-Core package installed in our Angular application, do that using the NPM CLI with the following command
npm i quicktype-core
Now let’s do the stuff, create a component and put this method in it, this method converts JSON into a specified language. We should pass Target Language, Class name in the target language and JSON string to this method.
async quicktypeJSON(targetLanguage: string | TargetLanguage, className: string, jsonString)
{
const jsonInput = jsonInputForTargetLanguage(targetLanguage);
await jsonInput.addSource({
name: className,
samples: [jsonString],
});
const inputData = new InputData();
inputData.addInput(jsonInput);
return await quicktype({
inputData,
lang: targetLanguage,
});
}