Socket
Socket
Sign inDemoInstall

json-pointer

Package Overview
Dependencies
1
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    json-pointer

Some utilities for JSON pointers described by RFC 6901


Version published
Weekly downloads
1.2M
increased by0.52%
Maintainers
1
Install size
22.1 kB
Created
Weekly downloads
 

Readme

Source

json-pointer

Build Status

Some utilities for JSON pointers described by RFC 6901

Provides some additional stuff i needed but is not included in node-jsonpointer

Installation

node.js

$ npm install json-pointer

component

$ component install manuelstofer/json-pointer

API

var pointer = require('json-pointer');

pointer(object, [pointer, [value]])

Convenience wrapper around the api.

Calls .get when called with an object and a pointer. Calls .set when also called with value. If only supplied object, returns a partially applied function, mapped to the object.

var obj = {
    existing: 'bla'
};

pointer(obj, '/new-value/bla', 'expected'); // .set a property
var objPointer = pointer(obj); // all api calls are now scoped to `obj`
objPointer('/existing') // gets '/existing' from `obj`
objPointer('/new-value/bla') // gets '/new-value/bla' from `obj`

.get(object, pointer)

Looks up a json pointer in an object

var obj = {
    example: {
        bla: 'hello'
    }
};
pointer.get(obj, '/example/bla');

.set(object, pointer, value)

Sets a new value on object at the location described by pointer

var obj = {};
pointer.set(obj, '/example/bla', 'hello');

.dict(object)

Creates a dictionary object (pointer -> value)

var obj = {
    hello: {bla: 'example'}
};
pointer.dict(obj);

// Returns:
// {
//    '/hello/bla': 'example'
// }

.walk(object, iterator)

Just like:

each(pointer.dict(obj), iterator);

.has(object, pointer)

Tests if an object has a value for a json pointer

var obj = {
    bla: 'hello'
};

pointer.has(obj, '/bla');               // -> true
pointer.has(obj, '/non/existing');      // -> false

.escape(str)

Escapes a reference token

pointer.escape('hello~bla');            // -> 'hello~0bla'
pointer.escape('hello/bla');            // -> 'hello~1bla'

.unescape(str)

Unescape a reference token

pointer.unescape('hello~0bla');         // -> 'hello~bla'
pointer.unescape('hello~1bla');         // -> 'hello/bla'

.parse(str)

Converts a json pointer into a array of reference tokens

pointer.parse('/hello/bla');            // -> ['hello', 'bla']

.compile(str)

Builds a json pointer from a array of reference tokens

pointer.compile(['hello', 'bla']);      // -> '/hello/bla'

FAQs

Last updated on 07 Apr 2013

Did you know?

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc