
Company News
Socket Joins New OpenJS Program to Fund Node.js Security Work
Socket is joining the OpenJS Security Stewardship Program to fund Node.js vulnerability research, maintainer remediation, and security releases.
@apidevtools/json-schema-ref-parser
Advanced tools
Parse, Resolve, and Dereference JSON Schema $ref pointers
Install using npm:
npm install @apidevtools/json-schema-ref-parser
pnpm add @apidevtools/json-schema-ref-parser
bun add @apidevtools/json-schema-ref-parser
You've got a JSON Schema with $ref pointers to other files and/or URLs. Maybe you know all the referenced files ahead
of time. Maybe you don't. Maybe some are local files, and others are remote URLs. Maybe they are a mix of JSON and YAML
format. Maybe some of the files contain cross-references to each other.
{
"definitions": {
"person": {
"$ref": "schemas/people/Bruce-Wayne.json"
},
"place": {
"$ref": "schemas/places.yaml#/definitions/Gotham-City"
},
"thing": {
"$ref": "http://wayne-enterprises.com/things/batmobile"
},
"color": {
"$ref": "#/definitions/thing/properties/colors/black-as-the-night"
}
}
}
JSON Schema $Ref Parser is a full JSON Reference and JSON Pointer implementation that crawls even the most complex JSON Schemas and gives you simple, straightforward JavaScript objects.
$ref pointers to external files and URLs, as well
as custom sources such as databases$ref pointers$ref pointers to the same value always resolve to the same object
instanceimport $RefParser from "@apidevtools/json-schema-ref-parser";
try {
await $RefParser.dereference(mySchema);
// note - by default, mySchema is modified in place, and the returned value is a reference to the same object
console.log(mySchema.definitions.person.properties.firstName);
// if you want to avoid modifying the original schema, you can disable the `mutateInputSchema` option
let clonedSchema = await $RefParser.dereference(mySchema, { mutateInputSchema: false });
console.log(clonedSchema.definitions.person.properties.firstName);
} catch (err) {
console.error(err);
}
For more detailed examples, please see the API Documentation
If you are using Node.js < 18, you'll need a polyfill for fetch,
like node-fetch:
import fetch from "node-fetch";
globalThis.fetch = fetch;
JSON Schema $Ref Parser supports recent versions of every major web browser. Older browsers may require Babel and/or polyfills.
To use JSON Schema $Ref Parser in a browser, you'll need to use a bundling tool such
as Webpack, Rollup, Parcel,
or Browserify. Some bundlers may require a bit of configuration, such as
setting browser: true in rollup-plugin-resolve.
Webpack 5 has dropped the default export of node core modules in favour of polyfills, you'll need to set them up
yourself ( after npm-installing them )
Edit your webpack.config.js :
config.resolve.fallback = {
path: require.resolve("path-browserify"),
fs: require.resolve("browserify-fs"),
};
config.plugins.push(
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
}),
);
Full API documentation is available right here
I welcome any contributions, enhancements, and bug-fixes. Open an issue on GitHub and submit a pull request.
To build/test the project locally on your computer:
Clone this repo
git clone https://github.com/APIDevTools/json-schema-ref-parser.git
Install dependencies
pnpm install
Run the tests
pnpm test
JSON Schema $Ref Parser is 100% free and open-source, under the MIT license. Use it however you want.
Thanks to these awesome contributors for their major support of this open-source project.
Similar to @apidevtools/json-schema-ref-parser, this package focuses on resolving $ref pointers within JSON Schemas. However, it might not offer the same level of functionality for bundling schemas into a single file or the same breadth of dereferencing options.
jsonref is another package that offers functionality to resolve $ref pointers in JSON objects, including JSON Schemas. It provides a simpler interface but may not have as comprehensive support for complex schemas or the ability to bundle schemas as @apidevtools/json-schema-ref-parser does.
FAQs
Parse, Resolve, and Dereference JSON Schema $ref pointers
The npm package @apidevtools/json-schema-ref-parser receives a total of 12,144,183 weekly downloads. As such, @apidevtools/json-schema-ref-parser popularity was classified as popular.
We found that @apidevtools/json-schema-ref-parser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.

Company News
Socket is joining the OpenJS Security Stewardship Program to fund Node.js vulnerability research, maintainer remediation, and security releases.

Security News
Two compromised GitHub Actions were re-enabled with malicious tags intact, exposing thousands of downstream repositories to Mini Shai-Hulud.

Research
/Security News
A malicious Firefox extension fetches its payload after installation to evade detection, steal Google session cookies, and automate account takeover.