
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Various utilities for JSON References (http://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03).
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.
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;
}
}
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.
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.
Various utilities for JSON References, and JSON Pointers since JSON References are part JSON Pointer.
All examples below use a variable called jsonRefs
. Here is how to create it:
var jsRefs = require('jsonRefs');
findRefs (json)
Arguments
json {object}
- The JavaScript object to search for referencesResponse
An object
whose keys are JSON Pointers to where the JSON Reference's $ref
node is and the JSON Reference string
.
pathFromPointer (ptr)
Arguments
ptr {string}
- A JSON Pointer stringResponse
A string[]
of path segments for the JSON Pointer unless its a remote reference in which case ptr
is returned as-is.
Example
console.log(jsonRefs.pathFromPointer('#/owner/login')); // ['owner', 'login']
pathToPointer (path)
Arguments
path {string[]}
- An array of path segments.Response
A string
representing a JSON Pointer.
Example
console.log(jsonRefs.pathToPointer(['owner', 'login'])); // #/owner/login
resolveRefs (json, done)
Arguments
json {object}
: The JavaScript object containing zero or more JSON Referencesdone {function}
: An error-first callback to be called with the fully-resolved objectResponse
If there is an Error
, the callback is called with the Error
in the first argument and undefined
in the second
argument. If there is no Error
, the first argument is undefined
and the second argument is an object
whose value
is the fully resolved document.
Example
var json = {
name: 'json-refs',
owner: {
$ref: 'https://api.github.com/repos/whitlockjc/json-refs#/owner'
}
};
jsonRefs.resolveRefs(json, function (err, rJson) {
if (err) throw err;
console.log(JSON.stringify(rJson)); // {name: 'json-refs', owner: {/* GitHub Repository Owner Information */}}
});
FAQs
Various utilities for JSON References (http://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03).
The npm package json-refs receives a total of 954,990 weekly downloads. As such, json-refs popularity was classified as popular.
We found that json-refs 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.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.