eval-json-path
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -7,5 +7,6 @@ const evalJsonPath = require('./index') | ||
step2: { | ||
'pretty.nice-step': { | ||
step3: 4 | ||
} | ||
'pretty.nice-step': [ | ||
{}, | ||
{step3: 4} | ||
] | ||
} | ||
@@ -40,10 +41,10 @@ } | ||
test('nice-name steps further', () => { | ||
const result = evalJsonPath(obj, 'step1.step2[pretty.nice-step].step3') | ||
expect(result).toBe(obj.step1.step2['pretty.nice-step'].step3) | ||
const result = evalJsonPath(obj, 'step1.step2[pretty.nice-step][1].step3') | ||
expect(result).toBe(4) | ||
}) | ||
test('any out of track', () => { | ||
const result = evalJsonPath(obj, 'step1.XXX[pretty.nice-step].step3') | ||
const result = evalJsonPath(obj, 'step1.xxxxx[pretty.nice-step][1].step3') | ||
expect(result).toBe(undefined) | ||
}) | ||
}) |
{ | ||
"name": "eval-json-path", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Evaluate and query json object value at given path", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# eval-json-path | ||
Evaluate/Query the value of json object at given path | ||
[![JavaScript Style Guide](https://cdn.rawgit.com/standard/standard/master/badge.svg)](https://github.com/standard/standard) | ||
> Commonly js object variable can be accessed by property name or index. This module allow to access by path/steps given by a string | ||
## Usage | ||
```js | ||
const evalJsonPath = require('eval-json-path') | ||
const value = evalJsonPath(obj, 'prop.subprop[prett-prop][3].lastprop') | ||
const sameValue = obj.prop.subprop['prett-prop'][3].lastprop | ||
``` | ||
> The evaluation is done by each step, which is null-safe, any not-existing step will result undefined or fallback | ||
## API | ||
evalJsonPath(obj, path, fallback) | ||
- obj: The object should has sub property | ||
- path: A string represent the path/steps | ||
- fallback: A optional fallback for any not-existing step |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5607
92
28