Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typescript-json-schema

Package Overview
Dependencies
Maintainers
2
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typescript-json-schema

typescript-json-schema generates JSON Schema files from your Typescript sources

  • 0.65.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
465K
increased by10.61%
Maintainers
2
Weekly downloads
 
Created

What is typescript-json-schema?

The typescript-json-schema npm package is a tool that generates JSON schemas from your TypeScript types. This can be particularly useful for validating JSON data, generating documentation, or ensuring consistency between your TypeScript code and JSON data structures.

What are typescript-json-schema's main functionalities?

Generate JSON Schema from TypeScript Interface

This feature allows you to generate a JSON schema from a TypeScript interface. The code sample demonstrates how to set up the schema generator, specify the TypeScript file, and generate the schema for a specific interface.

const TJS = require('typescript-json-schema');

// Settings for the schema generator
const settings = {
  required: true
};

// Path to the TypeScript file
const files = ["./example.ts"];

// Generate the schema
const program = TJS.getProgramFromFiles(files);
const schema = TJS.generateSchema(program, "MyInterface", settings);

console.log(JSON.stringify(schema, null, 2));

Generate JSON Schema with Custom Settings

This feature allows you to customize the settings for the JSON schema generation. The code sample demonstrates how to use custom settings such as `noExtraProps` and `propOrder` to control the schema generation process.

const TJS = require('typescript-json-schema');

// Custom settings for the schema generator
const settings = {
  required: true,
  noExtraProps: true,
  propOrder: true
};

// Path to the TypeScript file
const files = ["./example.ts"];

// Generate the schema
const program = TJS.getProgramFromFiles(files);
const schema = TJS.generateSchema(program, "MyInterface", settings);

console.log(JSON.stringify(schema, null, 2));

Generate JSON Schema for Multiple Interfaces

This feature allows you to generate JSON schemas for multiple TypeScript interfaces at once. The code sample demonstrates how to specify multiple interfaces and generate their schemas in a single operation.

const TJS = require('typescript-json-schema');

// Settings for the schema generator
const settings = {
  required: true
};

// Path to the TypeScript file
const files = ["./example.ts"];

// Generate the schema
const program = TJS.getProgramFromFiles(files);
const schema = TJS.generateSchema(program, ["MyInterface1", "MyInterface2"], settings);

console.log(JSON.stringify(schema, null, 2));

Other packages similar to typescript-json-schema

Keywords

FAQs

Package last updated on 20 Aug 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