How to use the json-ptr.get function in json-ptr

To help you get started, we’ve selected a few json-ptr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github IBM / report-toolkit / packages / diff / src / index.js View on Github external
) {
                  /**
                   * @type {Array}
                   */
                  const nextPathParts = patchObj.path.split('/');
                  const nextPathIdx = Number(nextPathParts.pop()) + offset;
                  const nextPath = nextPathParts.concat(nextPathIdx).join('/');
                  oldValue = ptr.get(reportA, nextPath);
                  offset++;
                  nextValue = {...patchObj, oldValue, path: nextPath};
                } else {
                  // there's no old value to look up for 'add' operations.
                  if (patchObj.op === 'add') {
                    nextValue = patchObj;
                  } else {
                    oldValue = ptr.get(reportA, patchObj.path);
                    nextValue = {...patchObj, oldValue};
                  }
                  offset = 1;
                }
                lastPatchObj = patchObj;
                observer.next(nextValue);
              }, patch);
            } catch (err) {
github IBM / report-toolkit / packages / diff / src / index.js View on Github external
// is repeated 3 times with the same path. to get the old value--in other words,
                // *what* was removed--we must increment the index at the end of the path
                // and use that to retrieve the value from reportA.
                if (
                  lastPatchObj &&
                  patchObj.op === 'remove' &&
                  patchObj.path === lastPatchObj.path &&
                  patchObj.op === lastPatchObj.op
                ) {
                  /**
                   * @type {Array}
                   */
                  const nextPathParts = patchObj.path.split('/');
                  const nextPathIdx = Number(nextPathParts.pop()) + offset;
                  const nextPath = nextPathParts.concat(nextPathIdx).join('/');
                  oldValue = ptr.get(reportA, nextPath);
                  offset++;
                  nextValue = {...patchObj, oldValue, path: nextPath};
                } else {
                  // there's no old value to look up for 'add' operations.
                  if (patchObj.op === 'add') {
                    nextValue = patchObj;
                  } else {
                    oldValue = ptr.get(reportA, patchObj.path);
                    nextValue = {...patchObj, oldValue};
                  }
                  offset = 1;
                }
                lastPatchObj = patchObj;
                observer.next(nextValue);
              }, patch);
            } catch (err) {
github nodecg / nodecg / lib / replicant / schema-hacks.js View on Github external
function resolvePointerReference(obj, ref) {
	return ptr.get(obj, ref);
}
github boschni / json-merger / src / Processor.ts View on Github external
resolveJsonPointer(target: object, pointer?: string): any {
        let result;

        if (pointer === undefined || pointer === "/") {
            result = target;
        } else {
            result = jsonPtr.get(target, pointer);
        }

        if (result === undefined && this._config.errorOnRefNotFound) {
            throw new Error(`The JSON pointer "${pointer}" resolves to undefined. Set Config.errorOnRefNotFound to false to suppress this message`);
        }

        return result;
    }
github sonnyp / JSON8 / packages / pointer / benchmark.js View on Github external
.add("flitbit/json-ptr get", function() {
    flitbit.get(doc, pointer);
  })
  .add("flitbit/json-ptr compiled", function() {

json-ptr

A complete implementation of JSON Pointer (RFC 6901) for nodejs and modern browsers.

MIT
Latest version published 2 years ago

Package Health Score

65 / 100
Full package analysis