JSON Pointer [RFC 6901] and JSON Merge Patch [RFC 7396] implementation
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
dist v2.2.0 Jul 14, 2016
tests Expose isObject Jul 14, 2016
.gitignore Add files to package.json Feb 28, 2015
.travis.yml Update node version in travis config Nov 8, 2015
README.md
index.js v2.2.0 Jul 14, 2016
package.json v2.2.0 Jul 14, 2016

README.md

@version    2.2.0
@date       2016-07-14
@stability  3 - Stable

JSON util – Build Coverage

JSON Pointer RFC 6901 and JSON Merge Patch RFC 7396 implementation. The main goal is to have a small and reasonably fast code.

When used directly with script tag, methods are added to global JSON object.

When used with require, methods are exported as expected.

Examples

var util = require("json-util")
, obj = {"a": {"b": 1}}

// get a value
var b = util.pointer(obj, "/a/b")
// b is 1

// set a value
var oldValue = util.pointer(obj, "/a/b", 2) // sets value to 2
// oldValue is 1

// adding to a nonexistent target will create missing object literals
util.pointer(obj, "/a/c/d/e", "3")
// obj is now {"a": {"b": 2, "c": {"d": {"e": "3"}}}}

// apply a patch and collect JSON Pointers to array that were changed
var changed = []
util.mergePatch(obj, {"a": {"c": "C"}}, changed /* optional */)
// obj is now {"a": {"b": 2, "c": "C"}}
// changed = ["/a", "/a/c"]

// test is it a object literal
json.isObject(obj)
// true

Coding Style Guidelines

  • Use tabs for indentation, align with spaces
  • Use lowerCamelCase for method and variable names
  • Use UpperCamelCase for constructor names
  • Commit files with Unix-style line endings
  • Do not use spaces in file and directory names Consider substituting a dash (-) where you would normally use spaces.
  • Rebase before pushing
  • Fix tests before push or pull request

External links

Licence

Copyright (c) 2014-2016 Lauri Rooden <lauri@rooden.ee>
The MIT License