/ref-replace

Replaces $ref in JSON objects so that they can be stored in Mongo.

Primary LanguageJavaScript

Ref Replace npm version

A module that converts $ref in JSON objects and replaces it with _ref so that it can be stored in Mongo, and vice versa.

I made this module because $ref is a standard in JSON and in Mongo.

Usage

import {replaceRefsJSON, replaceRefsMongo} from 'ref-replace';

const someJSON = {
  $ref: 'test',
  test: {
    $ref: 'test',
    test: {
      $ref: 'test'
    }
  }
};

console.log(replaceRefsJSON(someJSON))
/**
Output:
{
  _ref: 'test',
  test: {
    _ref: 'test',
    test: {
      _ref: 'test'
    }
  }
}
 */

License

MIT © Hugo Müller-Downing