Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
json-schema-resolver
Advanced tools
The json-schema-resolver npm package is designed to resolve JSON schema references, allowing you to dereference $ref pointers within your JSON schemas. This is particularly useful for validating complex JSON structures that reference other schemas.
Resolving JSON Schema References
This feature allows you to resolve $ref pointers within a JSON schema. The code sample demonstrates how to use the json-schema-resolver package to dereference a schema that includes a reference to another schema.
const resolver = require('json-schema-resolver');
const schema = {
"$id": "http://example.com/root.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"name": {
"$ref": "http://example.com/name.json"
}
}
};
const resolvedSchema = resolver.resolve(schema);
console.log(JSON.stringify(resolvedSchema, null, 2));
json-schema-ref-parser is a powerful library for parsing, resolving, and dereferencing JSON schema $ref pointers. It offers similar functionality to json-schema-resolver but includes additional features like bundling and dereferencing schemas with circular references.
json-schema-deref-sync is a synchronous library for dereferencing JSON schema $ref pointers. It is similar to json-schema-resolver but operates synchronously, making it suitable for use cases where asynchronous operations are not desired.
json-schema-deref is another library for dereferencing JSON schema $ref pointers. It provides similar functionality to json-schema-resolver but focuses on simplicity and ease of use.
Resolve all $refs
in your JSON schema!
npm install json-schema-resolver
This plugin support Node.js >= 10
const RefResolver = require('json-schema-resolver')
const ref = RefResolver({
clone: true // Clone the input schema without changing it. Default: false
})
const inputSchema = {
$id: 'http://example.com/SimplePerson',
type: 'object',
properties: {
name: { type: 'string' },
address: { $ref: 'relativeAddress#' },
houses: { type: 'array', items: { $ref: 'relativeAddress#' } }
}
}
const addresSchema = {
$id: 'relativeAddress', // Note: prefer always absolute URI like: http://mysite.com
type: 'object',
properties: {
zip: { type: 'string' },
city: { type: 'string' }
}
}
const singleSchema = ref.resolve(inputSchema, { externalSchemas: [addresSchema] })
// mySchema is untouched thanks to clone:true
singleSchema
will be like:
{
"$id": "http://example.com/SimplePerson",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"address": {
"$ref": "#/definitions/def-0"
},
"houses": {
"type": "array",
"items": {
"$ref": "#/definitions/def-0"
}
}
},
"definitions": {
"def-0": {
"$id": "relativeAddress",
"type": "object",
"properties": {
"zip": {
"type": "string"
},
"city": {
"type": "string"
}
}
}
}
}
Licensed under MIT.
FAQs
Resolve all your $refs
The npm package json-schema-resolver receives a total of 288,646 weekly downloads. As such, json-schema-resolver popularity was classified as popular.
We found that json-schema-resolver demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.