What is json-refs?
The json-refs npm package is a utility for working with JSON references, which are pointers within JSON objects that reference other parts of the JSON document. It helps resolve these references and can be used to make JSON documents easier to understand and manipulate by consolidating linked data.
What are json-refs's main functionalities?
Resolving JSON References
This feature allows the resolution of JSON references within a JSON document. The code sample demonstrates how to resolve references in a JSON file located at a specified path, with an option to resolve circular references.
{
"jsonRefs": require('json-refs'),
"path": './somePath/to/json',
"options": { resolveCirculars: true },
"resolvedJson": function() {
var root = jsonRefs.resolveRefsAt(this.path, this.options).then(function (results) {
console.log(results.resolved);
}).catch(function (err) {
console.error(err.stack);
});
return root;
}
}
Finding JSON References
This feature involves identifying all the JSON references in a given JSON object. The code sample shows how to find all references, including those that might be invalid, within a JSON object.
{
"jsonRefs": require('json-refs'),
"jsonObject": { /* some JSON object */ },
"options": { includeInvalid: true },
"foundRefs": function() {
var refs = jsonRefs.findRefs(this.jsonObject, this.options);
console.log(refs);
return refs;
}
}
Other packages similar to json-refs
swagger-parser
Swagger Parser is a package that can parse, validate, and dereference Swagger and OpenAPI documents. Similar to json-refs, it handles resolving references but is specifically tailored for Swagger and OpenAPI specs, providing more specialized functionality in these contexts compared to the more general-purpose json-refs.
json-schema-ref-parser
This package dereferences JSON Schema $refs pointers. Like json-refs, it resolves references within JSON documents but focuses specifically on JSON Schema, making it ideal for scenarios involving JSON Schema validation and manipulation.
json-refs
json-refs is a simple library for interacting with JSON References and
JSON Pointers. While the main purpose of this library is to provide JSON References features,
since JSON References are a combination of Object
structure and a JSON Pointer
, this library also provides some
features for JSON Pointers as well.
Project Badges
- Build status:
- Dependencies:
- Developer dependencies:
- Downloads:
- Gitter:
- License:
- Version:
Documentation
The documentation for this project can be found at https://github.com/whitlockjc/json-refs/blob/master/docs/README.md.
Specific documentation can be found here:
Installation
json-refs is available for both Node.js and the browser. Installation instructions for each environment are below.
Browser
json-refs binaries for the browser are available in the dist/
directory:
Of course, these links are for the master builds so feel free to download from the release of your choice. Once you've
gotten them downloaded, to use the standalone binaries, your HTML include might look like this:
<script src="json-refs.js"></script>
Node.js
Installation for Node.js applications can be done via NPM.
npm install json-refs --save
If you plan on using the json-refs
CLI executable, you can install json-refs globally like this:
npm install json-refs --global
After this, feel free to run json-refs help
to see what you can do or view the CLI documentation linked above