Creates a new instance.
a string representation of a JSON Pointer, or a decoded array of path segments.
The pointer's decoded path segments.
This pointer's JSON Pointer encoded string representation.
This pointer's URI fragment identifier encoded string representation.
Creates a new instance by concatenating the specified pointer's path onto this pointer's path.
the string representation of a pointer, it's decoded path, or an instance of JsonPointer indicating the additional path to concatenate onto the pointer.
Gets the target object's value at the pointer's location.
the target of the operation
Determines if the specified target's object graph has a value at the pointer's location.
the target of the operation
Gets the value in the object graph that is the parent of the pointer location.
the target of the operation
Resolves the specified relative pointer path against the specified target object, and gets the target object's value at the relative pointer's location.
the target of the operation
the relative pointer (relative to this)
the value at the relative pointer's resolved path; otherwise undefined.
Creates a new JsonPointer instance, pointing to the specified relative location in the object graph.
the relative pointer (relative to this)
A new instance that points to the relative location.
Sets the target object's value, as specified, at the pointer's location.
If any part of the pointer's path does not exist, the operation aborts without modification, unless the caller indicates that pointer's location should be created.
the target of the operation
the value to set
indicates whether the pointer's location should be created if it doesn't already exist.
Emits the JSON Pointer encoded string representation.
Removes the target object's value at the pointer's location.
the target of the operation
the value that was removed from the object graph.
Factory function that creates a JsonPointer instance.
const ptr = JsonPointer.create('/deeply/nested/data/0/here');
or
const ptr = JsonPointer.create(['deeply', 'nested', 'data', 0, 'here']);
the pointer or path.
Decodes the specified pointer into path segments.
a string representation of a JSON Pointer
Evaluates the target's object graph, returning a Record<Pointer, unknown> populated with pointers and the corresponding values from the graph.
the target of the operation
indicates whether the results are populated with fragment identifiers rather than regular pointers
Gets the target
object's value at the pointer
's location.
const target = {
first: 'second',
third: ['fourth', 'fifth', { sixth: 'seventh' }],
eighth: 'ninth'
};
console.log(JsonPointer.get(target, '/third/2/sixth'));
// seventh
console.log(JsonPointer.get(target, '/tenth'));
// undefined
the target of the operation
the pointer or path.
Determines if the specified target
's object graph has a value at the pointer
's location.
const target = {
first: 'second',
third: ['fourth', 'fifth', { sixth: 'seventh' }],
eighth: 'ninth'
};
console.log(JsonPointer.has(target, '/third/0'));
// true
console.log(JsonPointer.has(target, '/tenth'));
// false
the target of the operation
the pointer or path
Evaluates the target's object graph, returning a UriFragmentIdentifierPointerListItem for each location in the graph.
the target of the operation
Evaluates the target's object graph, returning a JsonStringPointerListItem for each location in the graph.
the target of the operation
Evaluates the target's object graph, returning a Map<Pointer,unknown> populated with pointers and the corresponding values form the graph.
the target of the operation
indicates whether the results are populated with fragment identifiers rather than regular pointers
Sets the target
object's value, as specified, at the pointer
's location.
const target = {
first: 'second',
third: ['fourth', 'fifth', { sixth: 'seventh' }],
eighth: 'ninth'
};
console.log(JsonPointer.set(target, '/third/2/sixth', 'tenth'));
// seventh
console.log(JsonPointer.set(target, '/tenth', 'eleventh', true));
// undefined
console.log(JSON.stringify(target, null, ' '));
// {
// "first": "second",
// "third": [
// "fourth",
// "fifth",
// {
// "sixth": "tenth"
// }
// ],
// "eighth": "ninth",
// "tenth": "eleventh"
// }
the target of the operation
the pointer or path
a value to write into the object graph at the specified pointer location
indications whether the operation should force the pointer's location into existence in the object graph.
the prior value at the pointer's location in the object graph.
Removes the target
object's value at the pointer
's location.
const target = {
first: 'second',
third: ['fourth', 'fifth', { sixth: 'seventh' }],
eighth: 'ninth'
};
console.log(JsonPointer.unset(target, '/third/2/sixth'));
// seventh
console.log(JsonPointer.unset(target, '/tenth'));
// undefined
console.log(JSON.stringify(target, null, ' '));
// {
// "first": "second",
// "third": [
// "fourth",
// "fifth",
// {}
// ],
// "eighth": "ninth",
// }
the target of the operation
the pointer or path
the value that was removed from the object graph.
Evaluates the target's object graph, calling the specified visitor for every unique pointer location discovered while walking the graph.
the target of the operation
a callback function invoked for each unique pointer location in the object graph
indicates whether the visitor should receive fragment identifiers or regular pointers
Generated using TypeDoc
Represents a JSON Pointer, capable of getting and setting the value on target objects at the pointer's location.
While there are static variants for most operations, our recommendation is to use the instance level methods, which enables you avoid repeated compiling/emitting transient accessors. Take a look at the speed comparisons for our justification.
In most cases, you should create and reuse instances of JsonPointer within scope that makes sense for your app. We often create constants for frequently used pointers, but your use case may vary.
The following is a contrived example showing a function that uses pointers to deal with changes in the structure of data (a version independent function):
There are many uses for pointers.