json-refs is a JavaScript library providing comprehensive utilities for interacting with JSON References (based on draft-pbryan-zyp-json-ref-03) and JSON Pointers (RFC6901). Its primary function is to resolve references within JSON documents, making it highly valuable for managing complex data structures such as OpenAPI/Swagger definitions, JSON Schemas, or any document with interlinked parts. The current stable version is 3.0.15. While a strict release cadence is not explicitly defined, the project shows active maintenance, including significant breaking changes in v3.0.0 and critical security patches in v2.1.7. A key differentiator is its dual focus on both JSON Reference and JSON Pointer specifications, offering robust solutions for Node.js and browser environments, complete with TypeScript type definitions.
npm install json-refsVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to resolve JSON References within a document, including local, relative, and external references.
Replace `options.relativeBase` with `options.location` in your configuration objects, providing the URI of the document being resolved.
If you require full resolution of circular references, set `options.resolveCirculars` to `true`. Otherwise, review your handling of circular structures to account for the new default behavior.
Upgrade to `json-refs@2.1.7` or newer immediately to mitigate these security risks. All dependencies were updated in this release to address the vulnerabilities.
For TypeScript or modern JavaScript with transpilation, use `import jsonRefs from 'json-refs';`. For pure CommonJS, use `const jsonRefs = require('json-refs');`. Do not use named imports like `import { resolveRefs } from 'json-refs';`.Verify the JSON Pointer path within the reference. Ensure all external files or URLs are accessible. If using relative paths, set `options.location` to the base URI of the document containing the reference. Remember `options.relativeBase` was removed in v3.0.0.
Explicitly set `options.resolveCirculars: true` if you intend to fully resolve all circular references, but be cautious of potential performance or output size issues. Otherwise, understand that circular paths might not be fully resolved by default.