Class to create JSON Patch (RFC-6902).
More...
#include "nn/nlib/msgpack/JsonPatch.h"
Class to create JSON Patch (RFC-6902).
- Description
- Instantiates the object and then constructs a JSON Patch document using
Add()
, Remove()
, Replace()
, Move()
, Copy()
, or Test()
. Each of these member functions corresponds to the "add," "remove," "replace," "move," "copy," or "test" operation defined in RFC-6902. When the JSON Patch document has been constructed, it is output as MpObject
using Export()
. The output JSON Patch document can be applied using JsonPatch::Apply()
.
- See also
- https://tools.ietf.org/html/rfc6902
-
https://triple-underscore.github.io/RFC6902-ja.html
Definition at line 29 of file JsonPatch.h.
◆ Add()
Adds an "add" operation to the array that serves as the JSON Patch document.
- Parameters
-
[in] | path | A JSON Pointer string that indicates a location where value is set in the JSON document. |
[in] | value | The value being set. |
- Return values
-
0 | Success. |
ENOMEM | Indicates that the memory allocation has failed. |
- Description
- The "add" operation performs one of the following operations on the location indicated by path in the JSON document.
-
If path is an empty string, the entire JSON document is replaced with value.
-
If path indicates an array index, new value is inserted into the position of that index. If the end of the array is '-,' value is appended to the array end.
-
If no key is found at the end of path, value is appended to that end as a value referenced as the key.
-
If a value that serves as the key for path has been found, that value is replaced with value.
Definition at line 34 of file JsonPatch.h.
◆ Copy()
Adds a "copy" operation to the array that serves as the JSON Patch document.
- Parameters
-
[in] | path | A JSON Pointer string that indicates a location to copy to in the JSON document. |
[in] | from | A JSON Pointer string that indicates a location to copy from in the JSON document. |
- Return values
-
0 | Success. |
ENOMEM | Indicates that the memory allocation has failed. |
- Description
- The "copy" operation is equivalent to an operation where an "add" operation appends a value specified by from by specifying path. The location from represents needs to be described in the target JSON document before doing this operation.
Definition at line 45 of file JsonPatch.h.
◆ Export()
nn::nlib::msgpack::JsonPatchBuilder::Export |
( |
MpObject * |
patch | ) |
|
|
noexcept |
Retrieves a JSON document that serves as JSON Patch.
- Parameters
-
[in] | patch | MpObject that contains the JSON document that serves as JSON Patch. |
- Return values
-
0 | Success. |
ENOMEM | Indicates that the memory allocation has failed. |
- Description
- The retrieved JSON Patch document is stored in patch. The data stored in patch is deleted, and
JsonPatchBuilder
is set to the same state as when immediately after the constructor was executed. ENOMEM
may be returned only when no operation has been added.
◆ Move()
Adds a "move" operation to the array that serves as the JSON Patch document.
- Parameters
-
[in] | path | A JSON Pointer string that indicates a location to move to in the JSON document. |
[in] | from | A JSON Pointer string that indicates a location to move from in the JSON document. |
- Return values
-
0 | Success. |
ENOMEM | Indicates that the memory allocation has failed. |
- Description
- The "move" operation is equivalent to a set of operations where a "remove" operation removes a value by specifying from and then an "add" operation appends that value by specifying path. The location from represents needs to be described in the target JSON document before doing this operation.
Definition at line 41 of file JsonPatch.h.
◆ Remove()
nn::nlib::msgpack::JsonPatchBuilder::Remove |
( |
const nlib_utf8_t * |
path | ) |
|
|
noexcept |
Adds a "remove" operation to the array that serves as the JSON Patch document.
- Parameters
-
[in] | path | A JSON Pointer string that indicates a location to be deleted in the JSON document. |
- Return values
-
0 | Success. |
ENOMEM | Indicates that the memory allocation has failed. |
- Description
- The "remove" operation deletes the location indicated by path in the JSON document. The location path represents needs to be described in the target JSON document before doing this operation. The details are as follows:
-
If path is an empty string, the entire JSON document is deleted.
-
If path indicates an array index, elements before the specified index are moved forward one by one.
-
Otherwise, the value specified by path and the key that directly indicates that value are removed.
◆ Test()
Adds a "test" operation to the array that serves as the JSON Patch document.
- Parameters
-
[in] | path | A JSON Pointer string that indicates a location where an operation is performed in the JSON document. |
[in] | value | A value to be compared. |
- Return values
-
0 | Success. |
ENOMEM | Indicates that the memory allocation has failed. |
- Description
- The "test" operation compares the value specified by path with value. When the both values are equivalent in terms of JSON, the "test" operation is evaluated for success.
Definition at line 49 of file JsonPatch.h.
The documentation for this class was generated from the following files: