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

json-schema-to-ts

Package Overview
Dependencies
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-schema-to-ts

Infer typescript types from your JSON schemas!

  • 3.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.4M
increased by0.71%
Maintainers
1
Weekly downloads
 
Created

What is json-schema-to-ts?

The json-schema-to-ts npm package is a utility that converts JSON Schema definitions into TypeScript types. This allows developers to ensure type safety and consistency between their JSON data and TypeScript code.

What are json-schema-to-ts's main functionalities?

Convert JSON Schema to TypeScript Types

This feature allows you to convert a JSON Schema into a TypeScript type. The `FromSchema` utility type takes a JSON Schema object and infers the corresponding TypeScript type.

import { FromSchema } from 'json-schema-to-ts';

const userSchema = {
  type: 'object',
  properties: {
    id: { type: 'string' },
    name: { type: 'string' },
    age: { type: 'number' }
  },
  required: ['id', 'name']
} as const;

type User = FromSchema<typeof userSchema>;

const user: User = {
  id: '123',
  name: 'John Doe',
  age: 30
};

Type Validation

This feature ensures that the TypeScript types derived from JSON Schema are validated at compile time, reducing runtime errors and improving code reliability.

import { FromSchema } from 'json-schema-to-ts';

const productSchema = {
  type: 'object',
  properties: {
    productId: { type: 'string' },
    price: { type: 'number' }
  },
  required: ['productId', 'price']
} as const;

type Product = FromSchema<typeof productSchema>;

const product: Product = {
  productId: 'abc123',
  price: 19.99
};

Other packages similar to json-schema-to-ts

Keywords

FAQs

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