Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
@types/json-schema
Advanced tools
The @types/json-schema package provides TypeScript type definitions for JSON Schema. It allows developers to use JSON Schema in TypeScript projects with type checking, enabling them to define valid JSON structures more accurately and with the benefits of autocompletion and compile-time validation. This package does not include functionality to validate JSON data against schemas but rather provides types to assist in writing code that can create, manipulate, or understand JSON Schemas.
Defining a JSON Schema
This code sample demonstrates how to define a simple JSON Schema for an object with required 'name' (string) and 'age' (number) properties using TypeScript. The @types/json-schema package provides types that make it easier to define such schemas with the benefits of type checking.
{"$schema": "http://json-schema.org/draft-07/schema#","type": "object","properties": {"name": {"type": "string"},"age": {"type": "number"}},"required": ["name", "age"]}
Using JSON Schema with TypeScript interfaces
This example shows how to define a TypeScript interface and a corresponding JSON Schema. The @types/json-schema package allows the use of JSONSchema7 (or other version-specific types) to ensure the schema definition is type-safe.
interface Person {name: string; age: number;}; const personSchema: JSONSchema7 = {type: 'object', properties: {name: {type: 'string'}, age: {type: 'number'}}, required: ['name', 'age']};
Ajv is a JSON schema validator that compiles schemas to functions and validates data against them. It is significantly different from @types/json-schema as Ajv focuses on validation rather than providing TypeScript types. However, it supports JSON Schema draft-06/07/2019-09 and can be used alongside type definitions for runtime validation.
The jsonschema package is a JSON Schema validator that can validate JavaScript objects using JSON Schemas. Unlike @types/json-schema, which provides TypeScript types for schema definitions, jsonschema focuses on the validation aspect, checking if objects match the schemas.
npm install --save @types/json-schema
This package contains type definitions for json-schema 4.0, 6.0 and (https://github.com/kriszyp/json-schema).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/json-schema.
These definitions were written by Boris Cherny, Cyrille Tuzi, Lucian Buzzo, Roland Groza, and Jason Kwok.
FAQs
TypeScript definitions for json-schema
The npm package @types/json-schema receives a total of 21,393,891 weekly downloads. As such, @types/json-schema popularity was classified as popular.
We found that @types/json-schema demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.