...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Set an element via JSON Pointer.
boost::system::result
<value
& > try_set_at_pointer(string_view
sv,value_ref
ref,set_pointer_options
const& opts = {});
This function is used to insert or assign to a potentially nested element of the value using a JSON Pointer string. The function may create intermediate elements corresponding to pointer segments.
The particular conditions when and what kind of intermediate element is
created is governed by the ptr
parameter.
Each pointer token is considered in sequence. For each token
object
, then a new null
element is created with key
equal to unescaped token string; otherwise
array
, and the token represents
a past-the-end marker, then a null
element is appended to the array; otherwise
array
, and the token represents
a number, then if the difference between the number and array's size
is smaller than opts.max_created_elements
,
then the size of the array is increased, so that the number can reference
an element in the array; otherwise
kind
and opts.replace_any_scalar
is true
, or the value
is null
, then
opts.create_arrays
is true
and the token either represents
past-the-end marker or a number, then the value is replaced with
an empty array and the token is considered again; otherwise
opts.create_objects
is true
, then the value is replaced
with an empty object and the token is considered again; otherwise
Linear in the sum of size of ptr
,
size of underlying array, object, or string and opts.max_created_elements
.
Basic guarantee. Calls to memory_resource::allocate
may throw.
Name |
Description |
---|---|
|
JSON Pointer string. |
|
The value to assign to pointed element. |
|
The options for the algorithm. |
boost::json::result<value&>
containing either a reference to the element identified by ptr
or a corresponding error_code
.
set_pointer_options
, RFC
6901 - JavaScript Object Notation (JSON) Pointer.