@jsonjoy.com/json-pointer
High-performance JSON Pointer implementation
Last updated 9 months ago by streamich .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @jsonjoy.com/json-pointer 
SYNC missed versions from official npm registry.

JSON Pointer - json-pointer

Fast implementation of JSON Pointer (RFC 6901) specification in TypeScript.

Usage

Can find a value in a JSON object using three methods: (1) JSON Pointer string, (2) array of steps, or (3) a pre-compiled function.

Examples

Find the value in a JSON document at some specific location.

Find by JSON Pointer string

import { findByPointer } from '@jsonjoy.com/json-pointer';

const doc = {
  foo: {
    bar: 123,
  },
};

const res = findByPointer(doc, '/foo/bar');

Find by path array

Alternatively, you can specify an array of steps, such as ['foo', 'bar']. Or, use the parseJsonPointer function to convert a JSON Pointer string to an array.

import { find, parseJsonPointer } from '@jsonjoy.com/json-pointer';

const doc = {
  foo: {
    bar: 123,
  },
};

const path = parseJsonPointer('/foo/bar');
const ref = find(doc, path);

console.log(ref);
// { val: 123, obj: { bar: 123 }, key: 'bar' }

Pre-compiled function

If you know the path in advance, you can compile a function that will find the value at that location, it will work few times faster than the previous methods.

import { $$find } from '@jsonjoy.com/json-pointer/lib/codegen';

const doc = {
  foo: {
    bar: 123,
  },
};
const finder = $$find(['foo', 'bar']);

const res = finder(doc);

Low-level API

Convert JSON Pointer to path array and back.

import { parseJsonPointer } from '@jsonjoy.com/json-pointer';

console.log(parseJsonPointer('/f~0o~1o/bar/1/baz'));
// [ 'f~o/o', 'bar', '1', 'baz' ]

console.log(formatJsonPointer(['f~o/o', 'bar', '1', 'baz']));
// /f~0o~1o/bar/1/baz

Decode and encode a single step of JSON Pointer.

console.log(unescapeComponent('~0~1'));
// ~/

console.log(escapeComponent('~/'));
// ~0~1

Current Tags

  • 18.8.0                                ...           latest (4 days ago)

18 Versions

  • 18.8.0                                ...           4 days ago
  • 18.7.0                                ...           5 days ago
  • 18.6.0                                ...           7 days ago
  • 18.5.0                                ...           8 days ago
  • 18.1.0                                ...           21 days ago
  • 18.0.0                                ...           2 months ago
  • 17.67.0                                ...           2 months ago
  • 17.65.0                                ...           4 months ago
  • 17.64.0                                ...           4 months ago
  • 17.63.0                                ...           5 months ago
  • 17.62.0                                ...           5 months ago
  • 17.61.1                                ...           6 months ago
  • 17.61.0                                ...           6 months ago
  • 17.60.0                                ...           6 months ago
  • 17.59.0                                ...           6 months ago
  • 1.0.2                                ...           8 months ago
  • 1.0.1                                ...           9 months ago
  • 1.0.0                                ...           2 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (8)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |