1.0.2 • Published 1 year ago

@saasquatch/jsonata-paths-extractor v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

JSONata Paths Extractor

A package for statically analysing JSONata expressions and returning object paths from the context that are likely used. Complete static analysis of JSONata is not attempted (and may not actually be feasible), so the results are considered best-effort.

Installation

Using npm or yarn the package can be installed

npm i @saasquatch/jsonata-paths-extractor

Usage

A single function is exported as the default export. The function accepts a JSONata expression as input and returns the paths found in the expression.

For more detail on behaviour, see test/paths.feature

Example usage:

import extractJSONataPaths from "@saasquatch/jsonata-paths-extractor";

const exampleJsonataExpression =
  'example.jsonata.path = "a string" ? example.two : example[two="test"].name^(<three)';

const paths = extractJSONataPaths(exampleJsonataExpression);
// paths: ["/example/jsonata/path","/example/two","/example/name","/example/two","/example/name/three"]

Test Suite

The package contains a test suite that runs through expressions sourced from program conditions and the JSONata test suite. The results of these tests were autogenerated and reviewed, they should be used as a set of tests to ensure against regressions. The results of the test suite should only be modified after implementing improvements to the library.

Improvements should be documented in the feature file in addition to the automated tests.