
Security News
Open Source Maintainers Demand Ability to Block Copilot-Generated Issues and PRs
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
quicktype-core
Advanced tools
The quicktype-core npm package is a powerful tool for generating type-safe code from JSON, GraphQL, and other data formats. It helps developers quickly create models and types in various programming languages, ensuring that the data structures are correctly typed and reducing the likelihood of runtime errors.
Generate TypeScript Interfaces from JSON
This feature allows you to generate TypeScript interfaces from a given JSON string. It ensures that the JSON data is correctly typed in TypeScript, making it easier to work with the data in a type-safe manner.
const quicktype = require('quicktype-core');
const { InputData, JSONInput, quicktypeJSON } = quicktype;
async function generateTypeScript(jsonString) {
const jsonInput = new JSONInput(new quicktype.JSONSchemaStore());
await jsonInput.addSource({ name: 'MyType', samples: [jsonString] });
const inputData = new InputData();
inputData.addInput(jsonInput);
const result = await quicktypeJSON({
inputData,
lang: 'ts'
});
return result.lines.join('\n');
}
const jsonString = '{ "name": "John", "age": 30 }';
generateTypeScript(jsonString).then(console.log);
Generate C# Classes from JSON
This feature allows you to generate C# classes from a given JSON string. It ensures that the JSON data is correctly typed in C#, making it easier to work with the data in a type-safe manner.
const quicktype = require('quicktype-core');
const { InputData, JSONInput, quicktypeJSON } = quicktype;
async function generateCSharp(jsonString) {
const jsonInput = new JSONInput(new quicktype.JSONSchemaStore());
await jsonInput.addSource({ name: 'MyType', samples: [jsonString] });
const inputData = new InputData();
inputData.addInput(jsonInput);
const result = await quicktypeJSON({
inputData,
lang: 'csharp'
});
return result.lines.join('\n');
}
const jsonString = '{ "name": "John", "age": 30 }';
generateCSharp(jsonString).then(console.log);
Generate JSON Schema from TypeScript Interfaces
This feature allows you to generate JSON Schema from TypeScript interfaces. It ensures that the TypeScript data structures are correctly represented in JSON Schema, making it easier to validate JSON data against the schema.
const quicktype = require('quicktype-core');
const { InputData, TypeScriptInput, quicktypeJSON } = quicktype;
async function generateJSONSchema(tsString) {
const tsInput = new TypeScriptInput(new quicktype.JSONSchemaStore());
await tsInput.addSource({ name: 'MyType', samples: [tsString] });
const inputData = new InputData();
inputData.addInput(tsInput);
const result = await quicktypeJSON({
inputData,
lang: 'schema'
});
return result.lines.join('\n');
}
const tsString = 'interface MyType { name: string; age: number; }';
generateJSONSchema(tsString).then(console.log);
The json-schema-to-typescript package converts JSON Schemas to TypeScript interfaces. It is similar to quicktype-core in that it helps generate type-safe code, but it focuses specifically on JSON Schema to TypeScript conversion.
The typescript-json-schema package generates JSON Schema from your TypeScript sources. It is similar to quicktype-core in that it helps create JSON Schemas from TypeScript, but it does not support as many languages or input formats as quicktype-core.
The swagger-typescript-api package generates TypeScript API client code from Swagger/OpenAPI definitions. It is similar to quicktype-core in that it generates type-safe TypeScript code, but it focuses specifically on API client generation from Swagger/OpenAPI definitions.
FAQs
The quicktype engine as a library
The npm package quicktype-core receives a total of 168,142 weekly downloads. As such, quicktype-core popularity was classified as popular.
We found that quicktype-core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
Research
Security News
Malicious Koishi plugin silently exfiltrates messages with hex strings to a hardcoded QQ account, exposing secrets in chatbots across platforms.
Research
Security News
Malicious PyPI checkers validate stolen emails against TikTok and Instagram APIs, enabling targeted account attacks and dark web credential sales.