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

@swagger-api/apidom-json-path

Package Overview
Dependencies
Maintainers
0
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@swagger-api/apidom-json-path

Evaluate JSONPath expressions against ApiDOM.

  • 1.0.0-beta.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

@swagger-api/apidom-json-path

apidom-json-path is a package that evaluates JSONPath expressions against ApiDOM.

Installation

You can install this package via npm CLI by running the following command:

 $ npm install @swagger-api/apidom-json-path

Evaluating

Package contains JSONPath evaluation functions for evaluating single or multiple JSONPath expression.

Evaluating single JSONPath expression

Suited for evaluating single JSONPath expression against ApiDOM.

import { ObjectElement } from '@swagger-api/apidom-core';
import { evaluate } from '@swagger-api/apidom-json-path';

const apidom = new ObjectElement({
  a: {
    b: [100, 1, 2],
  },
});
const result = evaluate('$.a.b[?(@ < 10)]', apidom);
// =>
// [
//   NumberElement(1),
//   NumberElement(2),
// ]

Evaluating multiple JSONPath expressions

Suited for evaluating multiple JSONPath expression against the same ApiDOM. Use this function in cases when you have multiple JSONPath expressions that need to be evaluated against single ApiDOM fragment.

import { ObjectElement } from '@swagger-api/apidom-core';
import { evaluateMulti } from '@swagger-api/apidom-json-path';

const apidom = new ObjectElement({
  a: {
    b: [100, 1, 2],
  },
});
const resultMulti = evaluateMulti(['$.a.b[?(@ < 10)]', '$.a.b[?(@ > 10)]'], apidom);
// => returns list of tuples which represents mappings between paths and end point values
// [
//   ['$.a.b[?(@ < 10)]', [NumberElement(1), NumberElement(2)]],
//   ['$.a.b[?(@ > 10)]', [NUmberElement(100)]],
// ]

Invalid JSONPath expression

If either evaluate or evaluateMulti functions are provided with invalid JSONPath expressions, they don't throw errors, but they rather return empty list of end point values.

import { ObjectElement } from '@swagger-api/apidom-core';
import { evaluate, evaluateMulti } from '@swagger-api/apidom-json-path';

const apidom = new ObjectElement({
  a: {
    b: [100, 1, 2],
  },
});
const result = evaluate('%~!@U@IU$@', apidom); // => []
const resultMulti = evaluateMulti(['%~!@U@IU$@', 'd*AS&*)(&YR3R'], apidom); // => []

FAQs

Package last updated on 16 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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