Socket
Book a DemoInstallSign in
Socket

json-schema-deref-local

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-schema-deref-local

Simple JSON Schema local dereferencer

0.2.1
latest
Source
npmnpm
Version published
Weekly downloads
111
94.74%
Maintainers
1
Weekly downloads
 
Created
Source

json-schema-deref-local

Dereference local JSON pointers in a JSON schema with their true resolved values. Basically a lighter, local-only version of json-schema-deref-sync but omits web references, file references, and custom loaders.

Why?

This local-only fork removes the dependency on the Node.js fs module, allowing it to be used either in Node.js or in a web browser.

Installation

npm install SeedScientific/json-schema-deref-local

Overview

Let's say you have the following JSON Schema:

{
  "description": "Just some JSON schema.",
  "title": "Basic Widget",
  "type": "object",
  "definitions": {
    "id": {
      "description": "unique identifier",
      "type": "string",
      "minLength": 1,
      "readOnly": true
    }
  },
  "properties": {
    "id": {
      "$ref": "#/definitions/id"
    }
  }
}

Sometimes you just want that schema to be fully expanded, with $refs being their (true) resolved values:

{
  "description": "Just some JSON schema.",
  "title": "Basic Widget",
  "type": "object",
  "definitions": {
    "id": {
      "description": "unique identifier",
      "type": "string",
      "minLength": 1,
      "readOnly": true
    }
  },
  "properties": {
    "id": {
      "description": "unique identifier",
      "type": "string",
      "minLength": 1,
      "readOnly": true
    }
  }
}

This utility lets you do that:

var deref = require('json-schema-deref-local');
var myschema = require('schema.json');

var fullSchema = deref(myschema);

API

deref(schema, options)

Dereferences $ref's in json schema to actual resolved values. Supports local refs only (ie. refs starting with '#' referring to definitions in the same schema file).

Parameters:

schema

The input JSON schema

deref.getRefPathValue(schema, refPath)

Gets the "local" ref value given the path.

schema - the (root) json schema to search

refPath - string ref path to get within the schema. Ex. #/definitions/id

var localValue = deref.getRefPathValue(myschema, '#/definitions/foo');
console.dir(localValue);

Keywords

json

FAQs

Package last updated on 18 Jun 2015

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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.