Skip to main content

Class: JSONPointer

jsonpointer.JSONPointer

Identify a single value in JSON-like data, as per RFC 6901.

Constructors

constructor

new JSONPointer(pointer): JSONPointer

Parameters

NameTypeDescription
pointerstringA string representation of a JSON Pointer.

Returns

JSONPointer

Defined in

src/pointer/pointer.ts:27

Properties

#pointer

Private #pointer: string

Defined in

src/pointer/pointer.ts:21


tokens

tokens: string[]

Defined in

src/pointer/pointer.ts:22

Methods

_join

_join(pointer): JSONPointer

Parameters

NameType
pointerstring

Returns

JSONPointer

Defined in

src/pointer/pointer.ts:189


exists

exists(value): boolean

Return true if this pointer can be resolved against value.

Note that JSONPointer.resolve() can return legitimate falsy values that form part of the target JSON document. This method will return true if a falsy value is found.

Parameters

NameType
valueJSONValue

Returns

boolean

Defined in

src/pointer/pointer.ts:240


getItem

getItem(val, token, idx): JSONValue

Parameters

NameType
valJSONValue
tokenstring
idxnumber

Returns

JSONValue

Defined in

src/pointer/pointer.ts:140


isRelativeTo

isRelativeTo(pointer): boolean

Return true if this pointer points to a child of pointer.

Parameters

NameType
pointerJSONPointer

Returns

boolean

Defined in

src/pointer/pointer.ts:117


join

join(...tokens): JSONPointer

Join this pointer with tokens.

Parameters

NameTypeDescription
...tokensstring[]JSON Pointer strings, possibly without leading slashes. If a token or "part" does have a leading slash, the previous pointer is ignored and a new JSONPointer is created, then processing of the remaining tokens continues.

Returns

JSONPointer

A new JSON Pointer that is the concatenation of all tokens or "parts".

Defined in

src/pointer/pointer.ts:220


parent

parent(): JSONPointer

Return this pointer's parent as a new JSONPointer.

If this pointer points to the document root, this is returned.

Returns

JSONPointer

Defined in

src/pointer/pointer.ts:257


parse

parse(pointer): string[]

Parameters

NameType
pointerstring

Returns

string[]

Defined in

src/pointer/pointer.ts:126


resolve

resolve(value, fallback?): JSONValue

Resolve this pointer against JSON-like data value.

Parameters

NameTypeDefault valueDescription
valueJSONValueundefinedThe target JSON-like value, possibly loaded using JSON.parse().
fallbackMaybeJSONValueUNDEFINEDA default value to return if value has no path matching pointer.

Returns

JSONValue

The value identified by pointer or, if given, the fallback value in the even of a JSONPointerResolutionError.

Throws

JSONPointerResolutionError If the value pointed to by pointer does not exist in value, and no fallback value is given.

Defined in

src/pointer/pointer.ts:57


resolveWithParent

resolveWithParent(value): [MaybeJSONValue, MaybeJSONValue]

Parameters

NameType
valueJSONValue

Returns

[MaybeJSONValue, MaybeJSONValue]

Defined in

src/pointer/pointer.ts:79


to

to(rel): JSONPointer

Parameters

NameType
relstring | RelativeJSONPointer

Returns

JSONPointer

Defined in

src/pointer/pointer.ts:267


toString

toString(): string

Returns

string

Defined in

src/pointer/pointer.ts:110


encode

encode(tokens): string

Parameters

NameType
tokensstring[]

Returns

string

Defined in

src/pointer/pointer.ts:32