1.0.0-alpha.1 • Published 6 days ago

@swagger-api/apidom-json-path v1.0.0-alpha.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
6 days ago

@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); // => []
1.0.0-alpha.1

6 days ago

1.0.0-alpha.0

7 days ago

0.99.2

21 days ago

0.99.1

2 months ago

0.99.0

2 months ago

0.98.0

2 months ago

0.97.0

3 months ago

0.96.0

3 months ago

0.95.0

3 months ago

0.94.0

4 months ago

0.93.0

4 months ago

0.92.0

4 months ago

0.91.0

4 months ago

0.90.0

5 months ago

0.89.0

5 months ago

0.88.0

5 months ago

0.87.0

5 months ago

0.86.0

6 months ago

0.84.0

6 months ago

0.85.0

6 months ago

0.82.2

7 months ago

0.80.0

7 months ago

0.81.0

7 months ago

0.82.0

7 months ago

0.83.0

7 months ago

0.82.1

7 months ago

0.78.0

7 months ago

0.76.2

9 months ago

0.77.0

8 months ago

0.76.1

9 months ago

0.79.0

7 months ago

0.74.0

10 months ago

0.73.0

10 months ago

0.76.0

9 months ago

0.75.0

9 months ago

0.74.1

10 months ago

0.72.0

10 months ago

0.71.0

10 months ago

0.70.1

11 months ago

0.70.0

12 months ago

0.69.2

1 year ago

0.69.1

1 year ago

0.69.3

1 year ago

0.69.0

1 year ago

0.68.1

1 year ago