Export json_document and json_view from the C++20 module

The nlohmann.json module includes json_view.hpp in its global module
fragment and exports basic_json_document, basic_json_view, and the four
aliases next to basic_json, json, and ordered_json. features/modules.md
lists them, and tests/module_cpp20 parses a document, so that a missing
export fails the ci_module_cpp20 job.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann committed 2026-09-30 15:07:19 +02:00
1 parent ca8c82fa68
commit 440383d20e
3 files changed
+19 -1

No files matched your search

+6
View File
@@ -32,9 +32,15 @@ Only the following symbols are exported from `nlohmann.json`:
- `nlohmann::adl_serializer` - `nlohmann::adl_serializer`
- `nlohmann::basic_json` - `nlohmann::basic_json`
- `nlohmann::basic_json_document`
- `nlohmann::basic_json_view`
- `nlohmann::json` - `nlohmann::json`
- `nlohmann::json_document`
- `nlohmann::json_pointer` - `nlohmann::json_pointer`
- `nlohmann::json_view`
- `nlohmann::ordered_json` - `nlohmann::ordered_json`
- `nlohmann::ordered_json_document`
- `nlohmann::ordered_json_view`
- `nlohmann::ordered_map` - `nlohmann::ordered_map`
- `nlohmann::to_string` - `nlohmann::to_string`
- `nlohmann::literals::json_literals::operator""_json` - `nlohmann::literals::json_literals::operator""_json`
+7
View File
@@ -18,6 +18,7 @@ module;
// See: https://github.com/nlohmann/json/issues/5103 // See: https://github.com/nlohmann/json/issues/5103
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <nlohmann/json_view.hpp>
export module nlohmann.json; export module nlohmann.json;
@@ -26,9 +27,15 @@ NLOHMANN_JSON_NAMESPACE_BEGIN
using NLOHMANN_JSON_NAMESPACE::adl_serializer; using NLOHMANN_JSON_NAMESPACE::adl_serializer;
using NLOHMANN_JSON_NAMESPACE::basic_json; using NLOHMANN_JSON_NAMESPACE::basic_json;
using NLOHMANN_JSON_NAMESPACE::basic_json_document;
using NLOHMANN_JSON_NAMESPACE::basic_json_view;
using NLOHMANN_JSON_NAMESPACE::json; using NLOHMANN_JSON_NAMESPACE::json;
using NLOHMANN_JSON_NAMESPACE::json_document;
using NLOHMANN_JSON_NAMESPACE::json_pointer; using NLOHMANN_JSON_NAMESPACE::json_pointer;
using NLOHMANN_JSON_NAMESPACE::json_view;
using NLOHMANN_JSON_NAMESPACE::ordered_json; using NLOHMANN_JSON_NAMESPACE::ordered_json;
using NLOHMANN_JSON_NAMESPACE::ordered_json_document;
using NLOHMANN_JSON_NAMESPACE::ordered_json_view;
using NLOHMANN_JSON_NAMESPACE::ordered_map; using NLOHMANN_JSON_NAMESPACE::ordered_map;
using NLOHMANN_JSON_NAMESPACE::to_string; using NLOHMANN_JSON_NAMESPACE::to_string;
+6 -1
View File
@@ -52,8 +52,13 @@ int main()
std::ostringstream os; std::ostringstream os;
os << j << oj << lit; os << j << oj << lit;
// json_document / json_view (json_view.hpp): zero-copy parse of a literal
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();
// use every result so the references cannot be optimized away // use every result so the references cannot be optimized away
return (a == 1 && last == 3 && b == 2 && lit.size() == 3 return (a == 1 && last == 3 && b == 2 && lit.size() == 3
&& m.size() == 1 && !dumped.empty() && !os.str().empty()) && m.size() == 1 && !dumped.empty() && !os.str().empty()
&& doc_size == 2)
? 0 : 1; ? 0 : 1;
} }