json-keypath
Get and Set values in JSON objects using keypaths
Install
npm install --save json-keypath
Usage
Older Versions:
var JSONKeyPath = ;
ES6 and above:
Directly import specific method with object spread
;
Example
var JSONKeyPath = ; var data = example: app: count: 5 var value = JSONKeyPath;console; // 5 JSONKeyPath; value = JSONKeyPath;console; // 6
You can set values by creating new path too.
JSONKeyPath; value = JSONKeyPath;console; // likes
To avoid creating new paths, pass true
as the last parameter
JSONKeyPath; value = JSONKeyPath;// error Invalid path
By default, passing an invalid path to get would return undefined
. To follow strict path, pass the last parameter as true
var value = JSONKeyPath;console; // undefined var value = JSONKeyPath;// error Invalid path
Contributing
Contributions are welcome!
Fork this repo, clone it locally, Submit a pull request once you are done with your changes