Closed mohitmv closed 4 years ago
The Json
object is immutable by design, which has its own set of benefits particularly around safety and concurrency. That said, there's nothing stopping you from extracting the map of keys to values and mutating it freely (the Json::object
type is a map) then wrapping it back in a Json object when you're done. Something like this (not compiled, so meant to be demonstrative not fully correct):
auto mutable_map = json_obj.object_items()
mutable_map["a"] = Json(1);
json_obj = Json(std::move(mutable_map))
It will be highly useful if you make object_items() and array_items() not-const reference. or if you support
mutable_object_items()
?Thanks.