Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ralyodio/getbypath
Get JSON data by path
https://github.com/ralyodio/getbypath
Last synced: 19 days ago
JSON representation
Get JSON data by path
- Host: GitHub
- URL: https://github.com/ralyodio/getbypath
- Owner: ralyodio
- License: mit
- Created: 2013-11-12T05:16:42.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-09-08T05:35:45.000Z (about 9 years ago)
- Last Synced: 2024-10-05T23:04:42.484Z (about 1 month ago)
- Language: JavaScript
- Size: 144 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
getbypath
=========Get data from a JSON object by path.
## Install
npm install getbypath
## Usage
var getByPath = require('getbypath');
var obj = { foo: { bar: { baz: 'thedata', biz: ['one', 'two'] }}};
var bar = getByPath(obj, 'foo.bar.baz');console.log(bar);
console.log(getByPath(obj, 'foo.bar'));
console.log(getByPath(obj, 'foo.bar.biz'));//produces the following output
thedata
{ baz: 'thedata', biz: [ 'one', 'two' ] }
[ 'one', 'two' ]// use getByPath with a third argument true to create path
var newPath = getByPath(obj, 'my.newPath', true);console.log(newPath); // {}
console.log(obj);/*
{
foo: {
bar: {
baz: 'thedata',
biz: ['one', 'two']
}
},
my: {
newPath: {}
}
}
*/## Tests
Install devDependencies
npm install
Run tests
npm test