You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/guides/json-patch.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
JSON Patch ([RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902)) is a standard for describing update operations to perform on JSON-like data. Each operation includes, at least, an `op` string and a `path`, which is a [JSON Pointer](./json-pointer.md).
4
4
5
-
Use [`jsonpatch.apply(ops, data)`](../api/namespaces/jsonpatch.md#apply) to apply _ops_ to _data_, where _ops_ should be an array of [`OpObject`s](../api/namespaces/jsonpatch.md#opobject), as per RFC 6902. Patch operation are applied sequentially and, unless the target JSON document's root value is replaced, **data is modified in place**.
5
+
Use [`jsonpatch.apply(ops, data)`](../api/namespaces/jsonpatch/functions/apply.md) to apply _ops_ to _data_, where _ops_ should be an array of [`OpObject`s](../api/namespaces/jsonpatch/type-aliases/OpObject.md), as per RFC 6902. Patch operation are applied sequentially and, unless the target JSON document's root value is replaced, **data is modified in place**.
Use the [`JSONPatch`](../api/classes/jsonpatch.JSONPatch.md) constructor to create a patch for repeated application.
23
+
Use the [`JSONPatch`](../api/namespaces/jsonpatch/classes/JSONPatch.md) constructor to create a patch for repeated application.
24
24
25
25
```javascript
26
26
import { JSONPatch } from"json-p3";
@@ -40,11 +40,11 @@ console.log(data);
40
40
41
41
## Builder API
42
42
43
-
[`JSONPatch`](../api/classes/jsonpatch.JSONPatch.md) implements a builder interface for constructing JSON Patch documents. Each of the following methods appends an operation to the patch and returns the patch instance, so method calls can be chained.
43
+
[`JSONPatch`](../api/namespaces/jsonpatch/classes/JSONPatch.md) implements a builder interface for constructing JSON Patch documents. Each of the following methods appends an operation to the patch and returns the patch instance, so method calls can be chained.
44
44
45
45
### `add()`
46
46
47
-
[`JSONPatch.add(pointer, value)`](../api/classes/jsonpatch.JSONPatch.md#add) appends an [_add_](https://datatracker.ietf.org/doc/html/rfc6902#section-4.1) operation to the patch. _pointer_ can be a string following RFC 6901 or an instance of [`JSONPointer`](../api/classes/jsonpointer.JSONPointer.md).
47
+
[`JSONPatch.add(pointer, value)`](../api/namespaces/jsonpatch/classes/JSONPatch.md#add) appends an [_add_](https://datatracker.ietf.org/doc/html/rfc6902#section-4.1) operation to the patch. _pointer_ can be a string following RFC 6901 or an instance of [`JSONPointer`](../api/namespaces/jsonpointer/classes/JSONPointer.md).
[`JSONPatch.remove(pointer)`](../api/classes/jsonpatch.JSONPatch.md#add) appends an[_remove_](https://datatracker.ietf.org/doc/html/rfc6902#section-4.2) operation to the patch. _pointer_ can be a string following RFC 6901 or an instance of [`JSONPointer`](../api/classes/jsonpointer.JSONPointer.md).
70
+
[`JSONPatch.remove(pointer)`](../api/namespaces/jsonpatch/classes/JSONPatch.md#remove) appends a[_remove_](https://datatracker.ietf.org/doc/html/rfc6902#section-4.2) operation to the patch. _pointer_ can be a string following RFC 6901 or an instance of [`JSONPointer`](../api/namespaces/jsonpointer/classes/JSONPointer.md).
[`JSONPatch.replace(pointer, value)`](../api/classes/jsonpatch.JSONPatch.md#add) appends an[_replace_](https://datatracker.ietf.org/doc/html/rfc6902#section-4.3) operation to the patch. _pointer_ can be a string following RFC 6901 or an instance of [`JSONPointer`](../api/classes/jsonpointer.JSONPointer.md).
90
+
[`JSONPatch.replace(pointer, value)`](../api/namespaces/jsonpatch/classes/JSONPatch.md#replace) appends a[_replace_](https://datatracker.ietf.org/doc/html/rfc6902#section-4.3) operation to the patch. _pointer_ can be a string following RFC 6901 or an instance of [`JSONPointer`](../api/namespaces/jsonpointer/classes/JSONPointer.md).
[`JSONPatch.move(fromPointer, toPointer)`](../api/classes/jsonpatch.JSONPatch.md#add) appends an[_move_](https://datatracker.ietf.org/doc/html/rfc6902#section-4.4) operation to the patch. _fromPointer_ and _toPointer_ can be a string following RFC 6901 or an instance of [`JSONPointer`](../api/classes/jsonpointer.JSONPointer.md).
111
+
[`JSONPatch.move(fromPointer, toPointer)`](../api/namespaces/jsonpatch/classes/JSONPatch.md#move) appends a[_move_](https://datatracker.ietf.org/doc/html/rfc6902#section-4.4) operation to the patch. _fromPointer_ and _toPointer_ can be a string following RFC 6901 or an instance of [`JSONPointer`](../api/namespaces/jsonpointer/classes/JSONPointer.md).
[`JSONPatch.copy(fromPointer, toPointer)`](../api/classes/jsonpatch.JSONPatch.md#add) appends an[_copy_](https://datatracker.ietf.org/doc/html/rfc6902#section-4.5) operation to the patch. _fromPointer_ and _toPointer_ can be a string following RFC 6901 or an instance of [`JSONPointer`](../api/classes/jsonpointer.JSONPointer.md).
132
+
[`JSONPatch.copy(fromPointer, toPointer)`](../api/namespaces/jsonpatch/classes/JSONPatch.md#copy) appends a[_copy_](https://datatracker.ietf.org/doc/html/rfc6902#section-4.5) operation to the patch. _fromPointer_ and _toPointer_ can be a string following RFC 6901 or an instance of [`JSONPointer`](../api/namespaces/jsonpointer/classes/JSONPointer.md).
[`JSONPatch.copy(pointer, value)`](../api/classes/jsonpatch.JSONPatch.md#add) appends an[_test_](https://datatracker.ietf.org/doc/html/rfc6902#section-4.6) operation to the patch. _pointer_ can be a string following RFC 6901 or an instance of [`JSONPointer`](../api/classes/jsonpointer.JSONPointer.md).
153
+
[`JSONPatch.copy(pointer, value)`](../api/namespaces/jsonpatch/classes/JSONPatch.md#test) appends a[_test_](https://datatracker.ietf.org/doc/html/rfc6902#section-4.6) operation to the patch. _pointer_ can be a string following RFC 6901 or an instance of [`JSONPointer`](../api/namespaces/jsonpointer/classes/JSONPointer.md).
`resolve()` is a convenience function equivalent to `new JSONPointer(pointer).resolve(data)`. Use the [`JSONPointer`](../api/classes/jsonpointer.JSONPointer.md) constructor when you need to resolve the same pointer repeatedly against different data.
31
+
`resolve()` is a convenience function equivalent to `new JSONPointer(pointer).resolve(data)`. Use the [`JSONPointer`](../api/namespaces/jsonpointer/classes/JSONPointer.md) constructor when you need to resolve the same pointer repeatedly against different data.
If the pointer can't be resolved against the argument JSON value, one of [`JSONPointerIndexError`](../api/classes/jsonpointer.JSONPointerIndexError.md), [`JSONPointerKeyError`](../api/classes/jsonpointer.JSONPointerKeyError.md) or [`JSONPointerTypeError`](../api/classes/jsonpointer.JSONPointerTypeError.md) is thrown. All three exceptions inherit from [`JSONPointerResolutionError`](../api/classes/jsonpointer.JSONPointerResolutionError.md).
55
+
If the pointer can't be resolved against the argument JSON value, one of [`JSONPointerIndexError`](../api/namespaces/jsonpointer/classes/JSONPointerIndexError.md), [`JSONPointerKeyError`](../api/namespaces/jsonpointer/classes/JSONPointerKeyError.md) or [`JSONPointerTypeError`](../api/namespaces/jsonpointer/classes/JSONPointerTypeError.md) is thrown. All three exceptions inherit from [`JSONPointerResolutionError`](../api/namespaces/jsonpointer/classes/JSONPointerResolutionError.md).
56
56
57
57
```javascript
58
58
// .. continued from above
@@ -70,7 +70,7 @@ console.log(rv); // -1
70
70
71
71
### With parent
72
72
73
-
[`resolveWithParent()`](../api/classes/jsonpointer.JSONPointer.md#resolvewithparent) is similar to `resolve()`, but returns the target's parent value and the target value as a two-element array.
73
+
[`resolveWithParent()`](../api/namespaces/jsonpointer/classes/JSONPointer.md#resolvewithparent) is similar to `resolve()`, but returns the target's parent value and the target value as a two-element array.
74
74
75
75
```javascript
76
76
import { JSONPointer } from"json-p3";
@@ -87,15 +87,15 @@ const pointer = new JSONPointer("/users/1");
If the target value does not exist but the parent does, you'll get the parent object and the special [`UNDEFINED`](../api/namespaces/jsonpointer.md#undefined) symbol. Similarly, if the pointer is pointing to the JSON document root, you'll get `UNDEFINED` and the target document in its entirety.
90
+
If the target value does not exist but the parent does, you'll get the parent object and the special [`UNDEFINED`](../api/namespaces/jsonpointer/variables/UNDEFINED.md) symbol. Similarly, if the pointer is pointing to the JSON document root, you'll get `UNDEFINED` and the target document in its entirety.
91
91
92
-
Otherwise, if the pointer's parent does not exist, a [`JSONPointerResolutionError`](../api/classes/jsonpointer.JSONPointerResolutionError.md) is thrown.
92
+
Otherwise, if the pointer's parent does not exist, a [`JSONPointerResolutionError`](../api/namespaces/jsonpointer/classes/JSONPointerResolutionError.md) is thrown.
93
93
94
94
## Utility methods
95
95
96
96
### `exists()`
97
97
98
-
Test for existence with [`JSONPointer.exists(data)`](../api/classes/jsonpointer.JSONPointer.md#exists). It returns `true` if the target exists in _data_, even if the target is falsy, and `false` otherwise.
98
+
Test for existence with [`JSONPointer.exists(data)`](../api/namespaces/jsonpointer/classes/JSONPointer.md#exists). It returns `true` if the target exists in _data_, even if the target is falsy, and `false` otherwise.
Build child pointers using [`JSONPointer.join(...tokens)`](../api/classes/jsonpointer.JSONPointer.md#join). It takes any number of JSON Pointer tokens and returns a new `JSONPointer`. Similar to joining a file system path, if a token has a leading slash, the previous pointer is ignored and a new `JSONPointer` is created, before processing of remaining tokens continues.
117
+
Build child pointers using [`JSONPointer.join(...tokens)`](../api/namespaces/jsonpointer/classes/JSONPointer.md#join). It takes any number of JSON Pointer tokens and returns a new `JSONPointer`. Similar to joining a file system path, if a token has a leading slash, the previous pointer is ignored and a new `JSONPointer` is created, before processing of remaining tokens continues.
Get a pointer to the parent of an existing JSON Pointer using [`JSONPointer.parent()`](../api/classes/jsonpointer.JSONPointer.md#parent). If the pointer is pointing to the document root, `this` is returned.
132
+
Get a pointer to the parent of an existing JSON Pointer using [`JSONPointer.parent()`](../api/namespaces/jsonpointer/classes/JSONPointer.md#parent). If the pointer is pointing to the document root, `this` is returned.
Use [Relative JSON Pointer](https://datatracker.ietf.org/doc/html/draft-hha-relative-json-pointer) syntax with [`JSONPointer.to(rel)`](../api/classes/jsonpointer.JSONPointer.md#to) to create a new pointer relative to an existing one.
161
+
Use [Relative JSON Pointer](https://datatracker.ietf.org/doc/html/draft-hha-relative-json-pointer) syntax with [`JSONPointer.to(rel)`](../api/namespaces/jsonpointer/classes/JSONPointer.md#to) to create a new pointer relative to an existing one.
Copy file name to clipboardExpand all lines: docs/docs/guides/jsonpath-extra.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
**_New in version 1.3.0_**
4
4
5
-
JSON P3 includes some extra, non-standard JSONPath syntax that is disabled by default. Setting the [`strict`](../api/namespaces/jsonpath.md#jsonpathenvironmentoptions) option to `false` when instantiating a [`JSONPathEnvironment`](../api/classes/jsonpath.JSONPathEnvironment.md) will enable all non-standard syntax.
5
+
JSON P3 includes some extra, non-standard JSONPath syntax that is disabled by default. Setting the [`strict`](../api/namespaces/jsonpath/type-aliases/JSONPathEnvironmentOptions) option to `false` when instantiating a [`JSONPathEnvironment`](../api/namespaces/jsonpath/classes/JSONPathEnvironment.md) will enable all non-standard syntax.
Return the value associated with the first node in _nodes_, if _nodes_ has exactly one [`JSONPathNode`](../api/classes/jsonpath.JSONPathNode.md). Usually, `value()` will be called with a [filter query](./jsonpath-syntax.md#filter-queries) as its argument.
61
+
Return the value associated with the first node in _nodes_, if _nodes_ has exactly one [`JSONPathNode`](../api/namespaces/jsonpath/classes/JSONPathNode.md). Usually, `value()` will be called with a [filter query](./jsonpath-syntax.md#filter-queries) as its argument.
62
62
63
63
:::info
64
64
[Filter queries](./jsonpath-syntax.md#filter-queries) that can result in at most one node are known as "singular queries", and all singular queries will be implicitly replaced with their value as required, without the use of `value()`. `value()` is useful when you need the value from a query that can, theoretically, return multiple nodes.
65
65
:::
66
66
67
67
## Well-typedness
68
68
69
-
The JSONPath specification defines a [type system for function expressions](https://datatracker.ietf.org/doc/html/rfc9535#name-type-system-for-function-ex), and rules for how those types can be used within an expression. JSON P3 will throw a [JSONPathTypeError](../api/classes/jsonpath.JSONPathTypeError.md) at query compile time if it contains expressions that are not deemed to be well-typed.
69
+
The JSONPath specification defines a [type system for function expressions](https://datatracker.ietf.org/doc/html/rfc9535#name-type-system-for-function-ex), and rules for how those types can be used within an expression. JSON P3 will throw a [JSONPathTypeError](../api/namespaces/jsonpath/classes/JSONPathTypeError.md) at query compile time if it contains expressions that are not deemed to be well-typed.
70
70
71
71
Please see [Section 2.4.3](https://datatracker.ietf.org/doc/html/rfc9535#name-well-typedness-of-function-)_Well-Typedness of Function Expressions_.
72
72
73
73
## Function extensions
74
74
75
-
Add, remove or replace [filter functions](./jsonpath-syntax.md#filter-functions) by updating the [function register](../api/classes/jsonpath.JSONPathEnvironment.md#functionregister) on a [`JSONPathEnvironment`](../api/classes/jsonpath.JSONPathEnvironment.md). It is a regular [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map), mapping function names to objects implementing the [`FilterFunction`](../api/interfaces/jsonpath.functions.FilterFunction.md) interface.
75
+
Add, remove or replace [filter functions](./jsonpath-syntax.md#filter-functions) by updating the [function register](../api/namespaces/jsonpath/classes/JSONPathEnvironment.md#functionregister) on a [`JSONPathEnvironment`](../api/namespaces/jsonpath/classes/JSONPathEnvironment.md). It is a regular [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map), mapping function names to objects implementing the [`FilterFunction`](../api/namespaces/jsonpath/namespaces/functions/interfaces/FilterFunction.md) interface.
76
76
77
77
:::info
78
78
You can update the function register on the _default environment_ (`import { DEFAULT_ENVIRONMENT } from "json-p3"`), and use convenience functions like [`query()`](../quick-start.md#jsonpath) and [`compile()`](../quick-start.md#compilation). Here we'll create a new `JSONPathEnvironment`, then use its methods directly.
79
79
:::
80
80
81
-
Every filter function must define the types of its parameters and the type of its return value, according to the JSONPath specification's [type system](https://datatracker.ietf.org/doc/html/rfc9535#name-type-system-for-function-ex). This example implements a `typeof()` function, which accepts a parameter of [`ValueType`](../api/enums/jsonpath.functions.FunctionExpressionType.md) and returns a `ValueType`.
81
+
Every filter function must define the types of its parameters and the type of its return value, according to the JSONPath specification's [type system](https://datatracker.ietf.org/doc/html/rfc9535#name-type-system-for-function-ex). This example implements a `typeof()` function, which accepts a parameter of [`ValueType`](../api/namespaces/jsonpath/namespaces/functions/enumerations/FunctionExpressionType.md) and returns a `ValueType`.
0 commit comments