Socket
Book a DemoInstallSign in
Socket

json-refs

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-refs

Various utilities for JSON References (http://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03).

Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
994K
-1.33%
Maintainers
1
Weekly downloads
 
Created
Source

json-refs

Various utilities for JSON References, and JSON Pointers since JSON References are part JSON Pointer.

Project Badges

APIs

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 references

Response

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 string

Response

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 References
  • done {function}: An error-first callback to be called with the fully-resolved object

Response

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 */}}
});

Keywords

json

FAQs

Package last updated on 31 Oct 2014

Did you know?

Socket

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.

Install

Related posts