Skip to main content

Class: JSONPointer

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

Constructors

new JSONPointer()

new JSONPointer(pointer): JSONPointer

Parameters

pointer

string

A string representation of a JSON Pointer.

Returns

JSONPointer

Defined in

src/pointer/pointer.ts:27

Properties

tokens

tokens: string[]

Defined in

src/pointer/pointer.ts:22

Methods

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

value

JSONValue

Returns

boolean

Defined in

src/pointer/pointer.ts:240


getItem()

protected getItem(val, token, idx): JSONValue

Parameters

val

JSONValue

token

string

idx

number

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

pointer

JSONPointer

Returns

boolean

Defined in

src/pointer/pointer.ts:117


join()

join(...tokens): JSONPointer

Join this pointer with tokens.

Parameters

tokens

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

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()

protected parse(pointer): string[]

Parameters

pointer

string

Returns

string[]

Defined in

src/pointer/pointer.ts:126


resolve()

resolve(value, fallback): JSONValue

Resolve this pointer against JSON-like data value.

Parameters

value

JSONValue

The target JSON-like value, possibly loaded using JSON.parse().

fallback

MaybeJSONValue = UNDEFINED

A 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

value

JSONValue

Returns

[MaybeJSONValue, MaybeJSONValue]

Defined in

src/pointer/pointer.ts:79


to()

to(rel): JSONPointer

Parameters

rel

string | RelativeJSONPointer

Returns

JSONPointer

Defined in

src/pointer/pointer.ts:267


toString()

toString(): string

Returns

string

Defined in

src/pointer/pointer.ts:110


encode()

static encode(tokens): string

Parameters

tokens

string[]

Returns

string

Defined in

src/pointer/pointer.ts:32