Skip to main content

Class: JSONPathEnvironment

jsonpath.JSONPathEnvironment

A configuration object from which JSONPath queries can be evaluated.

An environment is where you'd register custom function extensions or set the maximum recursion depth limit, for example.

Constructors

constructor

new JSONPathEnvironment(options?): JSONPathEnvironment

Parameters

NameTypeDescription
optionsJSONPathEnvironmentOptionsEnvironment configuration options.

Returns

JSONPathEnvironment

Defined in

src/path/environment.ts:129

Properties

functionRegister

functionRegister: Map<string, FilterFunction>

A map of function names to objects implementing the FilterFunction interface. You are free to set or delete custom filter functions directly.

Defined in

src/path/environment.ts:122


keysPattern

Readonly keysPattern: RegExp

The pattern to use for the non-standard keys selector.

Defined in

src/path/environment.ts:116


maxIntIndex

Readonly maxIntIndex: number

The maximum number allowed when indexing or slicing an array. Defaults to 2**53 -1.

Defined in

src/path/environment.ts:94


maxRecursionDepth

Readonly maxRecursionDepth: number

The maximum number of objects and/or arrays the recursive descent selector can visit before a JSONPathRecursionLimitError is thrown.

Defined in

src/path/environment.ts:106


minIntIndex

Readonly minIntIndex: number

The minimum number allowed when indexing or slicing an array. Defaults to -(2**53) -1.

Defined in

src/path/environment.ts:100


nondeterministic

Readonly nondeterministic: boolean

If true, enable nondeterministic ordering when iterating JSON object data.

Defined in

src/path/environment.ts:111


parser

Private parser: Parser

Defined in

src/path/environment.ts:124


strict

Readonly strict: boolean

Indicates if the environment should to be strict about its compliance with JSONPath standards.

Defaults to true. Setting strict to false currently has no effect. If/when we add non-standard features, the environment's strictness will control their availability.

Defined in

src/path/environment.ts:88

Methods

checkWellTypedness

checkWellTypedness(token, args): FilterExpression[]

Check the well-typedness of a function's arguments at compile-time.

This method is called by the Parser when parsing function calls. It is expected to throw a JSONPathTypeError if the function's parameters are not well-typed.

Override this if you want to deviate from the JSONPath Spec's function extension type system.

Parameters

NameTypeDescription
tokenTokenThe Token starting the function call. Token.value will contain the name of the function.
argsFilterExpression[]One FilterExpression for each argument.

Returns

FilterExpression[]

Defined in

src/path/environment.ts:219


compile

compile(path): JSONPath

Parameters

NameTypeDescription
pathstringA JSONPath query to parse.

Returns

JSONPath

A new JSONPath object, bound to this environment.

Defined in

src/path/environment.ts:145


entries

entries(obj): [string, JSONValue][]

Return an array of key/values of the enumerable properties in obj.

If you want to introduce some nondeterminism to iterating JSON-like objects, do it here. The wildcard selector, descendent segment and filter selector all use this.environment.entries.

Parameters

NameTypeDescription
objObjectA JSON-like object.

Returns

[string, JSONValue][]

Defined in

src/path/environment.ts:306


lazyQuery

lazyQuery(path, value): IterableIterator<JSONPathNode>

A lazy version of query which is faster and more memory efficient when querying some large datasets.

Parameters

NameTypeDescription
pathstringA JSONPath query to parse and evaluate against value.
valueJSONValueData to which path will be applied.

Returns

IterableIterator<JSONPathNode>

A sequence of JSONPathNode objects resulting from applying path to value.

Defined in

src/path/environment.ts:172


match

match(path, value): undefined | JSONPathNode

Return a JSONPathNode instance for the first object found in value matching path.

Parameters

NameTypeDescription
pathstringA JSONPath query.
valueJSONValueJSON-like data to which the query path will be applied.

Returns

undefined | JSONPathNode

The first node in value matching path, or undefined if there are no matches.

Defined in

src/path/environment.ts:188


query

query(path, value): JSONPathNodeList

Parameters

NameTypeDescription
pathstringA JSONPath query to parse and evaluate against value.
valueJSONValueData to which path will be applied.

Returns

JSONPathNodeList

The JSONPathNodeList resulting from applying path to value.

Defined in

src/path/environment.ts:159


setupFilterFunctions

setupFilterFunctions(): void

A hook for setting up the function register. You are encouraged to override this method in classes extending JSONPathEnvironment.

Returns

void

Defined in

src/path/environment.ts:196