# jsonpointer.js

> JavaScript implementation of JSON Pointer

Latest version **0.4.0** (published 2014-06-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install jsonpointer.js
pnpm add jsonpointer.js
yarn add jsonpointer.js
bun add jsonpointer.js
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2014-06-24 |
| First published | 2013-04-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Alexey Kuzmin |
| Maintainers | alexeykuzmin |
| Keywords | jsonpointer, json |

## Links

- npm: https://www.npmjs.com/package/jsonpointer.js
- Repository: https://github.com/alexeykuzmin/jsonpointer.js
- Issues: https://github.com/alexeykuzmin/jsonpointer.js/issues
- npm.io page: https://npm.io/package/jsonpointer.js

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.4.0 (latest) — 2014-06-24
- 0.3.0 — 2013-06-15
- 0.2.1 — 2013-04-20
- 0.2.0 — 2013-04-19
- 0.1.3 — 2013-04-15
- 0.1.2 — 2013-04-13
- 0.1.1 — 2013-04-13
- 0.1.0 — 2013-04-11

## README

# JavaScript JSON Pointer

[![Build Status](https://travis-ci.org/alexeykuzmin/jsonpointer.js.png)](https://travis-ci.org/alexeykuzmin/jsonpointer.js)
[![Dependency Status](https://gemnasium.com/alexeykuzmin/jsonpointer.js.png)](https://gemnasium.com/alexeykuzmin/jsonpointer.js)
[![NPM Version](https://badge.fury.io/js/jsonpointer.js.png)](https://npmjs.org/package/jsonpointer.js)

JavaScript implementation of JSON Pointer ([RFC 6901](http://tools.ietf.org/html/rfc6901)).  
Can be used as Node.js package, AMD module or a plain script.


## Installation

via [npm](https://npmjs.org/):

    $ npm install jsonpointer.js
    
via [Bower](http://twitter.github.io/bower/):

    $ bower install jsonpointer.js
    
or copy `src/jsonpointer.js` file from repo.


## Include
###Node.js
```js
var jsonpoiner = require('jsonpointer.js');  // XXX: '.js' is part of package name!
console.log(typeof jsonpointer);  // 'object'
```

###[AMD](https://github.com/amdjs/amdjs-api/wiki/AMD)
```js
require('jsonpointer', function(jsonpointer) {
  console.log(typeof jsonpointer);  // 'object'
});
```

### &lt;script&gt; tag
```html
<script src="/path/to/jsonpointer.js" type="text/javascript"></script>
<script>
   console.log(typeof window.jsonpointer);  // 'object'
</script>
```

## API
### jsonpointer.get

`get()` accepts strings, objects and arrays as evaluation target.
```js
var target = {
  foo: {
    bar: 'foobar'
  },
  baz: [true, false],
  '~': 'tilde',
  '/': 'slash'
});

var targetJSON = JSON.stringify(target);

jsonpointer.get(target, '/foo');  // {bar: 'foobar'}
jsonpointer.get(target, '/foo/bar');  // 'foobar'
jsonpointer.get(target, '/some/nonexisting/path');  // undefined
jsonpointer.get(target, '/~0');  // 'tilde'
jsonpointer.get(targetJSON, '/~1');  // 'slash'
jsonpointer.get(targetJSON, '/baz');  // [true, false]
jsonpointer.get(targetJSON, '/baz/0');  // true
jsonpointer.get(targetJSON, '/baz/2');  // undefined
```

Second argument might be omitted, in such case `get()` returns a function
that takes pointer as argument and evaluates it.
```js
var evaluate = jsonpointer.get(target);
evaluate('/foo/bar');  // 'foobar'
```

There are several cases when `.get()` throws an exception:

 - First argument is not string, object or array.
 - First argument is string but is not valid JSON string.
 - Seconds argument is not valid JSON Pointer string.
 - Unacceptable token met during evaluation (check [section 4 of spec](http://tools.ietf.org/html/rfc6901#section-4) for examples).
 - `'-'` token used in JSON Pointer string and it's going to be evaluated in `Array` context.

---
_Source: https://npm.io/package/jsonpointer.js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
