Socket
Socket
Sign inDemoInstall

quicktype-core

Package Overview
Dependencies
Maintainers
2
Versions
453
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

quicktype-core

The quicktype engine as a library


Version published
Weekly downloads
164K
increased by2.66%
Maintainers
2
Weekly downloads
 
Created

What is quicktype-core?

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.

What are quicktype-core's main functionalities?

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);

Other packages similar to quicktype-core

FAQs

Package last updated on 31 May 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc