Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
@hyperjump/json-schema
Advanced tools
JSON Schema Validator (JSV) is built on JSON Schema Core.
Supported Versions
JSV is designed to run in a vanilla node.js environment, but has no dependencies on node.js specific libraries so it can be bundled for the browser. No compilers, preprocessors, or bundlers are used.
npm install @hyperjump/json-schema
When in a browser context, JSV is designed to use the browser's fetch
implementation instead of a node.js fetch clone. The Webpack bundler does this
properly without any extra configuration, but if you are using the Rollup
bundler you will need to include the browser: true
option in your Rollup
configuration.
plugins: [
resolve({
browser: true
}),
commonjs()
]
const JsonSchema = require("@hyperjump/json-schema");
// Example: Inline schema
const schemaJson = {
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "http://example.com/schemas/string",
"type": "string"
}
JsonSchema.add(schemaJson);
const schema = await JsonSchema.get("http://example.com/schemas/string");
// Example: Fetch from the web
const schema = await JsonSchema.get("http://example.com/schemas/string");
// Example: Fetch from file
const schema = await JsonSchema.get("file:///path/to/my/schemas/string.schema.json");
// Example: Validate instance
const output = await JsonSchema.validate(schema, "foo");
if (output.valid) {
console.log("Instance is valid :-)");
} else {
console.log("Instance is invalid :-(");
}
// Example: Precompile validator
const isString = await JsonSchema.validate(schema);
const output = isString("foo");
// Example: Specify output format
const output = await JsonSchema.validate(schema, "foo", JsonSchema.VERBOSE);
// Example: Specify meta-validation output format
JsonSchema.setMetaOutputFormat(JsonSchema.FLAG);
add: (schema: object, url?: URI, schemaVersion?: string) => undefined
Load a schema. See JSC - $id and JSC - $schema for more information.
get: (url: URI, contextDoc?: SDoc, recursive: boolean = false) => Promise
Fetch a schema. Schemas can come from an HTTP request, a file, or a schema
that was added with add
.
validate: (schema: SDoc, instance: any, outputFormat: OutputFormat = FLAG) => OutputUnit
Validate an instance against a schema. The function is curried to allow compiling the schema once and applying it to multiple instances. See
setMetaOutputFormat: (outputFormat: OutputFormat = DETAILED) => undefined
Set the output format for meta-validation.
OutputFormat: [FLAG | BASIC | DETAILED | VERBOSE]
JSC - Output for more information on output formats.
This implementation supports all required features of JSON Schema draft 2019-09. The following optional features are not supported yet.
unevaluatedProperties
keywordunevaluatedItems
keywordRun the tests
npm test
Run the tests with a continuous test runner
npm test -- --watch
FAQs
A JSON Schema validator with support for custom keywords, vocabularies, and dialects
The npm package @hyperjump/json-schema receives a total of 38,343 weekly downloads. As such, @hyperjump/json-schema popularity was classified as popular.
We found that @hyperjump/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
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.