Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eval-json-path

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eval-json-path - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

13

index.spec.js

@@ -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
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc