0.0.2 • Published 3 years ago

json-reference-parser v0.0.2

Weekly downloads
4
License
MIT
Repository
-
Last release
3 years ago

Generic badge Generic badge Generic badge

JSON Reference Parser

This package parses the json and dereferences reference '($ref)' objects inside it

Installation

Run below command

npm install json-reference-parser

Problem

Sometimes JSON may contain $ref that referes to other object inside the JSON,

{
    "theme": {
      "$ref": "#/definitions/themes"
    }
    "definitions": {
        "themes": {
            "color": "blue",
            "material": false
        }
    }
}

Solution

Using this package JSON given in problem statement can be passed to dereference method which would dereference all the references inside it

{
    "theme": {
            "color": "blue",
            "material": false
    }
    "definitions": {
        "themes": {
            "color": "blue",
            "material": false
        }
    }
}

Usage

import * as DereferenceJSON from json-reference-parser
...
var dereferenceObject = new DereferenceJSON();
dereferenceObject.dereference(json)