Skip to content

JSONPath Tools / @jsonpath-tools/jsonpath / JSONPath

Class: JSONPath

JSONPath evaluator compliant with standard RFC 9535.

Methods

parse()

ts
static parse(queryText, queryOptions?): Query;

Parses the given query for later execution or analysis.

Parameters

queryText

string

Text of the query.

queryOptions?

QueryOptions = defaultQueryOptions

Query options.

Returns

Query

Parsed query (syntax tree).

Throws

JSONPathError When the query is not well-formed or valid.


remove()

ts
static remove(
   queryText, 
   queryArgument, 
   queryOptions?): JSONValue | undefined;

Executes the given query and removes the selected nodes from the query argument.

Parameters

queryText

string

Text of the query.

queryArgument

JSONValue

Argument of the query (JSON value the query is applied to).

queryOptions?

QueryOptions = defaultQueryOptions

Query options.

Returns

JSONValue | undefined

Query argument with removed values.

Throws

JSONPathError When the query is not well-formed or valid.


replace()

ts
static replace(
   queryText, 
   queryArgument, 
   replacer, 
   queryOptions?): JSONValue | undefined;

Executes the given query and replaces the selected nodes in the query argument with the specified value.

Parameters

queryText

string

Text of the query.

queryArgument

JSONValue

Argument of the query (JSON value the query is applied to).

replacer

| JSONValue | ((value) => JSONValue | undefined)

JSON value that should be used as a replacement or a function to create that value based on the replaced value.

queryOptions?

QueryOptions = defaultQueryOptions

Query options.

Returns

JSONValue | undefined

Query argument with replaced values.

Throws

JSONPathError When the query is not well-formed or valid.


select()

ts
static select(
   queryText, 
   queryArgument, 
   queryOptions?): NodeList;

Executes the given query and returns the selected nodes.

Parameters

queryText

string

Text of the query.

queryArgument

JSONValue

Argument of the query (JSON value the query is applied to).

queryOptions?

QueryOptions = defaultQueryOptions

Query options.

Returns

NodeList

Selected nodes.

Throws

JSONPathError When the query is not well-formed or valid.