@types/jsonpath

  • Version 0.2.4
  • Published
  • 5.28 kB
  • No dependencies
  • MIT license

Install

npm i @types/jsonpath
yarn add @types/jsonpath
pnpm add @types/jsonpath

Overview

TypeScript definitions for jsonpath

Index

Functions

function apply

apply: (
obj: any,
pathExpression: string,
fn: (x: any) => any
) => Array<{ path: PathComponent[]; value: any }>;
  • Runs the supplied function fn on each matching element, and replaces each matching element with the return value from the function. The function accepts the value of the matching element as its only parameter. Returns matching nodes with their updated values.

function nodes

nodes: (
obj: any,
pathExpression: string,
count?: number
) => Array<{ path: PathComponent[]; value: any }>;
  • Find elements and their corresponding paths in obj matching pathExpression. Returns an array of node objects where each node has a path containing an array of keys representing the location within obj, and a value pointing to the matched element. Returns only first count nodes if specified.

function parent

parent: (obj: any, pathExpression: string) => any;
  • Returns the parent of the first matching element.

function parse

parse: (pathExpression: string) => any[];
  • Parse the provided JSONPath expression into path components and their associated operations.

function paths

paths: (obj: any, pathExpression: string, count?: number) => PathComponent[][];
  • Find paths to elements in obj matching pathExpression. Returns an array of element paths that satisfy the provided JSONPath expression. Each path is itself an array of keys representing the location within obj of the matching element. Returns only first count paths if specified.

function query

query: (obj: any, pathExpression: string, count?: number) => any[];
  • Find elements in obj matching pathExpression. Returns an array of elements that satisfy the provided JSONPath expression,or an empty array if none were matched. Returns only first count elements if specified.

function stringify

stringify: (path: PathComponent[]) => string;
  • Returns a path expression in string form, given a path. The supplied path may either be a flat array of keys, as returned by jp.nodes for example, or may alternatively be a fully parsed path expression in the form of an array of path components as returned by jp.parse.

function value

value: {
(obj: any, pathExpression: string): any;
<T>(obj: any, pathExpression: string, newValue: T): T;
};
  • Returns the value of the first element matching pathExpression. If newValue is provided, sets the value of the first matching element and returns the new value.

Type Aliases

type PathComponent

type PathComponent = string | number;

    Package Files (1)

    Dependencies (0)

    No dependencies.

    Dev Dependencies (0)

    No dev dependencies.

    Peer Dependencies (0)

    No peer dependencies.

    Badge

    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/jsonpath.

    • Markdown
      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/jsonpath)
    • HTML
      <a href="https://www.jsdocs.io/package/@types/jsonpath"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>