|
OXY API 1.0
OXY API Library Documentation
|
Functor to push an optional value into a JSON object. More...
#include <json_helper.hpp>
Public Member Functions | |
| template<class T> | |
| json::value & | operator() (json::value &jv, json::string_view key, std::optional< T > const &item) const |
Functor to push an optional value into a JSON object.
This functor provides an operator() that takes a JSON value, a key, and an optional item of a generic type T. It checks if the JSON value is an object, and if not, it emplaces an empty object. It then inserts or assigns the key-value pair in the JSON object, where the value is obtained by converting the item to a JSON value using json::value_from if the optional has a value, or json::value_from(nullptr) if the optional is empty. The functor returns a reference to the modified JSON value, allowing for chaining of operations.
|
inline |
| T | - The type of the item to be pushed into the JSON object. |
| jv | - The JSON value to modify. |
| key | - The key to set in the JSON object. |
| item | - The optional item to set in the JSON object. |