json library
A range of utility modules and functions to work with json or js objects.
currently includes
-
json pointer implementation
pointer.get
andpointer.set
, which creates objects on its path andpointer.delete
, to remove a property or item -
json query a json pointer supporting glob-pattern
#/usr/**/*/passphrase
, filters#/input/*?valid:true
and simple regular expressions#/input/{name-.*}/id
-
json relation, a relationship definition and utilities to setup and deconstruct relationships between objects
For an up-to-date documentation refer to corresponding unit tests in */test/unit/
Contents
Installation
bower
bower install json-library
will install bower_components/json-library
, where by default /dist/JsonLibrary.min.js
will be loaded. This includes the complete json-library package, which is exposed to window.JsonLibrary
, if not otherwise required. Additional versions included are
/dist/JsonLibrary.pointer.min.js
exposingwindow.JsonPointer
only/dist/JsonLibrary.query.min.js
exposingwindow.JsonQuery
only/dist/JsonLibrary.base.min.js
exposingwindow.JsonLibrary
, excluding all relation utilities
npm
npm install json-library
you can also directly require separate modules with require("json-libary/pointer")
and
require("json-libary/query")
Usage
For a full API see lib README for an overview and its nested packages for details.
pointer
var pointer = pointer;// get value of data at json pointervar value = pointer; // target// add properties by pointer on datavar object = pointer; // {"a":{"b"}:[{"id":"target"}]}// delete properties or itemsvar object = pointer; // {"a":{"b"}:[]}// join arguments to a valid json pointervar pointerToTarget = pointer; // #/a/b/0/target
For further details check pointer README
query
var query = query;// call on each match of the query's matchesquery;// return all json pointers of query matchesvar matches = query;
For further details and query.get
and query.delete
check
query README.
relationship
A json relationship defines 1:1
, 1:n
or n:n
relationships between models (json values). This utility will work
non-destructibly on objects or may export transformed relation data. This is very useful for building different
relationships based on a single flat hierarchy (normalized data). Furthermore, relationships are useful for
transforming data. Some Details can be found in
relation README