Skip to content

litejs/json-util

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@version    2.3.0
@date       2017-04-27
@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

About

JSON Pointer [RFC 6901] and JSON Merge Patch [RFC 7396] implementation

Resources

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

 
 
 

Contributors