npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

json-library

v2.0.4

Published

Mothership of json-pointer, json-query and json-relationship

Downloads

19

Readme

json library

A range of utility modules and functions to work with json or js objects.

currently includes

  • json pointer implementation pointer.get and pointer.set, which creates objects on its path and pointer.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 exposing window.JsonPointer only
  • /dist/JsonLibrary.query.min.js exposing window.JsonQuery only
  • /dist/JsonLibrary.base.min.js exposing window.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 = require("json-library").pointer;
// get value of data at json pointer
var value = pointer.get({"a":{"b"}:[{"id":"target"}]}, "#/a/b/0/id"); // target
// add properties by pointer on data
var object = pointer.set({}, "#/a/b/[0]/id", "target"); // {"a":{"b"}:[{"id":"target"}]}
// delete properties or items
var object = pointer.delete({"a":{"b"}:[{"id":"target"}]}, "#/a/b/0"); // {"a":{"b"}:[]}
// join arguments to a valid json pointer
var pointerToTarget = pointer.join("#/a", "#/b", "/0/", "target"); // #/a/b/0/target

For further details check pointer README

query

var query = require("json-library").query;
// call on each match of the query's matches
query.run(data,
	"#/pointer/{regex.*}/**/*?property:hasValue||property:otherValue",
	function (value, key, parentObject, jsonPointer) {
	});
// return all json pointers of query matches
var matches = query.run(data,
	"#/pointer/{^regex.*}/**/*?property:hasValue||property:otherValue",
	query.get.POINTER
);

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