Giter Site home page Giter Site logo

json-pointer's Introduction

JSON Pointer

This is an implementation of RFC-6901 JSON Pointer. JSON Pointer is designed for referring to data values within a JSON document. It's designed to be URL friendly so it can be used as a URL fragment that points to a specific part of the JSON document.

Installation

npm install @hyperjump/json-pointer

Usage

const JsonPointer = require("@hyperjump/json-pointer");

const value = {
  "foo": {
    "bar": 42
  }
};

// Construct pointers
const fooPointer = JsonPointer.append(JsonPointer.nil, "foo"); // "/foo"
const fooBarPointer = JsonPointer.append(fooPointer, "bar"); // "/foo/bar"

// Get a value from a pointer
const getFooBar = JsonPointer.get(fooBarPointer);
getFooBar(value); // 42

// Set a value from a pointer
// New value is returned without modifying the original
const setFooBar = JsonPointer.set(fooBarPointer);
setFooBar(value, 33); // { "foo": { "bar": 33 } }

// Assign a value from a pointer
// The original value is changed and no value is returned
const assignFooBar = JsonPointer.assign(fooBarPointer);
assignFooBar(value, 33); // { "foo": { "bar": 33 } }

// Unset a value from a pointer
// New value is returned without modifying the original
const unsetFooBar = JsonPointer.unset(fooBarPointer);
setFooBar(value); // { "foo": {} }

// Delete a value from a pointer
// The original value is changed and no value is returned
const deleteFooBar = JsonPointer.delete(fooBarPointer);
setFooBar(value); // { "foo": {} }

Contributing

Tests

Run the tests

npm test

Run the tests with a continuous test runner

npm test -- --watch

json-pointer's People

Contributors

jdesrosiers avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.