Export the editing API of json_view from the C++20 module (#6090)

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann authored and GitHub committed 2026-11-11 22:32:29 +01:00
1 parent 1dae5a66b1
commit b5967d0ff9
3 files changed
+31 -1

No files matched your search

+7
View File
@@ -36,15 +36,21 @@ Only the following symbols are exported from `nlohmann.json`:
- `nlohmann::basic_json`
- `nlohmann::basic_json_document`
- `nlohmann::basic_json_view`
- `nlohmann::is_json_view`
- `nlohmann::json`
- `nlohmann::json_document`
- `nlohmann::json_editable_document`
- `nlohmann::json_editable_view`
- `nlohmann::json_pointer`
- `nlohmann::json_view`
- `nlohmann::ordered_json`
- `nlohmann::ordered_json_document`
- `nlohmann::ordered_json_editable_document`
- `nlohmann::ordered_json_editable_view`
- `nlohmann::ordered_json_view`
- `nlohmann::ordered_map`
- `nlohmann::to_string`
- `nlohmann::view_mode`
- `nlohmann::literals::json_literals::operator""_json`
- `nlohmann::literals::json_literals::operator""_json_pointer`
@@ -56,6 +62,7 @@ Additionally, the following `nlohmann::detail` symbols are exported, solely to w
and should not be used directly:
- `nlohmann::detail::json_sax_dom_callback_parser`
- `nlohmann::detail::json_sax_dom_parser`
- `nlohmann::detail::unknown_size`
## Known issues
+6
View File
@@ -36,15 +36,21 @@ using NLOHMANN_JSON_NAMESPACE::adl_serializer;
using NLOHMANN_JSON_NAMESPACE::basic_json;
using NLOHMANN_JSON_NAMESPACE::basic_json_document;
using NLOHMANN_JSON_NAMESPACE::basic_json_view;
using NLOHMANN_JSON_NAMESPACE::is_json_view;
using NLOHMANN_JSON_NAMESPACE::json;
using NLOHMANN_JSON_NAMESPACE::json_document;
using NLOHMANN_JSON_NAMESPACE::json_editable_document;
using NLOHMANN_JSON_NAMESPACE::json_editable_view;
using NLOHMANN_JSON_NAMESPACE::json_pointer;
using NLOHMANN_JSON_NAMESPACE::json_view;
using NLOHMANN_JSON_NAMESPACE::ordered_json;
using NLOHMANN_JSON_NAMESPACE::ordered_json_document;
using NLOHMANN_JSON_NAMESPACE::ordered_json_editable_document;
using NLOHMANN_JSON_NAMESPACE::ordered_json_editable_view;
using NLOHMANN_JSON_NAMESPACE::ordered_json_view;
using NLOHMANN_JSON_NAMESPACE::ordered_map;
using NLOHMANN_JSON_NAMESPACE::to_string;
using NLOHMANN_JSON_NAMESPACE::view_mode;
inline namespace literals
{
+18 -1
View File
@@ -56,9 +56,26 @@ int main()
const nlohmann::json_document doc = nlohmann::json_document::parse(R"({"a": 1, "list": [1, 2, 3]})");
const std::size_t doc_size = doc.root().size();
// editable documents and views, view_mode, is_json_view and the ordered variants
nlohmann::json_editable_document edoc = nlohmann::json_editable_document::parse(R"({"a": 1, "list": [1, 2, 3]})");
edoc.set(edoc.root(), "b", 2);
edoc.push_back(edoc.root()["list"], 4);
const nlohmann::json_editable_view eroot = edoc.root();
const std::size_t edit_size = eroot.size();
const std::size_t list_size = eroot["list"].size();
nlohmann::ordered_json_editable_document oedoc = nlohmann::ordered_json_editable_document::parse(R"({"z": 1, "y": 2})");
oedoc.erase(oedoc.root(), "z");
const nlohmann::ordered_json_editable_view oeroot = oedoc.root();
nlohmann::basic_json_document<nlohmann::json, nlohmann::view_mode::editable> mdoc = nlohmann::basic_json_document<nlohmann::json, nlohmann::view_mode::editable>::parse("[]");
mdoc.push_back(mdoc.root(), 1);
static_assert(nlohmann::is_json_view<nlohmann::json_view>::value, "json_view is a view");
static_assert(nlohmann::is_json_view<nlohmann::json_editable_view>::value, "json_editable_view is a view");
static_assert(!nlohmann::is_json_view<nlohmann::json>::value, "json is not a view");
// use every result so the references cannot be optimized away
return (a == 1 && last == 3 && b == 2 && lit.size() == 3
&& m.size() == 1 && !dumped.empty() && !os.str().empty()
&& doc_size == 2)
&& doc_size == 2
&& edit_size == 3 && list_size == 4 && oeroot.size() == 1 && mdoc.root().size() == 1)
? 0 : 1;
}