simple resolver for json reference and json pointer


stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
13May 11, 2021Jul 10, 2016Minified + gzip package size for @hn3000/json-ref in KB


JSON Reference tools

Contains some relatively simple tools to parse and resolve JSON Pointer and JSON Reference notation.

A custom fetch implementation must be provided to allow clients to provide different resolution strategies. For most uses a very simple adapter can be used with isomorphic-fetch, allowing operation in both node and browser.

Example code:

import { JsonReferenceProcessor } from '@hn3000/json-ref';

let referenceProcessor = new JsonReferenceProcessor();

let promise = referenceProcessor.expandRef ("./somedata.json#/foo");

promise.then((somedataFoo:any) => {
  // somedata.json#/foo is in somedataFoo

At this point, all referenced files have been loaded so that all references can be resolved without fetching anything.

The object has only been expanded as far as necessary to access the property foo. All further property accesses work through dynamic getters, avoiding any issues with (indirect) cyclic references. Direct cyclic references will currently lead to endless promise resolution, i.e. they will not even crash with a stackoverflow.

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.