Commit Graph
1188 Commits
Author SHA1 Message Date
Niels Lohmann 6fc0d501f3 Move the user-defined string literals to <nlohmann/json_literals.hpp> and add JSON_NO_AUTOMATIC_UDLS (#5610)
* Add JSON_NO_UDLS to leave out the user-defined string literals

The bodies of operator""_json and operator""_json_pointer call the
parser, so every translation unit including the library instantiates it,
even if it never parses anything. Defining JSON_NO_UDLS leaves the
literals out entirely, which saves 15-35% compile time for such
translation units (#5294). Nothing changes if the macro is not defined.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Mention JSON_NO_UDLS in the list of exported module symbols

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Move the user-defined string literals to <nlohmann/json_literals.hpp>

Following the review in #5294, the literals now live in their own header
instead of being removed entirely: <nlohmann/json.hpp> includes it at the
end unless JSON_NO_AUTOMATIC_UDLS (renamed from JSON_NO_UDLS) is defined,
so a project can opt out globally and include the header only where the
literals are used.

The header only uses public and standard macros, because the library's
internal macros are undefined at the end of json.hpp and the amalgamation
inlines macro_scope.hpp only once. For the same reason, the library no
longer defines and undefines JSON_USE_GLOBAL_UDLS, so a user's definition
is still visible to the header. The single-header copy is identical to
the multi-header one, as it only includes <nlohmann/json.hpp>. The module
always exports the literals.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Fix CI: include cycle, GCC 4.8 literal operator spacing, and global UDLs off in the JSON_NO_AUTOMATIC_UDLS test

- Suppress clang-tidy misc-header-include-cycle on the intentional mutual
  include of json.hpp and json_literals.hpp.
- Use operator"" _json with a space for GCC 4.8 in the test's detection
  aliases, as the header does.
- Only test the global literal operators when JSON_USE_GLOBAL_UDLS is on.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Declare the literal operators through a local macro

The GCC 4.8 spacing condition was repeated for both operator definitions
and the global using-declarations. NLOHMANN_JSON_LITERAL_OPERATOR(suffix)
now selects operator""##suffix or operator"" suffix in one place and is
undefined at the end of json_literals.hpp.

Suggested by gregmarr in review.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-09-30 20:08:17 +02:00
Hariom Phulre bb5404bb86 Fix GCC C++20 modules compilation #5103 (#5164)
* Fix: Add GCC diagnostic pragmas for C++ modules support (issue #5103)

Signed-off-by: hariomphulre <hariiomphullre@gmail.com>

* Fix: GCC C++20 modules with __cplusplus >= 202002L check (#5103)

Signed-off-by: hariomphulre <hariiomphullre@gmail.com>

Signed-off-by: hariomphulre <hariiomphullre@gmail.com>

* Fix: Remove indentation from nested preprocessor directives and disable astyle preprocessor indentation

Signed-off-by: hariomphulre <hariiomphullre@gmail.com>

* Update amalgamated files with correct preprocessor directive indentation

Signed-off-by: hariomphulre <hariiomphullre@gmail.com>

* Fix GCC build for issue #5103; refresh amalgamated header

Signed-off-by: hariomphulre <hariiomphullre@gmail.com>

---------

Signed-off-by: hariomphulre <hariiomphullre@gmail.com>
2026-05-15 17:04:42 +02:00
Miko a64fc21243 Fix missing exports from json.cppm (#5137)
* Fix missing exports from `json.cppm`

Signed-off-by: Miko <110693261+mikomikotaishi@users.noreply.github.com>

* Update documentation to describe what symbols are exported

Signed-off-by: Miko <110693261+mikomikotaishi@users.noreply.github.com>

* Add mention of `std` symbols

Signed-off-by: Miko <110693261+mikomikotaishi@users.noreply.github.com>

* Add `json_literals` inline namespace to `using` statement

Signed-off-by: Miko <110693261+mikomikotaishi@users.noreply.github.com>

* Remove internals (`nlohmann::detail::*`) from module

Signed-off-by: Miko <110693261+mikomikotaishi@users.noreply.github.com>

* Omit internals (`nlohmann::detail::*`) from modules documentation

Signed-off-by: Miko <110693261+mikomikotaishi@users.noreply.github.com>

* Restore `nlohmann::detail` symbols with mention of the MSVC bug

Signed-off-by: Miko <110693261+mikomikotaishi@users.noreply.github.com>

---------

Signed-off-by: Miko <110693261+mikomikotaishi@users.noreply.github.com>
2026-05-08 06:57:50 +02:00
Bander 11cc676142 Improve MSVC C++ modules compatibility for nlohmann_json (#4952)
* Improve MSVC C++ modules compatibility for nlohmann_json

- Keep complete module interface with all exports
- Export all standard types: json, basic_json, adl_serializer, json_pointer, ordered_json, ordered_map
- Export detail namespace symbols for advanced usage
- Ensure compatibility with MSVC C++20/23 modules
- Maintain full functionality without breaking changes

Signed-off-by: yudaichen <250074249@qq.com>

* Add C++20 module Windows CI test and fix file ending

- Add ci_module_cpp20 job to Windows workflow to verify module support with MSVC

- Add missing newline at end of json.cppm file

Signed-off-by: yudaichen <250074249@qq.com>

---------

Signed-off-by: yudaichen <250074249@qq.com>
2025-10-24 11:34:11 +02:00
Miko a3211ab3ca Simplify module API (#4840)
* Simplify module API

Signed-off-by: Miko <110693261+mikomikotaishi@users.noreply.github.com>

* Forgot missing newline

Signed-off-by: Miko <110693261+mikomikotaishi@users.noreply.github.com>

---------

Signed-off-by: Miko <110693261+mikomikotaishi@users.noreply.github.com>
2025-08-03 10:02:12 +02:00
Miko b7f741165b Add proper C++20 module support (#4799) 2025-06-29 22:02:31 +02:00
Théo DELRIEU 14cd019861 fix cmake install directory (for real this time)
* Rename 'develop' folder to 'include/nlohmann'
* Rename 'src' folder to 'single_include/nlohmann'
* Use <nlohmann/*> headers in sources and tests
* Change amalgamate config file
2018-02-01 11:06:51 +01:00
Kaido aed4a080bf Templatize std::string in binary_reader #941 2018-01-31 23:01:01 -08:00
Niels Lohmann e8bf1f62f7 ✨ added define for library version #948 #943 2018-01-31 22:36:18 +01:00
Niels Lohmann 60e2d28eb7 🐛 fix for #947 2018-01-31 20:53:13 +01:00
Niels Lohmann ae235139b9 Merge pull request #940 from kaidokert/develop
Allow overriding THROW/CATCH/TRY macros with no-exceptions #938
2018-01-29 22:04:26 +01:00
Niels Lohmann 8049442c2a 🔨 rename yytext to token_buffer (fixes #933) 2018-01-29 21:56:13 +01:00
Kaido d0c9e5fffc Allow overriding THROW/CATCH/TRY macros with no-exceptions (redo) #938 2018-01-28 14:42:13 -08:00
Niels Lohmann cb4a9c85cb 🔨 excluded code from coverage 2018-01-28 17:55:40 +01:00
Niels Lohmann 1483d39c91 🔨 moved class json_pointer into separate file #920 2018-01-28 15:36:56 +01:00
Niels Lohmann 102c474397 🔨 clean up 2018-01-28 14:13:02 +01:00
Niels Lohmann 6855bbb902 🔨 split "parsing" directory to "input" and "output" 2018-01-28 13:15:03 +01:00
Niels Lohmann 1be3935e9d 📝 cleanup after #936 2018-01-27 17:43:44 +01:00
Niels Lohmann dbfd7e532b Merge branch 'develop' of https://github.com/nlohmann/json into develop 2018-01-23 16:33:10 +01:00
Niels Lohmann 3c68a796df 🔥 deprecated iterator_wrapper #874
Also fixed some warnings from GCC.
2018-01-23 16:33:08 +01:00
Niels Lohmann f5c4e9f3a1 Merge pull request #919 from theodelrieu/fix/sfinae_for_incomplete_types
fix sfinae on basic_json UDT constructor
2018-01-23 07:32:06 +01:00
Niels Lohmann 7eabb6ba36 📝 updated documentation for UBJSON functions 2018-01-22 23:23:17 +01:00
Niels Lohmann 3cca630836 🔨 cleanup after #915 2018-01-21 15:55:35 +01:00
Niels Lohmann 010e596001 Merge pull request #915 from abolz/dtoa
Floating-point formatting
2018-01-21 15:02:57 +01:00
Niels Lohmann 9e5d901f55 Merge branch 'feature/ubjson' into develop 2018-01-21 14:04:29 +01:00
Niels Lohmann 327b8bb09e Merge branch 'feature/strings' into develop 2018-01-21 13:55:52 +01:00
Niels Lohmann a8f711a2f1 ➕ using Google Benchmark #921 2018-01-18 21:57:21 +01:00
Théo DELRIEU dcee778c1e fix sfinae on basic_json UDT constructor
Avoid compiler errors when performing SFINAE checks on basic_json
and incomplete types.
2018-01-17 12:17:38 +01:00
Niels Lohmann 7456f1d87b ♻️ re-used existing UTF-8 decoder to simplfy string serialization 2018-01-16 20:42:00 +01:00
abolz 9b9919d460 Use max_digits10 in dump_float for float->text->float round-trip 2018-01-15 21:26:03 +01:00
abolz 810f81bbd9 Regenerate src/json.hpp 2018-01-15 21:24:59 +01:00
Niels Lohmann 9d6b3731b9 ✅ improved test coverage 2018-01-14 20:07:38 +01:00
Niels Lohmann f85f4967fe ✅ improved test coverage 2018-01-14 17:22:06 +01:00
Niels Lohmann 541b46132d ♻️ adjusted code to split headers 2018-01-14 10:34:43 +01:00
Niels Lohmann 0e8f01a963 Merge branch 'develop' into feature/rfc7396 2018-01-14 10:28:09 +01:00
Niels Lohmann c772c01a48 ♻️ refactored code to split headers 2018-01-14 10:27:30 +01:00
Niels Lohmann 1b54d4a5aa Merge branch 'develop' into feature/ubjson 2018-01-14 10:10:56 +01:00
Niels Lohmann 241eea0c0e 📝 documentation 2018-01-12 09:23:33 +01:00
Niels Lohmann 3a7585e738 ✅ added more tests 2018-01-10 22:47:07 +01:00
Niels Lohmann 31bfabc4c0 🔨 optimized input format 2018-01-10 16:14:43 +01:00
Niels Lohmann 965a70e38d 🔨 optimized output format 2018-01-10 11:22:19 +01:00
Niels Lohmann 85173f5627 🔨 some clean up 2018-01-10 10:18:31 +01:00
Niels Lohmann ce53537ba2 ➖ ➕ replaces amalgamation tool
The tool used before created a lot of duplicates inside the generated amalgamation. The new tool is a single Python file which seems to do the same job.
2018-01-09 23:15:06 +01:00
Niels Lohmann 0a2920e0fd ♻️ reorganized code 2018-01-09 18:30:02 +01:00
Niels Lohmann fd04967676 🐛 fixed copy-paste error 2018-01-08 21:37:51 +01:00
Théo DELRIEU 57d822b6e2 add missing includes, put back include comments 2018-01-08 20:09:41 +01:00
Théo DELRIEU 9cab30cfce add adl_serializer.hpp 2018-01-08 20:09:38 +01:00
Théo DELRIEU 8e9714fe3d add detail/json_ref.hpp 2018-01-08 20:09:35 +01:00
Théo DELRIEU a3473fda6a add detail/serializer.hpp 2018-01-08 20:09:33 +01:00
Théo DELRIEU c117515e31 add detail/parsing/binary_writer.hpp 2018-01-08 20:09:29 +01:00