Skip to main content

Class: JSONPointer

Defined in: src/pointer/pointer.ts:23

Constructors​

Constructor​

new JSONPointer(tokens): JSONPointer

Defined in: src/pointer/pointer.ts:24

Parameters​

tokens​

string[]

Returns​

JSONPointer

Properties​

tokens​

readonly tokens: string[]

Defined in: src/pointer/pointer.ts:24

Methods​

exists()​

exists(value): boolean

Defined in: src/pointer/pointer.ts:131

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​

value​

JSONValue

Returns​

boolean


isRelativeTo()​

isRelativeTo(other): boolean

Defined in: src/pointer/pointer.ts:164

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

Parameters​

other​

JSONPointer

Returns​

boolean


join()​

join(...pointers): JSONPointer

Defined in: src/pointer/pointer.ts:182

Join this pointer with tokens.

Parameters​

pointers​

...string[]

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".


parent()​

parent(): JSONPointer

Defined in: src/pointer/pointer.ts:148

Return this pointer's parent as a new JSONPointer.

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

Returns​

JSONPointer


resolve()​

resolve(data, fallback?): JSONValue

Defined in: src/pointer/pointer.ts:74

Evaluate this pointer against data.

Parameters​

data​

JSONValue

The target JSON-like value, as you might get from JSON.parse().

fallback?​

JSONValue | typeof UNDEFINED

A default value to return if this pointer can not be resolved against data.

Returns​

JSONValue

The JSON-like value obtained by evaluating this pointer against data.

Throws​

JSONPointerResolutionError If the pointer can not be resolved and no fallback is given.


resolveWithParent()​

resolveWithParent(data): [JSONValue | typeof UNDEFINED, JSONValue | typeof UNDEFINED]

Defined in: src/pointer/pointer.ts:92

Parameters​

data​

JSONValue

Returns​

[JSONValue | typeof UNDEFINED, JSONValue | typeof UNDEFINED]


to()​

to(rel): JSONPointer

Defined in: src/pointer/pointer.ts:156

Parameters​

rel​

string | RelativeJSONPointer

Returns​

JSONPointer


toString()​

toString(): string

Defined in: src/pointer/pointer.ts:57

Returns​

string


encode()​

static encode(tokens): string

Defined in: src/pointer/pointer.ts:50

Encode tokens into a '/' separated string with '~' and '/' escaped according to RFC 6901.

Parameters​

tokens​

(string | number)[]

A sequence of property names and array indexes forming a path through JSON-like data. Numeric tokens should be integers.

Returns​

string

Tokens encoded according to RFC 6901.


fromString()​

static fromString(pointer): JSONPointer

Defined in: src/pointer/pointer.ts:29

Return a new JSONPointer given a pointer string following RFC 6901.

Parameters​

pointer​

string

Returns​

JSONPointer