Class: JSONPointer
jsonpointer.JSONPointer
Identify a single value in JSON-like data, as per RFC 6901.
Constructors
constructor
• new JSONPointer(pointer
): JSONPointer
Parameters
Name | Type | Description |
---|---|---|
pointer | string | A string representation of a JSON Pointer. |
Returns
Defined in
Properties
#pointer
• Private
#pointer: string
Defined in
tokens
• tokens: string
[]
Defined in
Methods
_join
▸ _join(pointer
): JSONPointer
Parameters
Name | Type |
---|---|
pointer | string |
Returns
Defined in
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
Name | Type |
---|---|
value | JSONValue |
Returns
boolean
Defined in
getItem
▸ getItem(val
, token
, idx
): JSONValue
Parameters
Name | Type |
---|---|
val | JSONValue |
token | string |
idx | number |
Returns
Defined in
isRelativeTo
▸ isRelativeTo(pointer
): boolean
Return true if this pointer points to a child of pointer.
Parameters
Name | Type |
---|---|
pointer | JSONPointer |
Returns
boolean
Defined in
join
▸ join(...tokens
): JSONPointer
Join this pointer with tokens.
Parameters
Name | Type | Description |
---|---|---|
...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
A new JSON Pointer that is the concatenation of all tokens or "parts".
Defined in
parent
▸ parent(): JSONPointer
Return this pointer's parent as a new JSONPointer
.
If this pointer points to the document root, this is returned.
Returns
Defined in
parse
▸ parse(pointer
): string
[]
Parameters
Name | Type |
---|---|
pointer | string |
Returns
string
[]
Defined in
resolve
▸ resolve(value
, fallback?
): JSONValue
Resolve this pointer against JSON-like data value.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
value | JSONValue | undefined | 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
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
resolveWithParent
▸ resolveWithParent(value
): [MaybeJSONValue
, MaybeJSONValue
]
Parameters
Name | Type |
---|---|
value | JSONValue |
Returns
[MaybeJSONValue
, MaybeJSONValue
]
Defined in
to
▸ to(rel
): JSONPointer
Parameters
Name | Type |
---|---|
rel | string | RelativeJSONPointer |
Returns
Defined in
toString
▸ toString(): string
Returns
string
Defined in
encode
▸ encode(tokens
): string
Parameters
Name | Type |
---|---|
tokens | string [] |
Returns
string