New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gson-pointer

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gson-pointer

json pointer - failsafe data retrieval on js and json objects

  • 2.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
502
decreased by-46.02%
Maintainers
1
Weekly downloads
 
Created
Source

Json Pointer

Here is a solid json-pointer implementation. The main differences to this implementation are

  • conforms to RFC 6901
  • throws an error when a value is not found / the pointer is invalid
  • additional utilities

This json-pointer implementation will return undefined if the pointer could not be resolved, which allows checks like if (pointer.get(data, "#/path/to/nested/item") {...} instead of if (path && path.to && path.to.nested ....

This library exposes

  • jsonpointer.get
  • jsonpointer.set and
  • jsonpointer.delete

install

npm i gson-pointer

pointer.get

	var data = {
		parent: {
			child: {
				title: "title of child"
			}
		}
	}

	var titleOfChild = pointer.get(data, "#/parent/child/title");
	// "title of child"

pointer.set

set values on an object

	var data = {
		parent: {
			children: [
				{
					title: "title of child"
				}
			]
		}
	};

	pointer.set(data, "#/parent/children/1", {title: "second child"});
	console.log(data.parent.children.length);
	// 2

pointer.delete

delete properties or array items

	pointer.delete(data, "#/parent/arrayOrObject/1");

Helpers

pointer.join

pointer.join joins all arguments to a valid json pointer:

	var key = "child";
	var target = pointer.join("parent", key, "title");
	// "#/parent/child/title"

Keywords

FAQs

Package last updated on 27 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc