UNPKG

json-p3

Version:

JSONPath, JSON Pointer and JSON Patch

85 lines (84 loc) 2.81 kB
import { JSONPointer } from "../pointer"; import { JSONValue } from "../types"; import { type SerializationOptions } from "./types"; /** * The pair of a JSON value and its location found in the target JSON value. */ export declare class JSONPathNode { readonly value: JSONValue; readonly location: Array<string | number>; readonly root: JSONValue; /** * @param value - The JSON value found at _location_. * @param location - The parts of a normalized path to _value_. * @param root - The target value at the top of the JSON node tree. */ constructor(value: JSONValue, location: Array<string | number>, root: JSONValue); /** * @deprecated Use {@link getPath} with `options.form` set to `canonical` instead. */ get path(): string; /** * Get the path to this node in the target JSON value. * * Given that the path refers to the singular current node, the returned path * will always be a normalized path if `options.form` is set to `canonical`, * following section 2.7 of RFC 9535. */ getPath(options?: SerializationOptions): string; /** * Return this node's location as a {@link JSONPointer}. */ toPointer(): JSONPointer; private decodeNameLocation; } /** * */ export declare class JSONPathNodeList { readonly nodes: JSONPathNode[]; constructor(nodes: JSONPathNode[]); /** * @returns an iterator over nodes in the list. */ [Symbol.iterator](): Iterator<JSONPathNode>; /** * @returns `true` if the node list is empty. */ empty(): boolean; /** * @returns An array containing the values at each node in the list. * * @see {@link valuesOrSingular} to unpack the array if there is only * one node in the list. */ values(): JSONValue[]; /** * Like {@link values}, but returns the node's value is there is only one * node in the list. */ valuesOrSingular(): JSONValue; /** * @returns An array of locations for each node in the node list. * * A location is an array of property names and array indices that were * required to reach the node's value in the target JSON value. */ locations(): Array<Array<string | number>>; /** * @returns An array of normalized path strings for each node in the list. * * A normalized path contains only property name and index selectors, and * always uses bracketed segments, never shorthand selectors. */ paths(options?: SerializationOptions): string[]; /** * @returns An array of {@link JSONPointer} instances, one for each node * in the list. */ pointers(): JSONPointer[]; /** * @returns The number of nodes in the node list. */ get length(): number; }