Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/prestaul/skeemas-json-pointer
Lightweight implementation of JSON Pointers
https://github.com/prestaul/skeemas-json-pointer
Last synced: about 18 hours ago
JSON representation
Lightweight implementation of JSON Pointers
- Host: GitHub
- URL: https://github.com/prestaul/skeemas-json-pointer
- Owner: Prestaul
- License: mit
- Created: 2015-01-22T05:27:40.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-12-16T14:39:43.000Z (almost 9 years ago)
- Last Synced: 2024-11-04T00:05:02.781Z (4 days ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# skeemas-json-pointer
Lightweight implementation of [JSON Pointers](https://tools.ietf.org/html/rfc6901)
## Install
```bash
npm install skeemas-json-pointer
```## Pointers for Getting Values
```js
var jsonPointer = require('skeemas-json-pointer');// Getting values
jsonPointer('#/foo').get({ foo:'bar' });
// =>'bar'jsonPointer('#/nested/foo').get({
nested: { foo:'bar' }
});
// =>'bar'jsonPointer('#/nested/foo/1').get({
nested: { foo:['bar','bat','baz'] }
});
// =>'bat'
```## Pointers for Setting Values
```js
var subject = {
nested: { foo:'bar' },
list: [0, 1, 2]
};// Change a property value
jsonPointer('#/nested/foo').set(subject, 'baz');// Change an array item
jsonPointer('#/list/1').set(subject, 'one');// Append an array item
jsonPointer('#/list/-').set(subject, 'last');assert.deepEqual(subject, {
nested: { foo:'baz' },
list: [0, 'one', 2, 'last']
});
```