Compare commits

...

35 Commits

Author SHA1 Message Date
Niels Lohmann
8e8b1b4883 Detect used C++ standard library (#4793)
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2025-05-25 16:20:37 +02:00
Kuan-Fu, Wu
39c59b89be doc: Fix JSON Pointer example to use direct initialization (#4468)
Changed the example code in the documentation from copy initialization
to direct initialization for `json::json_pointer`.
This prevents compilation errors caused by the constructor being explicit.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2025-05-25 16:20:36 +02:00
Niels Lohmann
c4c1820c47 # This is a combination of 5 commits.
# This is the 1st commit message:

 add test for #4440

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

# Conflicts:
#	tests/src/unit-regression2.cpp

# This is the commit message #2:

 add test for #4440

# This is the commit message #3:

 add test for #4440

# This is the commit message #4:

 add test for #4440

# This is the commit message #5:

 add test for #4440

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2025-05-25 16:20:35 +02:00
Niels Lohmann
6cbf2b205a # This is a combination of 3 commits.
# This is the 1st commit message:

 add test for #4440

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

# Conflicts:
#	tests/src/unit-regression2.cpp

# This is the commit message #2:

 add test for #4440

# This is the commit message #3:

 add test for #4440

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2025-05-25 16:20:34 +02:00
Niels Lohmann
b4a5a4fbbc # This is a combination of 2 commits.
# This is the 1st commit message:

 add test for #4440

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

# Conflicts:
#	tests/src/unit-regression2.cpp

# This is the commit message #2:

 add test for #4440

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2025-05-25 16:20:34 +02:00
chirsz
4b17f90f65 Add ignore_trailing_commas option (#4609)
Added examples and modified the corresponding documents and unit tests.

Signed-off-by: chirsz-ever <chirsz-ever@outlook.com>
Co-authored-by: Niels Lohmann <niels.lohmann@gmail.com>
2025-05-22 08:01:46 +02:00
dependabot[bot]
2d9a251266 ⬆️ Bump srvaroa/labeler (#4789) 2025-05-20 17:56:25 +02:00
dependabot[bot]
3cca3ad210 ⬆️ Bump github/codeql-action from 3.28.17 to 3.28.18 (#4787)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.17 to 3.28.18.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](60168efe1c...ff0a06e83c)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 3.28.18
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-05-16 19:55:33 +02:00
Niels Lohmann
828c891427 Extend type_name() to invalid type (#4786)
*  add regression test

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

* 💚 fix build

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

* 📝 add comment

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

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2025-05-16 18:16:47 +02:00
NmPassTHFan
46e7cd3dc2 Replace deprecated std::is_trivial in C++26 (#4775) 2025-05-16 16:11:44 +02:00
Niels Lohmann
6f6be39332 Add GCC 15.1.0 flags (#4766)
* 🔧 add GCC 15.1.0 flags

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

* 🔧 add GCC 15.1.0 flags

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

* 🔧 add GCC 15.1.0 flags

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

* 🚨 suppress -Wstrict-overflow warning

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

* 🚨 suppress -Wstrict-overflow warning

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

* 🚨 suppress -Wstrict-overflow warning

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

* 🚨 suppress -Wstrict-overflow warning

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

* 🚨 fix -Wstrict-overflow warning

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

* 🚨 fix -Wstrict-overflow warning

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

* 🚨 fix warnings

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

* 🚨 fix warnings

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

* 🎨 fix format

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

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2025-05-16 08:32:18 +02:00
Niels Lohmann
e02de2f971 Update to Doctest 2.4.12 (#4771)
* ⬆️ Doctest 2.4.12

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

* 🚨 fix warnings

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

* 🚨 fix warnings

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

* 🚨 fix warnings

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

* 🚨 fix warnings

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

* 🚨 fix warnings

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

* 🚨 fix warnings

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

* 🚨 fix warnings

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

* 🚨 fix warnings

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

* 🚨 fix warnings

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

* 🚨 fix warnings

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

* 🚨 fix warnings

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

* 🚨 fix warnings

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

* 🚨 fix warnings

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

* 🚨 fix warnings

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

* 🚨 fix warnings

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

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2025-05-15 19:25:27 +02:00
dependabot[bot]
410c96228c ⬆️ Bump mkdocs-material from 9.6.12 to 9.6.14 in /docs/mkdocs (#4783)
Bumps [mkdocs-material](https://github.com/squidfunk/mkdocs-material) from 9.6.12 to 9.6.14.
- [Release notes](https://github.com/squidfunk/mkdocs-material/releases)
- [Changelog](https://github.com/squidfunk/mkdocs-material/blob/master/CHANGELOG)
- [Commits](https://github.com/squidfunk/mkdocs-material/compare/9.6.12...9.6.14)

---
updated-dependencies:
- dependency-name: mkdocs-material
  dependency-version: 9.6.14
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-05-15 19:24:00 +02:00
dependabot[bot]
4e518d43d7 ⬆️ Bump actions/dependency-review-action from 4.7.0 to 4.7.1 (#4785)
Bumps [actions/dependency-review-action](https://github.com/actions/dependency-review-action) from 4.7.0 to 4.7.1.
- [Release notes](https://github.com/actions/dependency-review-action/releases)
- [Commits](38ecb5b593...da24556b54)

---
updated-dependencies:
- dependency-name: actions/dependency-review-action
  dependency-version: 4.7.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-05-15 19:23:51 +02:00
dependabot[bot]
230bfd15a2 ⬆️ Bump actions/dependency-review-action from 4.6.0 to 4.7.0 (#4779)
Bumps [actions/dependency-review-action](https://github.com/actions/dependency-review-action) from 4.6.0 to 4.7.0.
- [Release notes](https://github.com/actions/dependency-review-action/releases)
- [Commits](ce3cf9537a...38ecb5b593)

---
updated-dependencies:
- dependency-name: actions/dependency-review-action
  dependency-version: 4.7.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-05-10 10:32:19 +02:00
dependabot[bot]
e9391dc5bc ⬆️ Bump lukka/get-cmake from 4.0.1 to 4.02 (#4777)
Bumps [lukka/get-cmake](https://github.com/lukka/get-cmake) from 4.0.1 to 4.02.
- [Release notes](https://github.com/lukka/get-cmake/releases)
- [Commits](57c20a23a6...ea00481682)

---
updated-dependencies:
- dependency-name: lukka/get-cmake
  dependency-version: '4.02'
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-05-08 17:09:01 +02:00
dependabot[bot]
697c7e557c ⬆️ Bump github/codeql-action from 3.28.16 to 3.28.17 (#4774)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.16 to 3.28.17.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](28deaeda66...60168efe1c)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 3.28.17
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-05-04 10:28:46 +02:00
Niels Lohmann
9110918cf8 Fix typos (#4748)
* ✏️ fix typos

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

* ✏️ address review comments

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

* ✏️ address review comments

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

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2025-05-04 10:28:24 +02:00
Niels Lohmann
0a8b48ac6a Add comment regarding #4767 (#4770)
* 💡 add comment regarding #4767

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

* ✏️ address review comments

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

* ✏️ address review comments

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

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2025-05-04 10:27:58 +02:00
Ville Vesilehto
dff2b4756c fix: BJData size calculation overflow (#4765)
Adds pre-multiplication overflow detection to catch cases where dimension
products would exceed size_t max. The previous check only detected when
overflow resulted in exactly 0 or SIZE_MAX, missing other cases.

Retains the original post-multiplication check for backward compatibility.
Adds tests verifying overflow detection with dimensions (2^32+1)×(2^32),
which previously overflowed silently to 2^32.

This prevents custom SAX handlers from receiving incorrect array sizes
that could lead to buffer overflows.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
2025-04-29 10:17:50 +02:00
Niels Lohmann
eef76c200e Make library work with C++20 modules (#4764)
*  add test for C++20 modules

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

* 🚨 fix warning

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

* Add missing header (#4763)

* 🐛 add missing header

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

* 🚨 fix warning

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

* 🚨 fix warning

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

---------

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

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2025-04-28 21:52:26 +02:00
Xiaochuan Ye
3b02afb9d9 Specialize char_traits for std::byte to fix from_msgpack (fixes #4756) (#4760)
* Specialize char_traits for std::byte to fix from_msgpack (fixes #4756)

Provide a char_traits<std::byte> specialization under __cpp_lib_byte
to allow parsing MessagePack data from containers of std::byte.

Signed-off-by: xuesongtap <tap91624@gmail.com>
Signed-off-by: yexiaochuan <tap91624@gmail.com>

* Fix comments for cstddef include and MessagePack tests

Signed-off-by: xuesongtap <tap91624@gmail.com>
Signed-off-by: yexiaochuan <tap91624@gmail.com>

* Fix include <cstddef> only when __cpp_lib_byte is defined and sufficient

Signed-off-by: yexiaochuan <tap91624@gmail.com>

* Fix clang-tidy warnings in MessagePack std::byte tests

Signed-off-by: yexiaochuan <tap91624@gmail.com>

* Fix handle return value in MessagePack tests

Signed-off-by: yexiaochuan <tap91624@gmail.com>

---------

Signed-off-by: xuesongtap <tap91624@gmail.com>
Signed-off-by: yexiaochuan <tap91624@gmail.com>
2025-04-28 16:19:47 +02:00
Niels Lohmann
6b9199382b Add missing header (#4763)
* 🐛 add missing header

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

* 🚨 fix warning

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

* 🚨 fix warning

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

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2025-04-27 18:18:57 +02:00
dependabot[bot]
51a77f1dca ⬆️ Bump github/codeql-action from 3.28.15 to 3.28.16 (#4757) 2025-04-23 18:37:41 +02:00
Sergiu Deitsch
756ca22ec5 Provide fallback for missing char8_t support (#4736) 2025-04-23 18:36:41 +02:00
dependabot[bot]
85df7ed593 ⬆️ Bump mkdocs-material from 9.6.11 to 9.6.12 in /docs/mkdocs (#4750)
Bumps [mkdocs-material](https://github.com/squidfunk/mkdocs-material) from 9.6.11 to 9.6.12.
- [Release notes](https://github.com/squidfunk/mkdocs-material/releases)
- [Changelog](https://github.com/squidfunk/mkdocs-material/blob/master/CHANGELOG)
- [Commits](https://github.com/squidfunk/mkdocs-material/compare/9.6.11...9.6.12)

---
updated-dependencies:
- dependency-name: mkdocs-material
  dependency-version: 9.6.12
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-04-23 13:14:34 +02:00
dependabot[bot]
2be2c83d5c ⬆️ Bump step-security/harden-runner from 2.11.1 to 2.12.0 (#4754) 2025-04-22 18:56:49 +02:00
Niels Lohmann
c67d538274 Fix C4702 warning and extend MSVC CI job (#4749)
* ⚗️ try matrix for latest

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

* ♻️ refactor from https://github.com/nlohmann/json/issues/4745#issuecomment-2810128420

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

* 👷 simplify CI

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

* 👷 simplify CI

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

* 🚨 fix cpplint warning

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

* 👷 simplify CI

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

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2025-04-17 18:04:09 +02:00
Niels Lohmann
88c92e605c Fix compilation failure and warnings with NVHPC (#4744)
* 🚨 fix warnings

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

* 🚨 fix warnings

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

* ⚗️ enable ranges support

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

* 🔥 remove ci_nvhpc job

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

* ⚗️ enable ranges support

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

* 🔥 remove ci_nvhpc job

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

* 🚨 fix warning

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

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2025-04-16 16:09:21 +02:00
Niels Lohmann
96c1b52f1c Fix conversion to std::optional (#4742)
* ⚗️ remove JSON_USE_IMPLICIT_CONVERSIONS check for from_json(json, std::optional)

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

* ⚗️ remove JSON_USE_IMPLICIT_CONVERSIONS check for from_json(json, std::optional)

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

* ⚗️ remove JSON_USE_IMPLICIT_CONVERSIONS check for from_json(json, std::optional)

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

* ⚗️ remove JSON_USE_IMPLICIT_CONVERSIONS check for from_json(json, std::optional)

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

* ⚗️ remove JSON_USE_IMPLICIT_CONVERSIONS check for from_json(json, std::optional)

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

* ⚗️ add C++ standard library as matrix option

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

*  remove inline

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

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2025-04-15 16:10:39 +02:00
Niels Lohmann
4cca3b9cb2 Fix warning and add emscripten CI step (#4738)
* 🚨 fix warning

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

* 👷 add emscripten

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

* 👷 add emscripten

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

* 👷 add emscripten

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

* 👷 add emscripten

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

* 👷 add emscripten

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

* 👷 add emscripten

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

* 👷 add emscripten

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

* 👷 add emscripten

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

* 👷 add emscripten

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

* 📝 add compiler to list

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

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2025-04-13 17:54:56 +02:00
dependabot[bot]
93e957332b ⬆️ Bump lukka/get-cmake from 4.0.0 to 4.0.1 (#4735)
Bumps [lukka/get-cmake](https://github.com/lukka/get-cmake) from 4.0.0 to 4.0.1.
- [Release notes](https://github.com/lukka/get-cmake/releases)
- [Commits](28983e0d39...57c20a23a6)

---
updated-dependencies:
- dependency-name: lukka/get-cmake
  dependency-version: 4.0.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-04-12 10:31:40 +02:00
dependabot[bot]
7ddea2686f ⬆️ Bump cpplint from 2.0.1 to 2.0.2 in /cmake/requirements (#4728)
Bumps [cpplint](https://github.com/cpplint/cpplint) from 2.0.1 to 2.0.2.
- [Release notes](https://github.com/cpplint/cpplint/releases)
- [Changelog](https://github.com/cpplint/cpplint/blob/develop/CHANGELOG.rst)
- [Commits](https://github.com/cpplint/cpplint/compare/2.0.1...2.0.2)

---
updated-dependencies:
- dependency-name: cpplint
  dependency-version: 2.0.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-04-11 10:56:23 +02:00
dependabot[bot]
2b876ee671 ⬆️ Bump github/codeql-action from 3.28.14 to 3.28.15 (#4729)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.14 to 3.28.15.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](fc7e4a0fa0...45775bd823)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 3.28.15
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-04-11 10:56:15 +02:00
Niels Lohmann
1705bfe914 🔖 set version to 3.12.0 (#4727)
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2025-04-11 10:41:14 +02:00
223 changed files with 1986 additions and 1159 deletions

View File

@@ -1,7 +1,7 @@
# Contribution Guidelines # Contribution Guidelines
Thank you for your interest in contributing to this project! What began as an exercise to explore the exciting features Thank you for your interest in contributing to this project! What began as an exercise to explore the exciting features
of C++11 has evolved into a [widely-used](https://json.nlohmann.me/home/customers/) JSON library. I truly appreciate all of C++11 has evolved into a [widely used](https://json.nlohmann.me/home/customers/) JSON library. I truly appreciate all
the contributions from the community, whether it's proposing features, identifying bugs, or fixing mistakes! To ensure the contributions from the community, whether it's proposing features, identifying bugs, or fixing mistakes! To ensure
that our collaboration is efficient and effective, please follow these guidelines. that our collaboration is efficient and effective, please follow these guidelines.
@@ -21,7 +21,7 @@ Clearly describe the issue:
- If it is a bug, please describe how to **reproduce** it. If possible, attach a _complete example_ which demonstrates - If it is a bug, please describe how to **reproduce** it. If possible, attach a _complete example_ which demonstrates
the error. Please also state what you **expected** to happen instead of the error. the error. Please also state what you **expected** to happen instead of the error.
- If you propose a change or addition, try to give an **example** how the improved code could look like or how to use - If you propose a change or addition, try to give an **example** what the improved code could look like or how to use
it. it.
- If you found a compilation error, please tell us which **compiler** (version and operating system) you used and paste - If you found a compilation error, please tell us which **compiler** (version and operating system) you used and paste
the (relevant part of) the error messages to the ticket. the (relevant part of) the error messages to the ticket.
@@ -66,21 +66,21 @@ certification that he or she has the right to submit the patch for inclusion int
### Describe your changes ### Describe your changes
This library is primarily maintained as a spare-time project. As such, I can not make any guarantee how quickly changes This library is primarily maintained as a spare-time project. As such, I cannot make any guarantee how quickly changes
are merged and released. Therefore, it is very important to make the review as smooth as possible by explaining not only are merged and released. Therefore, it is very important to make the review as smooth as possible by explaining not only
_what_ you changed, but _why_. This rationale can be very valuable down the road when improvements or bugs are discussed _what_ you changed, but _why_. This rationale can be very valuable down the road when improvements or bugs are discussed
years later. years later.
### Reference existing issues ### Reference an existing issue
[Link a pull request to an issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/linking-a-pull-request-to-an-issue) [Link a pull request to an issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/linking-a-pull-request-to-an-issue)
to clarify that a fix is forthcoming and which issue can be closed after merging. Only few cases (e.g., fixing typos) to clarify that a fix is forthcoming and which issue can be closed after merging. Only a few cases (e.g., fixing typos)
dont require prior discussions. do not require prior discussions.
### Write tests ### Write tests
The library has an extensive test suite that currently covers [100 %](https://coveralls.io/github/nlohmann/json) of the The library has an extensive test suite that currently covers [100 %](https://coveralls.io/github/nlohmann/json) of the
library's code. These test are crucial to maintain API stability and give future contributors confidence that they do library's code. These tests are crucial to maintain API stability and give future contributors confidence that they do
not accidentally break things. As Titus Winters aptly put it: not accidentally break things. As Titus Winters aptly put it:
> If you liked it, you should have put a test on it. > If you liked it, you should have put a test on it.
@@ -118,14 +118,14 @@ exception into account.
#### Coverage #### Coverage
If test coverage decreases, an automatic warning comment will be posted on the pull request. You can access a code If test coverage decreases, an automatic warning comment will be posted on the pull request. You can access a code
coverage report as artifact to the “Ubuntu” workflow. coverage report as an artifact to the “Ubuntu” workflow.
### Update the documentation ### Update the documentation
The [main documentation](https://json.nlohmann.me) of the library is generated from the files The [main documentation](https://json.nlohmann.me) of the library is generated from the files
[`docs/mkdocs/docs`](https://github.com/nlohmann/json/blob/develop/docs/mkdocs/docs). This folder contains dedicated [`docs/mkdocs/docs`](https://github.com/nlohmann/json/blob/develop/docs/mkdocs/docs). This folder contains dedicated
pages for [certain features](https://github.com/nlohmann/json/tree/develop/docs/mkdocs/docs/features), a list of pages for [certain features](https://github.com/nlohmann/json/tree/develop/docs/mkdocs/docs/features), a list of
[all exceptions](https://github.com/nlohmann/json/blob/develop/docs/mkdocs/docs/home/exceptions.md), and an [all exceptions](https://github.com/nlohmann/json/blob/develop/docs/mkdocs/docs/home/exceptions.md), and
[extensive API documentation](https://github.com/nlohmann/json/tree/develop/docs/mkdocs/docs/api) with details on every [extensive API documentation](https://github.com/nlohmann/json/tree/develop/docs/mkdocs/docs/api) with details on every
public API function. public API function.
@@ -136,7 +136,7 @@ make install_venv -C docs/mkdocs
make serve -C docs/mkdocs make serve -C docs/mkdocs
``` ```
The documentation will then available at <http://127.0.0.1:8000/>. See the documentation of The documentation will then be available at <http://127.0.0.1:8000/>. See the documentation of
[mkdocs](https://www.mkdocs.org) and [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/) for more [mkdocs](https://www.mkdocs.org) and [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/) for more
information. information.
@@ -184,8 +184,8 @@ API of the 3.x.y version is broken. This includes:
Although these guidelines may seem restrictive, they are essential for maintaining the librarys utility. Although these guidelines may seem restrictive, they are essential for maintaining the librarys utility.
Breaking changes may be introduced when they are guarded with a feature macro such as Breaking changes may be introduced when they are guarded with a feature macro such as
[`JSON_USE_IMPLICIT_CONVERSIONS`](https://json.nlohmann.me/api/macros/json_use_implicit_conversions/) which allows to [`JSON_USE_IMPLICIT_CONVERSIONS`](https://json.nlohmann.me/api/macros/json_use_implicit_conversions/) which allows
selectively change the behavior of the library. In next steps, the current behavior can then be deprecated. Using selectively changing the behavior of the library. In next steps, the current behavior can then be deprecated. Using
feature macros then allows users to test their code against the library in the next major release. feature macros then allows users to test their code against the library in the next major release.
### Break C++11 language conformance ### Break C++11 language conformance
@@ -211,7 +211,7 @@ The following areas really need contribution and are always welcomed:
- Extending the **continuous integration** toward more exotic compilers such as Android NDK, Intel's Compiler, or the - Extending the **continuous integration** toward more exotic compilers such as Android NDK, Intel's Compiler, or the
bleeding-edge versions Clang. bleeding-edge versions Clang.
- Improving the efficiency of the **JSON parser**. The current parser is implemented as a naive recursive descent parser - Improving the efficiency of the **JSON parser**. The current parser is implemented as a naive recursive descent parser
with hand coded string handling. More sophisticated approaches like LALR parsers would be really appreciated. That with hand-coded string handling. More sophisticated approaches like LALR parsers would be really appreciated. That
said, parser generators like Bison or ANTLR do not play nice with single-header files -- I really would like to keep said, parser generators like Bison or ANTLR do not play nice with single-header files -- I really would like to keep
the parser inside the `json.hpp` header, and I am not aware of approaches similar to [`re2c`](http://re2c.org) for the parser inside the `json.hpp` header, and I am not aware of approaches similar to [`re2c`](http://re2c.org) for
parsing. parsing.

View File

@@ -76,7 +76,7 @@ body:
label: Library version label: Library version
description: > description: >
Which version of the library did you use? If it is a released version, Which version of the library did you use? If it is a released version,
please enter the version number (e.g., 3.11.3). Otherwise, please enter please enter the version number (e.g., 3.12.0). Otherwise, please enter
the commit hash. If you got the library from another source as the the commit hash. If you got the library from another source as the
GitHub repository (e.g., via a package manager), please also state GitHub repository (e.g., via a package manager), please also state
this. this.

View File

@@ -1,4 +1,4 @@
[Describe your pull request here. Please read the text below the line, and make sure you follow the checklist.] [Describe your pull request here. Please read the text below the line and make sure you follow the checklist.]
- [ ] The changes are described in detail, both the what and why. - [ ] The changes are described in detail, both the what and why.
- [ ] If applicable, an [existing issue](https://github.com/nlohmann/json/issues) is referenced. - [ ] If applicable, an [existing issue](https://github.com/nlohmann/json/issues) is referenced.

View File

@@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Harden Runner - name: Harden Runner
uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
with: with:
egress-policy: audit egress-policy: audit
@@ -34,7 +34,7 @@ jobs:
steps: steps:
- name: Harden Runner - name: Harden Runner
uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
with: with:
egress-policy: audit egress-policy: audit

View File

@@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Harden Runner - name: Harden Runner
uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
with: with:
egress-policy: audit egress-policy: audit

View File

@@ -27,7 +27,7 @@ jobs:
steps: steps:
- name: Harden Runner - name: Harden Runner
uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
with: with:
egress-policy: audit egress-policy: audit
@@ -36,14 +36,14 @@ jobs:
# Initializes the CodeQL tools for scanning. # Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL - name: Initialize CodeQL
uses: github/codeql-action/init@fc7e4a0fa01c3cca5fd6a1fddec5c0740c977aa2 # v3.28.14 uses: github/codeql-action/init@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18
with: with:
languages: c-cpp languages: c-cpp
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below) # If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild - name: Autobuild
uses: github/codeql-action/autobuild@fc7e4a0fa01c3cca5fd6a1fddec5c0740c977aa2 # v3.28.14 uses: github/codeql-action/autobuild@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18
- name: Perform CodeQL Analysis - name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@fc7e4a0fa01c3cca5fd6a1fddec5c0740c977aa2 # v3.28.14 uses: github/codeql-action/analyze@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18

View File

@@ -19,7 +19,7 @@ jobs:
pull-requests: write pull-requests: write
steps: steps:
- name: Harden Runner - name: Harden Runner
uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
with: with:
egress-policy: audit egress-policy: audit

View File

@@ -17,11 +17,11 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Harden Runner - name: Harden Runner
uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
with: with:
egress-policy: audit egress-policy: audit
- name: 'Checkout Repository' - name: 'Checkout Repository'
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: 'Dependency Review' - name: 'Dependency Review'
uses: actions/dependency-review-action@ce3cf9537a52e8119d91fd484ab5b8a807627bf8 # v4.6.0 uses: actions/dependency-review-action@da24556b548a50705dd671f47852072ea4c105d9 # v4.7.1

View File

@@ -17,10 +17,10 @@ jobs:
steps: steps:
- name: Harden Runner - name: Harden Runner
uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
with: with:
egress-policy: audit egress-policy: audit
- uses: srvaroa/labeler@e216fb40e2e6d3b17d90fb1d950f98bee92f65ce # master - uses: srvaroa/labeler@e7bef2249506ba9cbbd3ca5cee256abd9f930b04 # master
env: env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

View File

@@ -27,7 +27,7 @@ jobs:
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
steps: steps:
- name: Harden Runner - name: Harden Runner
uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
with: with:
egress-policy: audit egress-policy: audit

View File

@@ -36,7 +36,7 @@ jobs:
steps: steps:
- name: Harden Runner - name: Harden Runner
uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
with: with:
egress-policy: audit egress-policy: audit
@@ -76,6 +76,6 @@ jobs:
# Upload the results to GitHub's code scanning dashboard. # Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning" - name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@fc7e4a0fa01c3cca5fd6a1fddec5c0740c977aa2 # v3.28.14 uses: github/codeql-action/upload-sarif@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18
with: with:
sarif_file: results.sarif sarif_file: results.sarif

View File

@@ -16,7 +16,7 @@ jobs:
steps: steps:
- name: Harden Runner - name: Harden Runner
uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
with: with:
egress-policy: audit egress-policy: audit

View File

@@ -23,7 +23,7 @@ jobs:
steps: steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@28983e0d3955dba2bb0a6810caae0c6cf268ec0c # v4.0.0 uses: lukka/get-cmake@ea004816823209b8d1211e47b216185caee12cc5 # v4.02
- name: Run CMake - name: Run CMake
run: cmake -S . -B build -DJSON_CI=On run: cmake -S . -B build -DJSON_CI=On
- name: Build - name: Build
@@ -46,7 +46,7 @@ jobs:
target: [ci_test_amalgamation, ci_test_single_header, ci_cppcheck, ci_cpplint, ci_reproducible_tests, ci_non_git_tests, ci_offline_testdata, ci_reuse_compliance, ci_test_valgrind] target: [ci_test_amalgamation, ci_test_single_header, ci_cppcheck, ci_cpplint, ci_reproducible_tests, ci_non_git_tests, ci_offline_testdata, ci_reuse_compliance, ci_test_valgrind]
steps: steps:
- name: Harden Runner - name: Harden Runner
uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
with: with:
egress-policy: audit egress-policy: audit
@@ -54,7 +54,7 @@ jobs:
run: sudo apt-get update ; sudo apt-get install -y valgrind run: sudo apt-get update ; sudo apt-get install -y valgrind
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@28983e0d3955dba2bb0a6810caae0c6cf268ec0c # v4.0.0 uses: lukka/get-cmake@ea004816823209b8d1211e47b216185caee12cc5 # v4.02
- name: Run CMake - name: Run CMake
run: cmake -S . -B build -DJSON_CI=On run: cmake -S . -B build -DJSON_CI=On
- name: Build - name: Build
@@ -71,7 +71,7 @@ jobs:
run: apt-get update ; apt-get install -y git clang-tools iwyu unzip run: apt-get update ; apt-get install -y git clang-tools iwyu unzip
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@28983e0d3955dba2bb0a6810caae0c6cf268ec0c # v4.0.0 uses: lukka/get-cmake@ea004816823209b8d1211e47b216185caee12cc5 # v4.02
- name: Run CMake - name: Run CMake
run: cmake -S . -B build -DJSON_CI=On run: cmake -S . -B build -DJSON_CI=On
- name: Build - name: Build
@@ -88,7 +88,7 @@ jobs:
run: apt-get update ; apt-get install -y build-essential unzip wget git libssl-dev run: apt-get update ; apt-get install -y build-essential unzip wget git libssl-dev
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@28983e0d3955dba2bb0a6810caae0c6cf268ec0c # v4.0.0 uses: lukka/get-cmake@ea004816823209b8d1211e47b216185caee12cc5 # v4.02
- name: Run CMake - name: Run CMake
run: cmake -S . -B build -DJSON_CI=On run: cmake -S . -B build -DJSON_CI=On
- name: Build - name: Build
@@ -98,7 +98,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Harden Runner - name: Harden Runner
uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
with: with:
egress-policy: audit egress-policy: audit
@@ -143,12 +143,12 @@ jobs:
strategy: strategy:
matrix: matrix:
# older GCC docker images (4, 5, 6) fail to check out code # older GCC docker images (4, 5, 6) fail to check out code
compiler: ['7', '8', '9', '10', '11', '12', '13', '14', 'latest'] compiler: ['7', '8', '9', '10', '11', '12', '13', '14', '15', 'latest']
container: gcc:${{ matrix.compiler }} container: gcc:${{ matrix.compiler }}
steps: steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@28983e0d3955dba2bb0a6810caae0c6cf268ec0c # v4.0.0 uses: lukka/get-cmake@ea004816823209b8d1211e47b216185caee12cc5 # v4.02
- name: Run CMake - name: Run CMake
run: cmake -S . -B build -DJSON_CI=On run: cmake -S . -B build -DJSON_CI=On
- name: Build - name: Build
@@ -165,7 +165,7 @@ jobs:
run: apt-get update ; apt-get install -y unzip git run: apt-get update ; apt-get install -y unzip git
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@28983e0d3955dba2bb0a6810caae0c6cf268ec0c # v4.0.0 uses: lukka/get-cmake@ea004816823209b8d1211e47b216185caee12cc5 # v4.02
- name: Set env FORCE_STDCPPFS_FLAG for clang 7 / 8 / 9 / 10 - name: Set env FORCE_STDCPPFS_FLAG for clang 7 / 8 / 9 / 10
run: echo "JSON_FORCED_GLOBAL_COMPILE_OPTIONS=-DJSON_HAS_FILESYSTEM=0;-DJSON_HAS_EXPERIMENTAL_FILESYSTEM=0" >> "$GITHUB_ENV" run: echo "JSON_FORCED_GLOBAL_COMPILE_OPTIONS=-DJSON_HAS_FILESYSTEM=0;-DJSON_HAS_EXPERIMENTAL_FILESYSTEM=0" >> "$GITHUB_ENV"
if: ${{ matrix.compiler == '7' || matrix.compiler == '8' || matrix.compiler == '9' || matrix.compiler == '10' }} if: ${{ matrix.compiler == '7' || matrix.compiler == '8' || matrix.compiler == '9' || matrix.compiler == '10' }}
@@ -183,7 +183,7 @@ jobs:
steps: steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@28983e0d3955dba2bb0a6810caae0c6cf268ec0c # v4.0.0 uses: lukka/get-cmake@ea004816823209b8d1211e47b216185caee12cc5 # v4.02
- name: Run CMake - name: Run CMake
run: cmake -S . -B build -DJSON_CI=On run: cmake -S . -B build -DJSON_CI=On
- name: Build - name: Build
@@ -201,7 +201,7 @@ jobs:
run: apt-get update ; apt-get install -y git unzip run: apt-get update ; apt-get install -y git unzip
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@28983e0d3955dba2bb0a6810caae0c6cf268ec0c # v4.0.0 uses: lukka/get-cmake@ea004816823209b8d1211e47b216185caee12cc5 # v4.02
- name: Run CMake - name: Run CMake
run: cmake -S . -B build -DJSON_CI=On run: cmake -S . -B build -DJSON_CI=On
- name: Build with libc++ - name: Build with libc++
@@ -221,6 +221,21 @@ jobs:
- name: Build - name: Build
run: cmake --build build --target ci_cuda_example run: cmake --build build --target ci_cuda_example
ci_module_cpp20:
strategy:
matrix:
container: ['gcc:latest', 'silkeh/clang:latest']
runs-on: ubuntu-latest
container: ${{ matrix.container }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Get latest CMake and ninja
uses: lukka/get-cmake@ea004816823209b8d1211e47b216185caee12cc5 # v4.02
- name: Run CMake
run: cmake -S . -B build -DJSON_CI=On
- name: Build
run: cmake --build build --target ci_module_cpp20
ci_icpc: ci_icpc:
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: ghcr.io/nlohmann/json-ci:v2.2.0 container: ghcr.io/nlohmann/json-ci:v2.2.0
@@ -233,6 +248,24 @@ jobs:
. /opt/intel/oneapi/setvars.sh . /opt/intel/oneapi/setvars.sh
cmake --build build --target ci_icpc cmake --build build --target ci_icpc
ci_emscripten:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
with:
egress-policy: audit
- name: Install emscripten
uses: mymindstorm/setup-emsdk@v14
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Get latest CMake and ninja
uses: lukka/get-cmake@ea004816823209b8d1211e47b216185caee12cc5 # v4.02
- name: Run CMake
run: cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=$EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -GNinja
- name: Build
run: cmake --build build
ci_test_documentation: ci_test_documentation:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
@@ -240,7 +273,7 @@ jobs:
target: [ci_test_examples, ci_test_build_documentation] target: [ci_test_examples, ci_test_build_documentation]
steps: steps:
- name: Harden Runner - name: Harden Runner
uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
with: with:
egress-policy: audit egress-policy: audit

View File

@@ -37,69 +37,48 @@ jobs:
- name: Test - name: Test
run: cd build ; ctest -j 10 -C Debug --output-on-failure run: cd build ; ctest -j 10 -C Debug --output-on-failure
msvc2019: msvc:
runs-on: windows-2019
strategy: strategy:
matrix: matrix:
runs_on: [windows-2019, windows-2022]
build_type: [Debug, Release] build_type: [Debug, Release]
architecture: [Win32, x64] architecture: [Win32, x64]
std_version: [default, latest]
runs-on: ${{ matrix.runs_on }}
steps: steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Run CMake - name: Set generator
run: cmake -S . -B build -G "Visual Studio 16 2019" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/W4 /WX" id: generator
if: matrix.build_type == 'Release' run: |
- name: Run CMake if [ "${{ matrix.runs_on }}" = "windows-2019" ]; then
run: cmake -S . -B build -G "Visual Studio 16 2019" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DJSON_FastTests=ON -DCMAKE_CXX_FLAGS="/W4 /WX" echo "generator=Visual Studio 16 2019" >> $GITHUB_ENV
if: matrix.build_type == 'Debug' else
- name: Build echo "generator=Visual Studio 17 2022" >> $GITHUB_ENV
run: cmake --build build --config ${{ matrix.build_type }} --parallel 10 fi
- name: Test shell: bash
run: cd build ; ctest -j 10 -C ${{ matrix.build_type }} --output-on-failure - name: Set extra CXX_FLAGS for latest std_version
id: cxxflags
msvc2019_latest: run: |
runs-on: windows-2019 if [ "${{ matrix.std_version }}" = "latest" ]; then
echo "flags=/permissive- /std:c++latest /utf-8 /W4 /WX" >> $GITHUB_ENV
steps: else
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 echo "flags=/W4 /WX" >> $GITHUB_ENV
- name: Run CMake fi
run: cmake -S . -B build -G "Visual Studio 16 2019" -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/permissive- /std:c++latest /utf-8 /W4 /WX" shell: bash
- name: Build - name: Run CMake (Release)
run: cmake --build build --config Release --parallel 10 run: cmake -S . -B build -G "$env:generator" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="$env:flags"
- name: Test if: matrix.build_type == 'Release'
run: cd build ; ctest -j 10 -C Release --output-on-failure shell: pwsh
- name: Run CMake (Debug)
msvc2022: run: cmake -S . -B build -G "$env:generator" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DJSON_FastTests=ON -DCMAKE_CXX_FLAGS="$env:flags"
runs-on: windows-2022 if: matrix.build_type == 'Debug'
strategy: shell: pwsh
matrix: - name: Build
build_type: [Debug, Release] run: cmake --build build --config ${{ matrix.build_type }} --parallel 10
architecture: [Win32, x64] - name: Test
run: cd build ; ctest -j 10 -C ${{ matrix.build_type }} --output-on-failure
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Run CMake
run: cmake -S . -B build -G "Visual Studio 17 2022" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/W4 /WX"
if: matrix.build_type == 'Release'
- name: Run CMake
run: cmake -S . -B build -G "Visual Studio 17 2022" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DJSON_FastTests=ON -DCMAKE_CXX_FLAGS="/W4 /WX"
if: matrix.build_type == 'Debug'
- name: Build
run: cmake --build build --config ${{ matrix.build_type }} --parallel 10
- name: Test
run: cd build ; ctest -j 10 -C ${{ matrix.build_type }} --output-on-failure
msvc2022_latest:
runs-on: windows-2022
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Run CMake
run: cmake -S . -B build -G "Visual Studio 17 2022" -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/permissive- /std:c++latest /utf-8 /W4 /WX"
- name: Build
run: cmake --build build --config Release --parallel 10
- name: Test
run: cd build ; ctest -j 10 -C Release --output-on-failure
clang: clang:
runs-on: windows-2019 runs-on: windows-2019
@@ -118,7 +97,7 @@ jobs:
- name: Test - name: Test
run: cd build ; ctest -j 10 -C Debug --exclude-regex "test-unicode" --output-on-failure run: cd build ; ctest -j 10 -C Debug --exclude-regex "test-unicode" --output-on-failure
clang-cl-11: clang-cl-12:
runs-on: windows-2019 runs-on: windows-2019
strategy: strategy:
matrix: matrix:

View File

@@ -1,6 +1,6 @@
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ __| | __| | | | JSON for Modern C++
| | |__ | | | | | | version 3.11.3 | | |__ | | | | | | version 3.12.0
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
{% for copyright_line in copyright_lines %} {% for copyright_line in copyright_lines %}

View File

@@ -1,6 +1,6 @@
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (supporting code) __| | __| | | | JSON for Modern C++ (supporting code)
| | |__ | | | | | | version 3.11.3 | | |__ | | | | | | version 3.12.0
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
{% for copyright_line in copyright_lines %} {% for copyright_line in copyright_lines %}

View File

@@ -7,8 +7,8 @@ authors:
email: mail@nlohmann.me email: mail@nlohmann.me
website: https://nlohmann.me website: https://nlohmann.me
title: "JSON for Modern C++" title: "JSON for Modern C++"
version: 3.11.3 version: 3.12.0
date-released: 2023-11-28 date-released: 2025-04-07
license: MIT license: MIT
repository-code: "https://github.com/nlohmann" repository-code: "https://github.com/nlohmann"
url: https://json.nlohmann.me url: https://json.nlohmann.me

View File

@@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.5...4.0)
## PROJECT ## PROJECT
## name and version ## name and version
## ##
project(nlohmann_json VERSION 3.11.3 LANGUAGES CXX) project(nlohmann_json VERSION 3.12.0 LANGUAGES CXX)
## ##
## MAIN_PROJECT CHECK ## MAIN_PROJECT CHECK

View File

@@ -92,7 +92,7 @@ Further documentation:
### `.github/dependabot.yml` ### `.github/dependabot.yml`
The configuration of [dependabot](https://github.com/dependabot) which ensures the dependencies (GitHub actions and Python packages used in the CI) remain up-to-date. The configuration of [dependabot](https://github.com/dependabot) which ensures the dependencies (GitHub actions and Python packages used in the CI) remain up to date.
Further documentation: Further documentation:
@@ -185,7 +185,7 @@ Further documentation:
### `.reuse/dep5` ### `.reuse/dep5`
The file defines the licenses of certain third-party component in the repository. The root `Makefile` contains a target `reuse` that checks for compliance. The file defines the licenses of certain third-party components in the repository. The root `Makefile` contains a target `reuse` that checks for compliance.
Further documentation: Further documentation:
@@ -212,7 +212,7 @@ Further information:
### `LICENSES` ### `LICENSES`
A folder that contains every license of all licenses files (library and third-party code). A folder that contains every license of all license files (library and third-party code).
Further documentation: Further documentation:

View File

@@ -30,7 +30,7 @@
- [Examples](#examples) - [Examples](#examples)
- [Read JSON from a file](#read-json-from-a-file) - [Read JSON from a file](#read-json-from-a-file)
- [Creating `json` objects from JSON literals](#creating-json-objects-from-json-literals) - [Creating `json` objects from JSON literals](#creating-json-objects-from-json-literals)
- [JSON as first-class data type](#json-as-first-class-data-type) - [JSON as a first-class data type](#json-as-a-first-class-data-type)
- [Serialization / Deserialization](#serialization--deserialization) - [Serialization / Deserialization](#serialization--deserialization)
- [STL-like access](#stl-like-access) - [STL-like access](#stl-like-access)
- [Conversion from STL containers](#conversion-from-stl-containers) - [Conversion from STL containers](#conversion-from-stl-containers)
@@ -57,7 +57,7 @@
There are myriads of [JSON](https://json.org) libraries out there, and each may even have its reason to exist. Our class had these design goals: There are myriads of [JSON](https://json.org) libraries out there, and each may even have its reason to exist. Our class had these design goals:
- **Intuitive syntax**. In languages such as Python, JSON feels like a first class data type. We used all the operator magic of modern C++ to achieve the same feeling in your code. Check out the [examples below](#examples) and you'll know what I mean. - **Intuitive syntax**. In languages such as Python, JSON feels like a first-class data type. We used all the operator magic of modern C++ to achieve the same feeling in your code. Check out the [examples below](#examples) and you'll know what I mean.
- **Trivial integration**. Our whole code consists of a single header file [`json.hpp`](https://github.com/nlohmann/json/blob/develop/single_include/nlohmann/json.hpp). That's it. No library, no subproject, no dependencies, no complex build system. The class is written in vanilla C++11. All in all, everything should require no adjustment of your compiler flags or project settings. The library is also included in all popular [package managers](https://json.nlohmann.me/integration/package_managers/). - **Trivial integration**. Our whole code consists of a single header file [`json.hpp`](https://github.com/nlohmann/json/blob/develop/single_include/nlohmann/json.hpp). That's it. No library, no subproject, no dependencies, no complex build system. The class is written in vanilla C++11. All in all, everything should require no adjustment of your compiler flags or project settings. The library is also included in all popular [package managers](https://json.nlohmann.me/integration/package_managers/).
@@ -107,7 +107,7 @@ Thanks everyone!
:bug: If you found a **bug**, please check the [**FAQ**](https://json.nlohmann.me/home/faq/) if it is a known issue or the result of a design decision. Please also have a look at the [**issue list**](https://github.com/nlohmann/json/issues) before you [**create a new issue**](https://github.com/nlohmann/json/issues/new/choose). Please provide as much information as possible to help us understand and reproduce your issue. :bug: If you found a **bug**, please check the [**FAQ**](https://json.nlohmann.me/home/faq/) if it is a known issue or the result of a design decision. Please also have a look at the [**issue list**](https://github.com/nlohmann/json/issues) before you [**create a new issue**](https://github.com/nlohmann/json/issues/new/choose). Please provide as much information as possible to help us understand and reproduce your issue.
There is also a [**docset**](https://github.com/Kapeli/Dash-User-Contributions/tree/master/docsets/JSON_for_Modern_C%2B%2B) for the documentation browsers [Dash](https://kapeli.com/dash), [Velocity](https://velocity.silverlakesoftware.com), and [Zeal](https://zealdocs.org) that contains the full [documentation](https://json.nlohmann.me) as offline resource. There is also a [**docset**](https://github.com/Kapeli/Dash-User-Contributions/tree/master/docsets/JSON_for_Modern_C%2B%2B) for the documentation browsers [Dash](https://kapeli.com/dash), [Velocity](https://velocity.silverlakesoftware.com), and [Zeal](https://zealdocs.org) that contains the full [documentation](https://json.nlohmann.me) as an offline resource.
## Quick reference ## Quick reference
@@ -136,7 +136,7 @@ There is also a [**docset**](https://github.com/Kapeli/Dash-User-Contributions/t
Here are some examples to give you an idea how to use the class. Here are some examples to give you an idea how to use the class.
Beside the examples below, you may want to: Besides the examples below, you may want to:
→ Check the [documentation](https://json.nlohmann.me/)\ → Check the [documentation](https://json.nlohmann.me/)\
→ Browse the [standalone example files](https://github.com/nlohmann/json/tree/develop/docs/mkdocs/docs/examples)\ → Browse the [standalone example files](https://github.com/nlohmann/json/tree/develop/docs/mkdocs/docs/examples)\
@@ -195,7 +195,7 @@ json ex3 = {
}; };
``` ```
### JSON as first-class data type ### JSON as a first-class data type
Here are some examples to give you an idea how to use the class. Here are some examples to give you an idea how to use the class.
@@ -224,13 +224,13 @@ With this library, you could write:
// create an empty structure (null) // create an empty structure (null)
json j; json j;
// add a number that is stored as double (note the implicit conversion of j to an object) // add a number stored as double (note the implicit conversion of j to an object)
j["pi"] = 3.141; j["pi"] = 3.141;
// add a Boolean that is stored as bool // add a Boolean stored as bool
j["happy"] = true; j["happy"] = true;
// add a string that is stored as std::string // add a string stored as std::string
j["name"] = "Niels"; j["name"] = "Niels";
// add another null object by passing nullptr // add another null object by passing nullptr
@@ -239,7 +239,7 @@ j["nothing"] = nullptr;
// add an object inside the object // add an object inside the object
j["answer"]["everything"] = 42; j["answer"]["everything"] = 42;
// add an array that is stored as std::vector (using an initializer list) // add an array stored as std::vector (using an initializer list)
j["list"] = { 1, 0, 2 }; j["list"] = { 1, 0, 2 };
// add another object (using an initializer list of pairs) // add another object (using an initializer list of pairs)
@@ -349,7 +349,7 @@ std::cout << j_string << " == " << serialized_string << std::endl;
Note the library only supports UTF-8. When you store strings with different encodings in the library, calling [`dump()`](https://json.nlohmann.me/api/basic_json/dump/) may throw an exception unless `json::error_handler_t::replace` or `json::error_handler_t::ignore` are used as error handlers. Note the library only supports UTF-8. When you store strings with different encodings in the library, calling [`dump()`](https://json.nlohmann.me/api/basic_json/dump/) may throw an exception unless `json::error_handler_t::replace` or `json::error_handler_t::ignore` are used as error handlers.
#### To/from streams (e.g. files, string streams) #### To/from streams (e.g., files, string streams)
You can also use streams to serialize and deserialize: You can also use streams to serialize and deserialize:
@@ -382,7 +382,7 @@ Please note that setting the exception bit for `failbit` is inappropriate for th
#### Read from iterator range #### Read from iterator range
You can also parse JSON from an iterator range; that is, from any container accessible by iterators whose `value_type` is an integral type of 1, 2 or 4 bytes, which will be interpreted as UTF-8, UTF-16 and UTF-32 respectively. For instance, a `std::vector<std::uint8_t>`, or a `std::list<std::uint16_t>`: You can also parse JSON from an iterator range; that is, from any container accessible by iterators whose `value_type` is an integral type of 1, 2, or 4 bytes, which will be interpreted as UTF-8, UTF-16, and UTF-32 respectively. For instance, a `std::vector<std::uint8_t>`, or a `std::list<std::uint16_t>`:
```cpp ```cpp
std::vector<std::uint8_t> v = {'t', 'r', 'u', 'e'}; std::vector<std::uint8_t> v = {'t', 'r', 'u', 'e'};
@@ -486,7 +486,7 @@ To implement your own SAX handler, proceed as follows:
2. Create an object of your SAX interface class, e.g. `my_sax`. 2. Create an object of your SAX interface class, e.g. `my_sax`.
3. Call `bool json::sax_parse(input, &my_sax)`; where the first parameter can be any input like a string or an input stream and the second parameter is a pointer to your SAX interface. 3. Call `bool json::sax_parse(input, &my_sax)`; where the first parameter can be any input like a string or an input stream and the second parameter is a pointer to your SAX interface.
Note the `sax_parse` function only returns a `bool` indicating the result of the last executed SAX event. It does not return a `json` value - it is up to you to decide what to do with the SAX events. Furthermore, no exceptions are thrown in case of a parse error - it is up to you what to do with the exception object passed to your `parse_error` implementation. Internally, the SAX interface is used for the DOM parser (class `json_sax_dom_parser`) as well as the acceptor (`json_sax_acceptor`), see file [`json_sax.hpp`](https://github.com/nlohmann/json/blob/develop/include/nlohmann/detail/input/json_sax.hpp). Note the `sax_parse` function only returns a `bool` indicating the result of the last executed SAX event. It does not return a `json` value - it is up to you to decide what to do with the SAX events. Furthermore, no exceptions are thrown in case of a parse error -- it is up to you what to do with the exception object passed to your `parse_error` implementation. Internally, the SAX interface is used for the DOM parser (class `json_sax_dom_parser`) as well as the acceptor (`json_sax_acceptor`), see file [`json_sax.hpp`](https://github.com/nlohmann/json/blob/develop/include/nlohmann/detail/input/json_sax.hpp).
### STL-like access ### STL-like access
@@ -618,7 +618,7 @@ json j_umset(c_umset); // both entries for "one" are used
// maybe ["one", "two", "one", "four"] // maybe ["one", "two", "one", "four"]
``` ```
Likewise, any associative key-value containers (`std::map`, `std::multimap`, `std::unordered_map`, `std::unordered_multimap`) whose keys can construct an `std::string` and whose values can be used to construct JSON values (see examples above) can be used to create a JSON object. Note that in case of multimaps only one key is used in the JSON object and the value depends on the internal order of the STL container. Likewise, any associative key-value containers (`std::map`, `std::multimap`, `std::unordered_map`, `std::unordered_multimap`) whose keys can construct an `std::string` and whose values can be used to construct JSON values (see examples above) can be used to create a JSON object. Note that in case of multimaps, only one key is used in the JSON object and the value depends on the internal order of the STL container.
```cpp ```cpp
std::map<std::string, int> c_map { {"one", 1}, {"two", 2}, {"three", 3} }; std::map<std::string, int> c_map { {"one", 1}, {"two", 2}, {"three", 3} };
@@ -640,7 +640,7 @@ json j_ummap(c_ummap); // only one entry for key "three" is used
### JSON Pointer and JSON Patch ### JSON Pointer and JSON Patch
The library supports **JSON Pointer** ([RFC 6901](https://tools.ietf.org/html/rfc6901)) as alternative means to address structured values. On top of this, **JSON Patch** ([RFC 6902](https://tools.ietf.org/html/rfc6902)) allows describing differences between two JSON values - effectively allowing patch and diff operations known from Unix. The library supports **JSON Pointer** ([RFC 6901](https://tools.ietf.org/html/rfc6901)) as an alternative means to address structured values. On top of this, **JSON Patch** ([RFC 6902](https://tools.ietf.org/html/rfc6902)) allows describing differences between two JSON values -- effectively allowing patch and diff operations known from Unix.
```cpp ```cpp
// a JSON value // a JSON value
@@ -873,7 +873,7 @@ namespace ns {
This requires a bit more advanced technique. But first, let's see how this conversion mechanism works: This requires a bit more advanced technique. But first, let's see how this conversion mechanism works:
The library uses **JSON Serializers** to convert types to json. The library uses **JSON Serializers** to convert types to JSON.
The default serializer for `nlohmann::json` is `nlohmann::adl_serializer` (ADL means [Argument-Dependent Lookup](https://en.cppreference.com/w/cpp/language/adl)). The default serializer for `nlohmann::json` is `nlohmann::adl_serializer` (ADL means [Argument-Dependent Lookup](https://en.cppreference.com/w/cpp/language/adl)).
It is implemented like this (simplified): It is implemented like this (simplified):
@@ -923,7 +923,7 @@ namespace nlohmann {
#### How can I use `get()` for non-default constructible/non-copyable types? #### How can I use `get()` for non-default constructible/non-copyable types?
There is a way, if your type is [MoveConstructible](https://en.cppreference.com/w/cpp/named_req/MoveConstructible). You will need to specialize the `adl_serializer` as well, but with a special `from_json` overload: There is a way if your type is [MoveConstructible](https://en.cppreference.com/w/cpp/named_req/MoveConstructible). You will need to specialize the `adl_serializer` as well, but with a special `from_json` overload:
```cpp ```cpp
struct move_only_type { struct move_only_type {
@@ -1012,7 +1012,7 @@ struct bad_serializer
### Specializing enum conversion ### Specializing enum conversion
By default, enum values are serialized to JSON as integers. In some cases this could result in undesired behavior. If an enum is modified or re-ordered after data has been serialized to JSON, the later de-serialized JSON data may be undefined or a different enum value than was originally intended. By default, enum values are serialized to JSON as integers. In some cases, this could result in undesired behavior. If an enum is modified or re-ordered after data has been serialized to JSON, the later deserialized JSON data may be undefined or a different enum value than was originally intended.
It is possible to more precisely specify how a given enum is mapped to and from JSON as shown below: It is possible to more precisely specify how a given enum is mapped to and from JSON as shown below:
@@ -1168,7 +1168,7 @@ Please note:
The code compiles successfully with [Android NDK](https://developer.android.com/ndk/index.html?hl=ml), Revision 9 - 11 (and possibly later) and [CrystaX's Android NDK](https://www.crystax.net/en/android/ndk) version 10. The code compiles successfully with [Android NDK](https://developer.android.com/ndk/index.html?hl=ml), Revision 9 - 11 (and possibly later) and [CrystaX's Android NDK](https://www.crystax.net/en/android/ndk) version 10.
- For GCC running on MinGW or Android SDK, the error `'to_string' is not a member of 'std'` (or similarly, for `strtod` or `strtof`) may occur. Note this is not an issue with the code, but rather with the compiler itself. On Android, see above to build with a newer environment. For MinGW, please refer to [this site](https://tehsausage.com/mingw-to-string) and [this discussion](https://github.com/nlohmann/json/issues/136) for information on how to fix this bug. For Android NDK using `APP_STL := gnustl_static`, please refer to [this discussion](https://github.com/nlohmann/json/issues/219). - For GCC running on MinGW or Android SDK, the error `'to_string' is not a member of 'std'` (or similarly, for `strtod` or `strtof`) may occur. Note this is not an issue with the code, but rather with the compiler itself. On Android, see above to build with a newer environment. For MinGW, please refer to [this site](https://tehsausage.com/mingw-to-string) and [this discussion](https://github.com/nlohmann/json/issues/136) for information on how to fix this bug. For Android NDK using `APP_STL := gnustl_static`, please refer to [this discussion](https://github.com/nlohmann/json/issues/219).
- Unsupported versions of GCC and Clang are rejected by `#error` directives. This can be switched off by defining `JSON_SKIP_UNSUPPORTED_COMPILER_CHECK`. Note that you can expect no support in this case. - Unsupported versions of GCC and Clang are rejected by `#error` directives. This can be switched off by defining `JSON_SKIP_UNSUPPORTED_COMPILER_CHECK`. Note that you can expect no support in this case.
@@ -1187,7 +1187,7 @@ using json = nlohmann::json;
to the files you want to process JSON and set the necessary switches to enable C++11 (e.g., `-std=c++11` for GCC and Clang). to the files you want to process JSON and set the necessary switches to enable C++11 (e.g., `-std=c++11` for GCC and Clang).
You can further use file [`include/nlohmann/json_fwd.hpp`](https://github.com/nlohmann/json/blob/develop/include/nlohmann/json_fwd.hpp) for forward-declarations. The installation of json_fwd.hpp (as part of cmake's install step), can be achieved by setting `-DJSON_MultipleHeaders=ON`. You can further use file [`include/nlohmann/json_fwd.hpp`](https://github.com/nlohmann/json/blob/develop/include/nlohmann/json_fwd.hpp) for forward-declarations. The installation of `json_fwd.hpp` (as part of cmake's install step) can be achieved by setting `-DJSON_MultipleHeaders=ON`.
### CMake ### CMake
@@ -1199,7 +1199,7 @@ To use this library from a CMake project, you can locate it directly with `find_
```cmake ```cmake
# CMakeLists.txt # CMakeLists.txt
find_package(nlohmann_json 3.11.3 REQUIRED) find_package(nlohmann_json 3.12.0 REQUIRED)
... ...
add_library(foo ...) add_library(foo ...)
... ...
@@ -1243,13 +1243,13 @@ Example:
```cmake ```cmake
include(FetchContent) include(FetchContent)
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz) FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.12.0/json.tar.xz)
FetchContent_MakeAvailable(json) FetchContent_MakeAvailable(json)
target_link_libraries(foo PRIVATE nlohmann_json::nlohmann_json) target_link_libraries(foo PRIVATE nlohmann_json::nlohmann_json)
``` ```
**Note**: It is recommended to use the URL approach described above which is supported as of version 3.10.0. See **Note**: It is recommended to use the URL approach described above, which is supported as of version 3.10.0. See
<https://json.nlohmann.me/integration/cmake/#fetchcontent> for more information. <https://json.nlohmann.me/integration/cmake/#fetchcontent> for more information.
#### Supporting Both #### Supporting Both
@@ -1275,7 +1275,7 @@ target_link_libraries(foo PRIVATE nlohmann_json::nlohmann_json)
# thirdparty/CMakeLists.txt # thirdparty/CMakeLists.txt
... ...
if(FOO_USE_EXTERNAL_JSON) if(FOO_USE_EXTERNAL_JSON)
find_package(nlohmann_json 3.11.3 REQUIRED) find_package(nlohmann_json 3.12.0 REQUIRED)
else() else()
set(JSON_BuildTests OFF CACHE INTERNAL "") set(JSON_BuildTests OFF CACHE INTERNAL "")
add_subdirectory(nlohmann_json) add_subdirectory(nlohmann_json)
@@ -1371,13 +1371,13 @@ I deeply appreciate the help of the following people.
9. [Florian Weber](https://github.com/Florianjw) fixed a bug in and improved the performance of the comparison operators. 9. [Florian Weber](https://github.com/Florianjw) fixed a bug in and improved the performance of the comparison operators.
10. [Eric Cornelius](https://github.com/EricMCornelius) pointed out a bug in the handling with NaN and infinity values. He also improved the performance of the string escaping. 10. [Eric Cornelius](https://github.com/EricMCornelius) pointed out a bug in the handling with NaN and infinity values. He also improved the performance of the string escaping.
11. [易思龙](https://github.com/likebeta) implemented a conversion from anonymous enums. 11. [易思龙](https://github.com/likebeta) implemented a conversion from anonymous enums.
12. [kepkin](https://github.com/kepkin) patiently pushed forward the support for Microsoft Visual studio. 12. [kepkin](https://github.com/kepkin) patiently pushed forward the support for Microsoft Visual Studio.
13. [gregmarr](https://github.com/gregmarr) simplified the implementation of reverse iterators and helped with numerous hints and improvements. In particular, he pushed forward the implementation of user-defined types. 13. [gregmarr](https://github.com/gregmarr) simplified the implementation of reverse iterators and helped with numerous hints and improvements. In particular, he pushed forward the implementation of user-defined types.
14. [Caio Luppi](https://github.com/caiovlp) fixed a bug in the Unicode handling. 14. [Caio Luppi](https://github.com/caiovlp) fixed a bug in the Unicode handling.
15. [dariomt](https://github.com/dariomt) fixed some typos in the examples. 15. [dariomt](https://github.com/dariomt) fixed some typos in the examples.
16. [Daniel Frey](https://github.com/d-frey) cleaned up some pointers and implemented exception-safe memory allocation. 16. [Daniel Frey](https://github.com/d-frey) cleaned up some pointers and implemented exception-safe memory allocation.
17. [Colin Hirsch](https://github.com/ColinH) took care of a small namespace issue. 17. [Colin Hirsch](https://github.com/ColinH) took care of a small namespace issue.
18. [Huu Nguyen](https://github.com/whoshuu) correct a variable name in the documentation. 18. [Huu Nguyen](https://github.com/whoshuu) corrected a variable name in the documentation.
19. [Silverweed](https://github.com/silverweed) overloaded `parse()` to accept an rvalue reference. 19. [Silverweed](https://github.com/silverweed) overloaded `parse()` to accept an rvalue reference.
20. [dariomt](https://github.com/dariomt) fixed a subtlety in MSVC type support and implemented the `get_ref()` function to get a reference to stored values. 20. [dariomt](https://github.com/dariomt) fixed a subtlety in MSVC type support and implemented the `get_ref()` function to get a reference to stored values.
21. [ZahlGraf](https://github.com/ZahlGraf) added a workaround that allows compilation using Android NDK. 21. [ZahlGraf](https://github.com/ZahlGraf) added a workaround that allows compilation using Android NDK.
@@ -1412,7 +1412,7 @@ I deeply appreciate the help of the following people.
50. [Jared Grubb](https://github.com/jaredgrubb) silenced a nasty documentation warning. 50. [Jared Grubb](https://github.com/jaredgrubb) silenced a nasty documentation warning.
51. [Yixin Zhang](https://github.com/qwename) fixed an integer overflow check. 51. [Yixin Zhang](https://github.com/qwename) fixed an integer overflow check.
52. [Bosswestfalen](https://github.com/Bosswestfalen) merged two iterator classes into a smaller one. 52. [Bosswestfalen](https://github.com/Bosswestfalen) merged two iterator classes into a smaller one.
53. [Daniel599](https://github.com/Daniel599) helped to get Travis execute the tests with Clang's sanitizers. 53. [Daniel599](https://github.com/Daniel599) helped to get Travis to execute the tests with Clang's sanitizers.
54. [Jonathan Lee](https://github.com/vjon) fixed an example in the README file. 54. [Jonathan Lee](https://github.com/vjon) fixed an example in the README file.
55. [gnzlbg](https://github.com/gnzlbg) supported the implementation of user-defined types. 55. [gnzlbg](https://github.com/gnzlbg) supported the implementation of user-defined types.
56. [Alexej Harm](https://github.com/qis) helped to get the user-defined types working with Visual Studio. 56. [Alexej Harm](https://github.com/qis) helped to get the user-defined types working with Visual Studio.
@@ -1433,7 +1433,7 @@ I deeply appreciate the help of the following people.
71. [Vincent Thiery](https://github.com/vthiery) maintains a package for the Conan package manager. 71. [Vincent Thiery](https://github.com/vthiery) maintains a package for the Conan package manager.
72. [Steffen](https://github.com/koemeet) fixed a potential issue with MSVC and `std::min`. 72. [Steffen](https://github.com/koemeet) fixed a potential issue with MSVC and `std::min`.
73. [Mike Tzou](https://github.com/Chocobo1) fixed some typos. 73. [Mike Tzou](https://github.com/Chocobo1) fixed some typos.
74. [amrcode](https://github.com/amrcode) noted a misleading documentation about comparison of floats. 74. [amrcode](https://github.com/amrcode) noted misleading documentation about comparison of floats.
75. [Oleg Endo](https://github.com/olegendo) reduced the memory consumption by replacing `<iostream>` with `<iosfwd>`. 75. [Oleg Endo](https://github.com/olegendo) reduced the memory consumption by replacing `<iostream>` with `<iosfwd>`.
76. [dan-42](https://github.com/dan-42) cleaned up the CMake files to simplify including/reusing of the library. 76. [dan-42](https://github.com/dan-42) cleaned up the CMake files to simplify including/reusing of the library.
77. [Nikita Ofitserov](https://github.com/himikof) allowed for moving values from initializer lists. 77. [Nikita Ofitserov](https://github.com/himikof) allowed for moving values from initializer lists.
@@ -1460,13 +1460,13 @@ I deeply appreciate the help of the following people.
98. [Vadim Evard](https://github.com/Pipeliner) fixed a Markdown issue in the README. 98. [Vadim Evard](https://github.com/Pipeliner) fixed a Markdown issue in the README.
99. [zerodefect](https://github.com/zerodefect) fixed a compiler warning. 99. [zerodefect](https://github.com/zerodefect) fixed a compiler warning.
100. [Kert](https://github.com/kaidokert) allowed to template the string type in the serialization and added the possibility to override the exceptional behavior. 100. [Kert](https://github.com/kaidokert) allowed to template the string type in the serialization and added the possibility to override the exceptional behavior.
101. [mark-99](https://github.com/mark-99) helped fixing an ICC error. 101. [mark-99](https://github.com/mark-99) helped fix an ICC error.
102. [Patrik Huber](https://github.com/patrikhuber) fixed links in the README file. 102. [Patrik Huber](https://github.com/patrikhuber) fixed links in the README file.
103. [johnfb](https://github.com/johnfb) found a bug in the implementation of CBOR's indefinite length strings. 103. [johnfb](https://github.com/johnfb) found a bug in the implementation of CBOR's indefinite length strings.
104. [Paul Fultz II](https://github.com/pfultz2) added a note on the cget package manager. 104. [Paul Fultz II](https://github.com/pfultz2) added a note on the cget package manager.
105. [Wilson Lin](https://github.com/wla80) made the integration section of the README more concise. 105. [Wilson Lin](https://github.com/wla80) made the integration section of the README more concise.
106. [RalfBielig](https://github.com/ralfbielig) detected and fixed a memory leak in the parser callback. 106. [RalfBielig](https://github.com/ralfbielig) detected and fixed a memory leak in the parser callback.
107. [agrianius](https://github.com/agrianius) allowed to dump JSON to an alternative string type. 107. [agrianius](https://github.com/agrianius) allowed dumping JSON to an alternative string type.
108. [Kevin Tonon](https://github.com/ktonon) overworked the C++11 compiler checks in CMake. 108. [Kevin Tonon](https://github.com/ktonon) overworked the C++11 compiler checks in CMake.
109. [Axel Huebl](https://github.com/ax3l) simplified a CMake check and added support for the [Spack package manager](https://spack.io). 109. [Axel Huebl](https://github.com/ax3l) simplified a CMake check and added support for the [Spack package manager](https://spack.io).
110. [Carlos O'Ryan](https://github.com/coryan) fixed a typo. 110. [Carlos O'Ryan](https://github.com/coryan) fixed a typo.
@@ -1515,12 +1515,12 @@ I deeply appreciate the help of the following people.
153. [Ivor Wanders](https://github.com/iwanders) helped to reduce the CMake requirement to version 3.1. 153. [Ivor Wanders](https://github.com/iwanders) helped to reduce the CMake requirement to version 3.1.
154. [njlr](https://github.com/njlr) updated the Buckaroo instructions. 154. [njlr](https://github.com/njlr) updated the Buckaroo instructions.
155. [Lion](https://github.com/lieff) fixed a compilation issue with GCC 7 on CentOS. 155. [Lion](https://github.com/lieff) fixed a compilation issue with GCC 7 on CentOS.
156. [Isaac Nickaein](https://github.com/nickaein) improved the integer serialization performance and implemented the `contains()` function. 156. [Isaac Nickaein](https://github.com/nickaein) improved the integer serialization performance and implemented the `contains()` function.
157. [past-due](https://github.com/past-due) suppressed an unfixable warning. 157. [past-due](https://github.com/past-due) suppressed an unfixable warning.
158. [Elvis Oric](https://github.com/elvisoric) improved Meson support. 158. [Elvis Oric](https://github.com/elvisoric) improved Meson support.
159. [Matěj Plch](https://github.com/Afforix) fixed an example in the README. 159. [Matěj Plch](https://github.com/Afforix) fixed an example in the README.
160. [Mark Beckwith](https://github.com/wythe) fixed a typo. 160. [Mark Beckwith](https://github.com/wythe) fixed a typo.
161. [scinart](https://github.com/scinart) fixed bug in the serializer. 161. [scinart](https://github.com/scinart) fixed a bug in the serializer.
162. [Patrick Boettcher](https://github.com/pboettch) implemented `push_back()` and `pop_back()` for JSON Pointers. 162. [Patrick Boettcher](https://github.com/pboettch) implemented `push_back()` and `pop_back()` for JSON Pointers.
163. [Bruno Oliveira](https://github.com/nicoddemus) added support for Conda. 163. [Bruno Oliveira](https://github.com/nicoddemus) added support for Conda.
164. [Michele Caini](https://github.com/skypjack) fixed links in the README. 164. [Michele Caini](https://github.com/skypjack) fixed links in the README.
@@ -1562,7 +1562,7 @@ I deeply appreciate the help of the following people.
200. [Alexander “weej” Jones](https://github.com/alex-weej) fixed an example in the README. 200. [Alexander “weej” Jones](https://github.com/alex-weej) fixed an example in the README.
201. [Antoine Cœur](https://github.com/Coeur) fixed some typos in the documentation. 201. [Antoine Cœur](https://github.com/Coeur) fixed some typos in the documentation.
202. [jothepro](https://github.com/jothepro) updated links to the Hunter package. 202. [jothepro](https://github.com/jothepro) updated links to the Hunter package.
203. [Dave Lee](https://github.com/kastiglione) fixed link in the README. 203. [Dave Lee](https://github.com/kastiglione) fixed a link in the README.
204. [Joël Lamotte](https://github.com/Klaim) added instruction for using Build2's package manager. 204. [Joël Lamotte](https://github.com/Klaim) added instruction for using Build2's package manager.
205. [Paul Jurczak](https://github.com/pauljurczak) fixed an example in the README. 205. [Paul Jurczak](https://github.com/pauljurczak) fixed an example in the README.
206. [Sonu Lohani](https://github.com/sonulohani) fixed a warning. 206. [Sonu Lohani](https://github.com/sonulohani) fixed a warning.
@@ -1605,7 +1605,7 @@ I deeply appreciate the help of the following people.
243. [raduteo](https://github.com/raduteo) fixed a warning. 243. [raduteo](https://github.com/raduteo) fixed a warning.
244. [David Pfahler](https://github.com/theShmoo) added the possibility to compile the library without I/O support. 244. [David Pfahler](https://github.com/theShmoo) added the possibility to compile the library without I/O support.
245. [Morten Fyhn Amundsen](https://github.com/mortenfyhn) fixed a typo. 245. [Morten Fyhn Amundsen](https://github.com/mortenfyhn) fixed a typo.
246. [jpl-mac](https://github.com/jpl-mac) allowed to treat the library as a system header in CMake. 246. [jpl-mac](https://github.com/jpl-mac) allowed treating the library as a system header in CMake.
247. [Jason Dsouza](https://github.com/jasmcaus) fixed the indentation of the CMake file. 247. [Jason Dsouza](https://github.com/jasmcaus) fixed the indentation of the CMake file.
248. [offa](https://github.com/offa) added a link to Conan Center to the documentation. 248. [offa](https://github.com/offa) added a link to Conan Center to the documentation.
249. [TotalCaesar659](https://github.com/TotalCaesar659) updated the links in the documentation to use HTTPS. 249. [TotalCaesar659](https://github.com/TotalCaesar659) updated the links in the documentation to use HTTPS.
@@ -1647,7 +1647,7 @@ I deeply appreciate the help of the following people.
285. [Wolf Vollprecht](https://github.com/wolfv) added the `patch_inplace` function. 285. [Wolf Vollprecht](https://github.com/wolfv) added the `patch_inplace` function.
286. [Jake Zimmerman](https://github.com/jez) highlighted common usage patterns in the README file. 286. [Jake Zimmerman](https://github.com/jez) highlighted common usage patterns in the README file.
287. [NN](https://github.com/NN---) added the Visual Studio output directory to `.gitignore`. 287. [NN](https://github.com/NN---) added the Visual Studio output directory to `.gitignore`.
288. [Romain Reignier](https://github.com/romainreignier) improved the performance the vector output adapter. 288. [Romain Reignier](https://github.com/romainreignier) improved the performance of the vector output adapter.
289. [Mike](https://github.com/Mike-Leo-Smith) fixed the `std::iterator_traits`. 289. [Mike](https://github.com/Mike-Leo-Smith) fixed the `std::iterator_traits`.
290. [Richard Hozák](https://github.com/zxey) added macro `JSON_NO_ENUM` to disable default enum conversions. 290. [Richard Hozák](https://github.com/zxey) added macro `JSON_NO_ENUM` to disable default enum conversions.
291. [vakokako](https://github.com/vakokako) fixed tests when compiling with C++20. 291. [vakokako](https://github.com/vakokako) fixed tests when compiling with C++20.
@@ -1694,9 +1694,9 @@ I deeply appreciate the help of the following people.
332. [taro](https://github.com/tarolling) fixed a typo in the `CODEOWNERS` file. 332. [taro](https://github.com/tarolling) fixed a typo in the `CODEOWNERS` file.
333. [Ikko Eltociear Ashimine](https://github.com/eltociear) fixed a typo. 333. [Ikko Eltociear Ashimine](https://github.com/eltociear) fixed a typo.
334. [Felix Yan](https://github.com/felixonmars) fixed a typo in the README. 334. [Felix Yan](https://github.com/felixonmars) fixed a typo in the README.
335. [HO-COOH](https://github.com/HO-COOH) fixed a parentheses in the documentation. 335. [HO-COOH](https://github.com/HO-COOH) fixed a parenthesis in the documentation.
336. [Ivor Wanders](https://github.com/iwanders) fixed the examples to catch exception by `const&`. 336. [Ivor Wanders](https://github.com/iwanders) fixed the examples to catch exception by `const&`.
337. [miny1233](https://github.com/miny1233) fixed a parentheses in the documentation. 337. [miny1233](https://github.com/miny1233) fixed a parenthesis in the documentation.
338. [tomalakgeretkal](https://github.com/tomalakgeretkal) fixed a compilation error. 338. [tomalakgeretkal](https://github.com/tomalakgeretkal) fixed a compilation error.
339. [alferov](https://github.com/ALF-ONE) fixed a compilation error. 339. [alferov](https://github.com/ALF-ONE) fixed a compilation error.
340. [Craig Scott](https://github.com/craigscott-crascit) fixed a deprecation warning in CMake. 340. [Craig Scott](https://github.com/craigscott-crascit) fixed a deprecation warning in CMake.
@@ -1779,7 +1779,7 @@ The library itself consists of a single header file licensed under the MIT licen
The library supports **Unicode input** as follows: The library supports **Unicode input** as follows:
- Only **UTF-8** encoded input is supported which is the default encoding for JSON according to [RFC 8259](https://tools.ietf.org/html/rfc8259.html#section-8.1). - Only **UTF-8** encoded input is supported, which is the default encoding for JSON according to [RFC 8259](https://tools.ietf.org/html/rfc8259.html#section-8.1).
- `std::u16string` and `std::u32string` can be parsed, assuming UTF-16 and UTF-32 encoding, respectively. These encodings are not supported when reading from files or other input containers. - `std::u16string` and `std::u32string` can be parsed, assuming UTF-16 and UTF-32 encoding, respectively. These encodings are not supported when reading from files or other input containers.
- Other encodings such as Latin-1 or ISO 8859-1 are **not** supported and will yield parse or serialization errors. - Other encodings such as Latin-1 or ISO 8859-1 are **not** supported and will yield parse or serialization errors.
- [Unicode noncharacters](https://www.unicode.org/faq/private_use.html#nonchar1) will not be replaced by the library. - [Unicode noncharacters](https://www.unicode.org/faq/private_use.html#nonchar1) will not be replaced by the library.
@@ -1801,7 +1801,17 @@ This library does not support comments by default. It does so for three reasons:
3. It is dangerous for interoperability if some libraries would add comment support while others don't. Please check [The Harmful Consequences of the Robustness Principle](https://tools.ietf.org/html/draft-iab-protocol-maintenance-01) on this. 3. It is dangerous for interoperability if some libraries would add comment support while others don't. Please check [The Harmful Consequences of the Robustness Principle](https://tools.ietf.org/html/draft-iab-protocol-maintenance-01) on this.
However, you can pass set parameter `ignore_comments` to true in the `parse` function to ignore `//` or `/* */` comments. Comments will then be treated as whitespace. However, you can set set parameter `ignore_comments` to true in the `parse` function to ignore `//` or `/* */` comments. Comments will then be treated as whitespace.
### Trailing commas
The JSON specification does not allow trailing commas in arrays and objects, and hence this library is treating them as parsing errors by default.
Like comments, you can set parameter `ignore_trailing_commas` to true in the `parse` function to ignore trailing commas in arrays and objects. Note that a single comma as the only content of the array or object (`[,]` or `{,}`) is not allowed, and multiple trailing commas (`[1,,]`) are not allowed either.
This library does not add trailing commas when serializing JSON data.
For more information, see [JSON With Commas and Comments (JWCC)](https://nigeltao.github.io/blog/2021/json-with-commas-comments.html).
### Order of object keys ### Order of object keys

View File

@@ -659,6 +659,17 @@ add_custom_target(ci_cuda_example
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_cuda_example COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_cuda_example
) )
###############################################################################
# C++ 20 modules
###############################################################################
add_custom_target(ci_module_cpp20
COMMAND ${CMAKE_COMMAND}
-DCMAKE_BUILD_TYPE=Debug -GNinja
-S${PROJECT_SOURCE_DIR}/tests/module_cpp20 -B${PROJECT_BINARY_DIR}/ci_module_cpp20
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/ci_module_cpp20
)
############################################################################### ###############################################################################
# Intel C++ Compiler # Intel C++ Compiler
############################################################################### ###############################################################################

View File

@@ -0,0 +1,31 @@
/*
* Detect used C++ Standard Library
*
* This file is compiled and run via try_run in download_test_data.cmake.
*/
#include <cstdio>
// see https://en.cppreference.com/w/cpp/header/ciso646
#if __cplusplus >= 202002L
#include <version>
#else
#include <ciso646>
#endif
int main()
{
#if defined(_LIBCPP_VERSION)
std::printf("LLVM C++ Standard Library (libc++), _LIBCPP_VERSION=%d", _LIBCPP_VERSION);
#elif defined(__GLIBCXX__)
std::printf("GNU C++ Standard Library (libstdc++), __GLIBCXX__=%d", __GLIBCXX__);
#elif defined(_MSVC_STL_VERSION)
std::printf("Microsoft C++ Standard Library (MSVC STL), _MSVC_STL_VERSION=%d", _MSVC_STL_VERSION);
#elif defined(_LIBCUDACXX_VERSION)
std::printf("NVIDIA C++ Standard Library (libcudacxx), _LIBCUDACXX_VERSION=%d", _LIBCUDACXX_VERSION);
#elif defined(EASTL_VERSION)
std::printf("Electronic Arts Standard Template Library (EASTL), EASTL_VERSION=%d", EASTL_VERSION);
#else
std::printf("unknown");
#endif
}

View File

@@ -54,3 +54,18 @@ else()
endif() endif()
string(REGEX REPLACE "[ ]*\n" "; " CXX_VERSION_RESULT "${CXX_VERSION_RESULT}") string(REGEX REPLACE "[ ]*\n" "; " CXX_VERSION_RESULT "${CXX_VERSION_RESULT}")
message(STATUS "Compiler: ${CXX_VERSION_RESULT}") message(STATUS "Compiler: ${CXX_VERSION_RESULT}")
# determine used C++ standard library (for debug and support purposes)
if(NOT DEFINED LIBCPP_VERSION_OUTPUT_CACHED)
try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR
"${CMAKE_BINARY_DIR}" SOURCES "${CMAKE_SOURCE_DIR}/cmake/detect_libcpp_version.cpp"
RUN_OUTPUT_VARIABLE LIBCPP_VERSION_OUTPUT COMPILE_OUTPUT_VARIABLE LIBCPP_VERSION_COMPILE_OUTPUT
)
if(NOT LIBCPP_VERSION_OUTPUT)
set(LIBCPP_VERSION_OUTPUT "Unknown")
message(AUTHOR_WARNING "Failed to compile cmake/detect_libcpp_version to detect the used C++ standard library. This does not affect the library or the test cases. Please still create an issue at https://github.com/nlohmann/json to investigate this.\n${LIBCPP_VERSION_COMPILE_OUTPUT}")
endif()
set(LIBCPP_VERSION_OUTPUT_CACHED "${LIBCPP_VERSION_OUTPUT}" CACHE STRING "Detected C++ standard library version")
endif()
message(STATUS "C++ standard library: ${LIBCPP_VERSION_OUTPUT_CACHED}")

View File

@@ -1,13 +1,13 @@
# Warning flags determined for GCC 14.2.0 with https://github.com/nlohmann/gcc_flags: # Warning flags determined for GCC 15.1.0 with https://github.com/nlohmann/gcc_flags:
# Ignored GCC warnings: # Ignored GCC warnings:
# -Wno-abi-tag We do not care about ABI tags. # -Wno-abi-tag We do not care about ABI tags.
# -Wno-aggregate-return The library uses aggregate returns. # -Wno-aggregate-return The library uses aggregate returns.
# -Wno-long-long The library uses the long long type to interface with system functions. # -Wno-long-long The library uses the long long type to interface with system functions.
# -Wno-namespaces The library uses namespaces. # -Wno-namespaces The library uses namespaces.
# -Wno-nrvo Doctest triggers this warning. # -Wno-nrvo Doctest triggers this warning.
# -Wno-padded We do not care about padding warnings. # -Wno-padded We do not care about padding warnings.
# -Wno-system-headers We do not care about warnings in system headers. # -Wno-system-headers We do not care about warnings in system headers.
# -Wno-templates The library uses templates. # -Wno-templates The library uses templates.
set(GCC_CXXFLAGS set(GCC_CXXFLAGS
-pedantic -pedantic
@@ -65,6 +65,7 @@ set(GCC_CXXFLAGS
-Wanalyzer-tainted-offset -Wanalyzer-tainted-offset
-Wanalyzer-tainted-size -Wanalyzer-tainted-size
-Wanalyzer-too-complex -Wanalyzer-too-complex
-Wanalyzer-undefined-behavior-ptrdiff
-Wanalyzer-undefined-behavior-strtok -Wanalyzer-undefined-behavior-strtok
-Wanalyzer-unsafe-call-within-signal-handler -Wanalyzer-unsafe-call-within-signal-handler
-Wanalyzer-use-after-free -Wanalyzer-use-after-free
@@ -123,6 +124,7 @@ set(GCC_CXXFLAGS
-Wcoverage-invalid-line-number -Wcoverage-invalid-line-number
-Wcoverage-mismatch -Wcoverage-mismatch
-Wcoverage-too-many-conditions -Wcoverage-too-many-conditions
-Wcoverage-too-many-paths
-Wcpp -Wcpp
-Wctad-maybe-unsupported -Wctad-maybe-unsupported
-Wctor-dtor-privacy -Wctor-dtor-privacy
@@ -130,6 +132,7 @@ set(GCC_CXXFLAGS
-Wdangling-pointer=2 -Wdangling-pointer=2
-Wdangling-reference -Wdangling-reference
-Wdate-time -Wdate-time
-Wdefaulted-function-deleted
-Wdelete-incomplete -Wdelete-incomplete
-Wdelete-non-virtual-dtor -Wdelete-non-virtual-dtor
-Wdeprecated -Wdeprecated
@@ -138,6 +141,8 @@ set(GCC_CXXFLAGS
-Wdeprecated-declarations -Wdeprecated-declarations
-Wdeprecated-enum-enum-conversion -Wdeprecated-enum-enum-conversion
-Wdeprecated-enum-float-conversion -Wdeprecated-enum-float-conversion
-Wdeprecated-literal-operator
-Wdeprecated-variadic-comma-omission
-Wdisabled-optimization -Wdisabled-optimization
-Wdiv-by-zero -Wdiv-by-zero
-Wdouble-promotion -Wdouble-promotion
@@ -157,20 +162,21 @@ set(GCC_CXXFLAGS
-Wfloat-conversion -Wfloat-conversion
-Wfloat-equal -Wfloat-equal
-Wformat -Wformat-contains-nul -Wformat -Wformat-contains-nul
-Wformat -Wformat-diag
-Wformat -Wformat-extra-args -Wformat -Wformat-extra-args
-Wformat -Wformat-nonliteral -Wformat -Wformat-nonliteral
-Wformat -Wformat-overflow=2
-Wformat -Wformat-security -Wformat -Wformat-security
-Wformat -Wformat-signedness
-Wformat -Wformat-truncation=2
-Wformat -Wformat-y2k -Wformat -Wformat-y2k
-Wformat -Wformat-zero-length -Wformat -Wformat-zero-length
-Wformat-diag
-Wformat-overflow=2
-Wformat-signedness
-Wformat-truncation=2
-Wformat=2 -Wformat=2
-Wframe-address -Wframe-address
-Wfree-nonheap-object -Wfree-nonheap-object
-Wglobal-module -Wglobal-module
-Whardened -Whardened
-Wheader-guard
-Whsa -Whsa
-Wif-not-aligned -Wif-not-aligned
-Wignored-attributes -Wignored-attributes
@@ -197,6 +203,7 @@ set(GCC_CXXFLAGS
-Wno-long-long -Wno-long-long
-Wlto-type-mismatch -Wlto-type-mismatch
-Wmain -Wmain
-Wmaybe-musttail-local-addr
-Wmaybe-uninitialized -Wmaybe-uninitialized
-Wmemset-elt-size -Wmemset-elt-size
-Wmemset-transposed-args -Wmemset-transposed-args
@@ -215,6 +222,7 @@ set(GCC_CXXFLAGS
-Wmultichar -Wmultichar
-Wmultiple-inheritance -Wmultiple-inheritance
-Wmultistatement-macros -Wmultistatement-macros
-Wmusttail-local-addr
-Wno-namespaces -Wno-namespaces
-Wnarrowing -Wnarrowing
-Wnoexcept -Wnoexcept
@@ -245,6 +253,7 @@ set(GCC_CXXFLAGS
-Wpmf-conversions -Wpmf-conversions
-Wpointer-arith -Wpointer-arith
-Wpointer-compare -Wpointer-compare
-Wpragma-once-outside-header
-Wpragmas -Wpragmas
-Wprio-ctor-dtor -Wprio-ctor-dtor
-Wpsabi -Wpsabi
@@ -276,10 +285,12 @@ set(GCC_CXXFLAGS
-Wsizeof-pointer-div -Wsizeof-pointer-div
-Wsizeof-pointer-memaccess -Wsizeof-pointer-memaccess
-Wstack-protector -Wstack-protector
-Wstrict-aliasing
-Wstrict-aliasing=3 -Wstrict-aliasing=3
-Wstrict-null-sentinel -Wstrict-null-sentinel
-Wstrict-overflow -Wstrict-overflow
-Wstring-compare -Wstring-compare
-Wstringop-overflow
-Wstringop-overflow=4 -Wstringop-overflow=4
-Wstringop-overread -Wstringop-overread
-Wstringop-truncation -Wstringop-truncation
@@ -304,8 +315,12 @@ set(GCC_CXXFLAGS
-Wsynth -Wsynth
-Wno-system-headers -Wno-system-headers
-Wtautological-compare -Wtautological-compare
-Wtemplate-body
-Wtemplate-id-cdtor
-Wtemplate-names-tu-local
-Wno-templates -Wno-templates
-Wterminate -Wterminate
-Wtrailing-whitespace
-Wtrampolines -Wtrampolines
-Wtrigraphs -Wtrigraphs
-Wtrivial-auto-var-init -Wtrivial-auto-var-init

View File

@@ -1 +1 @@
cpplint==2.0.1 cpplint==2.0.2

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

After

Width:  |  Height:  |  Size: 1.6 MiB

View File

@@ -1,6 +1,6 @@
{ {
"name": "JSON for Modern C++", "name": "JSON for Modern C++",
"version": "3.11.3", "version": "3.12.0",
"archive": "JSON_for_Modern_C++.tgz", "archive": "JSON_for_Modern_C++.tgz",
"author": { "author": {
"name": "Niels Lohmann", "name": "Niels Lohmann",

BIN
docs/json.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

View File

@@ -8,7 +8,7 @@ struct adl_serializer;
Serializer that uses ADL ([Argument-Dependent Lookup](https://en.cppreference.com/w/cpp/language/adl)) to choose Serializer that uses ADL ([Argument-Dependent Lookup](https://en.cppreference.com/w/cpp/language/adl)) to choose
`to_json`/`from_json` functions from the types' namespaces. `to_json`/`from_json` functions from the types' namespaces.
It is implemented similar to It is implemented similarly to
```cpp ```cpp
template<typename ValueType> template<typename ValueType>

View File

@@ -4,12 +4,14 @@
// (1) // (1)
template<typename InputType> template<typename InputType>
static bool accept(InputType&& i, static bool accept(InputType&& i,
const bool ignore_comments = false); const bool ignore_comments = false,
const bool ignore_trailing_commas = false);
// (2) // (2)
template<typename IteratorType> template<typename IteratorType>
static bool accept(IteratorType first, IteratorType last, static bool accept(IteratorType first, IteratorType last,
const bool ignore_comments = false); const bool ignore_comments = false,
const bool ignore_trailing_commas = false);
``` ```
Checks whether the input is valid JSON. Checks whether the input is valid JSON.
@@ -50,6 +52,10 @@ Unlike the [`parse()`](parse.md) function, this function neither throws an excep
: whether comments should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error : whether comments should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error
(`#!cpp false`); (optional, `#!cpp false` by default) (`#!cpp false`); (optional, `#!cpp false` by default)
`ignore_trailing_commas` (in)
: whether trailing commas in arrays or objects should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error
(`#!cpp false`); (optional, `#!cpp false` by default)
`first` (in) `first` (in)
: iterator to the start of the character range : iterator to the start of the character range
@@ -102,6 +108,7 @@ A UTF-8 byte order mark is silently ignored.
- Added in version 3.0.0. - Added in version 3.0.0.
- Ignoring comments via `ignore_comments` added in version 3.9.0. - Ignoring comments via `ignore_comments` added in version 3.9.0.
- Changed [runtime assertion](../../features/assertions.md) in case of `FILE*` null pointers to exception in version 3.12.0. - Changed [runtime assertion](../../features/assertions.md) in case of `FILE*` null pointers to exception in version 3.12.0.
- Added `ignore_trailing_commas` in version 3.12.1.
!!! warning "Deprecation" !!! warning "Deprecation"

View File

@@ -74,7 +74,7 @@ basic_json(basic_json&& other) noexcept;
- **boolean**: `boolean_t` / `bool` can be used. - **boolean**: `boolean_t` / `bool` can be used.
- **binary**: `binary_t` / `std::vector<uint8_t>` may be used; unfortunately because string literals cannot be - **binary**: `binary_t` / `std::vector<uint8_t>` may be used; unfortunately because string literals cannot be
distinguished from binary character arrays by the C++ type system, all types compatible with `const char*` will be distinguished from binary character arrays by the C++ type system, all types compatible with `const char*` will be
directed to the string constructor instead. This is both for backwards compatibility, and due to the fact that a directed to the string constructor instead. This is both for backwards compatibility and due to the fact that a
binary type is not a standard JSON type. binary type is not a standard JSON type.
See the examples below. See the examples below.

View File

@@ -4,7 +4,7 @@
bool empty() const noexcept; bool empty() const noexcept;
``` ```
Checks if a JSON value has no elements (i.e. whether its [`size()`](size.md) is `0`). Checks if a JSON value has no elements (i.e., whether its [`size()`](size.md) is `0`).
## Return value ## Return value

View File

@@ -29,11 +29,11 @@ void insert(const_iterator first, const_iterator last);
For all cases where an element is added to an **array**, a reallocation can happen, in which case all iterators For all cases where an element is added to an **array**, a reallocation can happen, in which case all iterators
(including the [`end()`](end.md) iterator) and all references to the elements are invalidated. Otherwise, only the (including the [`end()`](end.md) iterator) and all references to the elements are invalidated. Otherwise, only the
[`end()`](end.md) iterator is invalidated. Also, any iterator or reference after the insertion point will point to the [`end()`](end.md) iterator is invalidated. Also, any iterator or reference after the insertion point will point to the
same index which is now a different value. same index, which is now a different value.
For [`ordered_json`](../ordered_json.md), also adding an element to an **object** can yield a reallocation which again For [`ordered_json`](../ordered_json.md), also adding an element to an **object** can yield a reallocation which again
invalidates all iterators and all references. Also, any iterator or reference after the insertion point will point to invalidates all iterators and all references. Also, any iterator or reference after the insertion point will point to
the same index which is now a different value. the same index, which is now a different value.
## Parameters ## Parameters

View File

@@ -16,7 +16,7 @@ Examples of such functionality might be metadata, additional member functions (e
#### Default type #### Default type
The default value for `CustomBaseClass` is `void`. In this case an The default value for `CustomBaseClass` is `void`. In this case, an
[empty base class](https://en.cppreference.com/w/cpp/language/ebo) is used and no additional functionality is injected. [empty base class](https://en.cppreference.com/w/cpp/language/ebo) is used and no additional functionality is injected.
#### Limitations #### Limitations

View File

@@ -6,14 +6,16 @@ template<typename InputType>
static basic_json parse(InputType&& i, static basic_json parse(InputType&& i,
const parser_callback_t cb = nullptr, const parser_callback_t cb = nullptr,
const bool allow_exceptions = true, const bool allow_exceptions = true,
const bool ignore_comments = false); const bool ignore_comments = false,
const bool ignore_trailing_commas = false);
// (2) // (2)
template<typename IteratorType> template<typename IteratorType>
static basic_json parse(IteratorType first, IteratorType last, static basic_json parse(IteratorType first, IteratorType last,
const parser_callback_t cb = nullptr, const parser_callback_t cb = nullptr,
const bool allow_exceptions = true, const bool allow_exceptions = true,
const bool ignore_comments = false); const bool ignore_comments = false,
const bool ignore_trailing_commas = false);
``` ```
1. Deserialize from a compatible input. 1. Deserialize from a compatible input.
@@ -56,6 +58,10 @@ static basic_json parse(IteratorType first, IteratorType last,
: whether comments should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error : whether comments should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error
(`#!cpp false`); (optional, `#!cpp false` by default) (`#!cpp false`); (optional, `#!cpp false` by default)
`ignore_trailing_commas` (in)
: whether trailing commas in arrays or objects should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error
(`#!cpp false`); (optional, `#!cpp false` by default)
`first` (in) `first` (in)
: iterator to the start of a character range : iterator to the start of a character range
@@ -189,6 +195,34 @@ A UTF-8 byte order mark is silently ignored.
--8<-- "examples/parse__allow_exceptions.output" --8<-- "examples/parse__allow_exceptions.output"
``` ```
??? example "Effect of `ignore_comments` parameter"
The example below demonstrates the effect of the `ignore_comments` parameter in the `parse()` function.
```cpp
--8<-- "examples/comments.cpp"
```
Output:
```
--8<-- "examples/comments.output"
```
??? example "Effect of `ignore_trailing_commas` parameter"
The example below demonstrates the effect of the `ignore_trailing_commas` parameter in the `parse()` function.
```cpp
--8<-- "examples/trailing_commas.cpp"
```
Output:
```
--8<-- "examples/trailing_commas.output"
```
## See also ## See also
- [accept](accept.md) - check if the input is valid JSON - [accept](accept.md) - check if the input is valid JSON
@@ -200,6 +234,7 @@ A UTF-8 byte order mark is silently ignored.
- Overload for contiguous containers (1) added in version 2.0.3. - Overload for contiguous containers (1) added in version 2.0.3.
- Ignoring comments via `ignore_comments` added in version 3.9.0. - Ignoring comments via `ignore_comments` added in version 3.9.0.
- Changed [runtime assertion](../../features/assertions.md) in case of `FILE*` null pointers to exception in version 3.12.0. - Changed [runtime assertion](../../features/assertions.md) in case of `FILE*` null pointers to exception in version 3.12.0.
- Added `ignore_trailing_commas` in version 3.12.1.
!!! warning "Deprecation" !!! warning "Deprecation"

View File

@@ -7,7 +7,8 @@ static bool sax_parse(InputType&& i,
SAX* sax, SAX* sax,
input_format_t format = input_format_t::json, input_format_t format = input_format_t::json,
const bool strict = true, const bool strict = true,
const bool ignore_comments = false); const bool ignore_comments = false,
const bool ignore_trailing_commas = false);
// (2) // (2)
template<class IteratorType, class SAX> template<class IteratorType, class SAX>
@@ -15,7 +16,8 @@ static bool sax_parse(IteratorType first, IteratorType last,
SAX* sax, SAX* sax,
input_format_t format = input_format_t::json, input_format_t format = input_format_t::json,
const bool strict = true, const bool strict = true,
const bool ignore_comments = false); const bool ignore_comments = false,
const bool ignore_trailing_commas = false);
``` ```
Read from input and generate SAX events Read from input and generate SAX events
@@ -65,6 +67,10 @@ The SAX event lister must follow the interface of [`json_sax`](../json_sax/index
: whether comments should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error : whether comments should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error
(`#!cpp false`); (optional, `#!cpp false` by default) (`#!cpp false`); (optional, `#!cpp false` by default)
`ignore_trailing_commas` (in)
: whether trailing commas in arrays or objects should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error
(`#!cpp false`); (optional, `#!cpp false` by default)
`first` (in) `first` (in)
: iterator to the start of a character range : iterator to the start of a character range
@@ -107,6 +113,7 @@ A UTF-8 byte order mark is silently ignored.
- Added in version 3.2.0. - Added in version 3.2.0.
- Ignoring comments via `ignore_comments` added in version 3.9.0. - Ignoring comments via `ignore_comments` added in version 3.9.0.
- Added `ignore_trailing_commas` in version 3.12.1.
!!! warning "Deprecation" !!! warning "Deprecation"

View File

@@ -79,7 +79,7 @@ template<typename BasicJsonType>
void from_json(const BasicJsonType&, type&); void from_json(const BasicJsonType&, type&);
``` ```
Macros 3 and 6 add one function to the namespace which takes care of the serialization only: Macros 3 and 6 add one function to the namespace, which takes care of the serialization only:
```cpp ```cpp
template<typename BasicJsonType> template<typename BasicJsonType>

View File

@@ -46,7 +46,7 @@ template<typename BasicJsonType>
friend void from_json(const BasicJsonType&, type&); // except (3) friend void from_json(const BasicJsonType&, type&); // except (3)
``` ```
See examples below for the concrete generated code. See the examples below for the concrete generated code.
## Notes ## Notes

View File

@@ -46,7 +46,7 @@ template<typename BasicJsonType>
void from_json(const BasicJsonType&, type&); // except (3) void from_json(const BasicJsonType&, type&); // except (3)
``` ```
See examples below for the concrete generated code. See the examples below for the concrete generated code.
## Notes ## Notes

View File

@@ -4,8 +4,8 @@
#define NLOHMANN_JSON_SERIALIZE_ENUM(type, conversion...) #define NLOHMANN_JSON_SERIALIZE_ENUM(type, conversion...)
``` ```
By default, enum values are serialized to JSON as integers. In some cases this could result in undesired behavior. If an By default, enum values are serialized to JSON as integers. In some cases, this could result in undesired behavior. If
enum is modified or re-ordered after data has been serialized to JSON, the later deserialized JSON data may be an enum is modified or re-ordered after data has been serialized to JSON, the later deserialized JSON data may be
undefined or a different enum value than was originally intended. undefined or a different enum value than was originally intended.
The `NLOHMANN_JSON_SERIALIZE_ENUM` allows to define a user-defined serialization for every enumerator. The `NLOHMANN_JSON_SERIALIZE_ENUM` allows to define a user-defined serialization for every enumerator.

View File

@@ -11,7 +11,7 @@ This type preserves the insertion order of object keys.
The type is based on [`ordered_map`](ordered_map.md) which in turn uses a `std::vector` to store object elements. The type is based on [`ordered_map`](ordered_map.md) which in turn uses a `std::vector` to store object elements.
Therefore, adding object elements can yield a reallocation in which case all iterators (including the Therefore, adding object elements can yield a reallocation in which case all iterators (including the
[`end()`](basic_json/end.md) iterator) and all references to the elements are invalidated. Also, any iterator or [`end()`](basic_json/end.md) iterator) and all references to the elements are invalidated. Also, any iterator or
reference after the insertion point will point to the same index which is now a different value. reference after the insertion point will point to the same index, which is now a different value.
## Examples ## Examples

View File

@@ -57,6 +57,7 @@ violations will result in a failed build.
| Clang 19.1.7 | x86_64 | Ubuntu 22.04.1 LTS | GitHub | | Clang 19.1.7 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
| Clang 20.1.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub | | Clang 20.1.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
| Clang 21.0.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub | | Clang 21.0.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
| Emscripten 4.0.6 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
| GNU 4.8.5 | x86_64 | Ubuntu 22.04.1 LTS | GitHub | | GNU 4.8.5 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
| GNU 4.9.3 | x86_64 | Ubuntu 22.04.1 LTS | GitHub | | GNU 4.9.3 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
| GNU 5.5.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub | | GNU 5.5.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
@@ -75,6 +76,8 @@ violations will result in a failed build.
| GNU 13.3.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub | | GNU 13.3.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
| GNU 14.2.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub | | GNU 14.2.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
| GNU 14.2.0 | arm64 | Linux 6.1.100 | Cirrus CI | | GNU 14.2.0 | arm64 | Linux 6.1.100 | Cirrus CI |
| GNU 15.1.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
| icpc (ICC) 2021.5.0 20211109 | x86_64 | Ubuntu 20.04.3 LTS | GitHub |
| MSVC 19.0.24241.7 | x86 | Windows 8.1 | AppVeyor | | MSVC 19.0.24241.7 | x86 | Windows 8.1 | AppVeyor |
| MSVC 19.16.27035.0 | x86 | Windows-10 (Build 14393) | AppVeyor | | MSVC 19.16.27035.0 | x86 | Windows-10 (Build 14393) | AppVeyor |
| MSVC 19.29.30157.0 | x86 | Windows 10 (Build 17763) | GitHub | | MSVC 19.29.30157.0 | x86 | Windows 10 (Build 17763) | GitHub |

View File

@@ -0,0 +1,31 @@
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
std::string s = R"(
{
// update in 2006: removed Pluto
"planets": ["Mercury", "Venus", "Earth", "Mars",
"Jupiter", "Uranus", "Neptune" /*, "Pluto" */]
}
)";
try
{
json j = json::parse(s);
}
catch (json::exception& e)
{
std::cout << e.what() << std::endl;
}
json j = json::parse(s,
/* callback */ nullptr,
/* allow exceptions */ true,
/* ignore_comments */ true);
std::cout << j.dump(2) << '\n';
}

View File

@@ -0,0 +1,12 @@
[json.exception.parse_error.101] parse error at line 3, column 9: syntax error while parsing object key - invalid literal; last read: '<U+000A> {<U+000A> /'; expected string literal
{
"planets": [
"Mercury",
"Venus",
"Earth",
"Mars",
"Jupiter",
"Uranus",
"Neptune"
]
}

View File

@@ -2,16 +2,16 @@
"compiler": { "compiler": {
"c++": "201103", "c++": "201103",
"family": "gcc", "family": "gcc",
"version": "12.3.0" "version": "12.4.0"
}, },
"copyright": "(C) 2013-2022 Niels Lohmann", "copyright": "(C) 2013-2025 Niels Lohmann",
"name": "JSON for Modern C++", "name": "JSON for Modern C++",
"platform": "apple", "platform": "apple",
"url": "https://github.com/nlohmann/json", "url": "https://github.com/nlohmann/json",
"version": { "version": {
"major": 3, "major": 3,
"minor": 11, "minor": 12,
"patch": 3, "patch": 0,
"string": "3.11.3" "string": "3.12.0"
} }
} }

View File

@@ -1 +1 @@
nlohmann::json_abi_v3_11_3 nlohmann::json_abi_v3_12_0

View File

@@ -1 +1 @@
JSON for Modern C++ version 3.11.3 JSON for Modern C++ version 3.12.0

View File

@@ -0,0 +1,37 @@
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
std::string s = R"(
{
"planets": [
"Mercury",
"Venus",
"Earth",
"Mars",
"Jupiter",
"Uranus",
"Neptune",
]
}
)";
try
{
json j = json::parse(s);
}
catch (json::exception& e)
{
std::cout << e.what() << std::endl;
}
json j = json::parse(s,
/* callback */ nullptr,
/* allow exceptions */ true,
/* ignore_comments */ false,
/* ignore_trailing_commas */ true);
std::cout << j.dump(2) << '\n';
}

View File

@@ -0,0 +1,12 @@
[json.exception.parse_error.101] parse error at line 11, column 9: syntax error while parsing value - unexpected ']'; expected '[', '{', or a literal
{
"planets": [
"Mercury",
"Venus",
"Earth",
"Mars",
"Jupiter",
"Uranus",
"Neptune"
]
}

View File

@@ -1,7 +1,7 @@
# CBOR # CBOR
The Concise Binary Object Representation (CBOR) is a data format whose design goals include the possibility of extremely The Concise Binary Object Representation (CBOR) is a data format whose design goals include the possibility of
small code size, fairly small message size, and extensibility without the need for version negotiation. extremely small code sizes, fairly small message size, and extensibility without the need for version negotiation.
!!! abstract "References" !!! abstract "References"

View File

@@ -1,7 +1,7 @@
# Binary Values # Binary Values
The library implements several [binary formats](binary_formats/index.md) that encode JSON in an efficient way. Most of The library implements several [binary formats](binary_formats/index.md) that encode JSON in an efficient way. Most of
these formats support binary values; that is, values that have semantics define outside the library and only define a these formats support binary values; that is, values that have semantics defined outside the library and only define a
sequence of bytes to be stored. sequence of bytes to be stored.
JSON itself does not have a binary value. As such, binary values are an extension that this library implements to store JSON itself does not have a binary value. As such, binary values are an extension that this library implements to store
@@ -189,7 +189,7 @@ as an array of uint8 values. The library implements this translation.
### BSON ### BSON
[BSON](binary_formats/bson.md) supports binary values and subtypes. If a subtype is given, it is used and added as [BSON](binary_formats/bson.md) supports binary values and subtypes. If a subtype is given, it is used and added as an
unsigned 8-bit integer. If no subtype is given, the generic binary subtype 0x00 is used. unsigned 8-bit integer. If no subtype is given, the generic binary subtype 0x00 is used.
??? example ??? example
@@ -274,7 +274,7 @@ byte array.
[MessagePack](binary_formats/messagepack.md) supports binary values and subtypes. If a subtype is given, the ext family [MessagePack](binary_formats/messagepack.md) supports binary values and subtypes. If a subtype is given, the ext family
is used. The library will choose the smallest representation among fixext1, fixext2, fixext4, fixext8, ext8, ext16, and is used. The library will choose the smallest representation among fixext1, fixext2, fixext4, fixext8, ext8, ext16, and
ext32. The subtype is then added as signed 8-bit integer. ext32. The subtype is then added as a signed 8-bit integer.
If no subtype is given, the bin family (bin8, bin16, bin32) is used. If no subtype is given, the bin family (bin8, bin16, bin32) is used.

View File

@@ -11,7 +11,9 @@ This library does not support comments *by default*. It does so for three reason
3. It is dangerous for interoperability if some libraries add comment support while others do not. Please check [The Harmful Consequences of the Robustness Principle](https://tools.ietf.org/html/draft-iab-protocol-maintenance-01) on this. 3. It is dangerous for interoperability if some libraries add comment support while others do not. Please check [The Harmful Consequences of the Robustness Principle](https://tools.ietf.org/html/draft-iab-protocol-maintenance-01) on this.
However, you can pass set parameter `ignore_comments` to `#!c true` in the parse function to ignore `//` or `/* */` comments. Comments will then be treated as whitespace. However, you can set parameter `ignore_comments` to `#!cpp true` in the [`parse`](../api/basic_json/parse.md) function to ignore `//` or `/* */` comments. Comments will then be treated as whitespace.
For more information, see [JSON With Commas and Comments (JWCC)](https://nigeltao.github.io/blog/2021/json-with-commas-comments.html).
!!! example !!! example
@@ -28,56 +30,11 @@ However, you can pass set parameter `ignore_comments` to `#!c true` in the parse
When calling `parse` without additional argument, a parse error exception is thrown. If `ignore_comments` is set to `#! true`, the comments are ignored during parsing: When calling `parse` without additional argument, a parse error exception is thrown. If `ignore_comments` is set to `#! true`, the comments are ignored during parsing:
```cpp ```cpp
#include <iostream> --8<-- "examples/comments.cpp"
#include "json.hpp"
using json = nlohmann::json;
int main()
{
std::string s = R"(
{
// update in 2006: removed Pluto
"planets": ["Mercury", "Venus", "Earth", "Mars",
"Jupiter", "Uranus", "Neptune" /*, "Pluto" */]
}
)";
try
{
json j = json::parse(s);
}
catch (json::exception &e)
{
std::cout << e.what() << std::endl;
}
json j = json::parse(s,
/* callback */ nullptr,
/* allow exceptions */ true,
/* ignore_comments */ true);
std::cout << j.dump(2) << '\n';
}
``` ```
Output: Output:
``` ```
[json.exception.parse_error.101] parse error at line 3, column 9: --8<-- "examples/comments.output"
syntax error while parsing object key - invalid literal;
last read: '<U+000A> {<U+000A> /'; expected string literal
```
```json
{
"planets": [
"Mercury",
"Venus",
"Earth",
"Mars",
"Jupiter",
"Uranus",
"Neptune"
]
}
``` ```

View File

@@ -1,8 +1,8 @@
# Specializing enum conversion # Specializing enum conversion
By default, enum values are serialized to JSON as integers. In some cases this could result in undesired behavior. If an By default, enum values are serialized to JSON as integers. In some cases, this could result in undesired behavior. If
enum is modified or re-ordered after data has been serialized to JSON, the later deserialized JSON data may be the integer values of any enum values are changed after data using those enum values has been serialized to JSON, then
undefined or a different enum value than was originally intended. deserializing that JSON would result in a different enum value being restored, or the value not being found at all.
It is possible to more precisely specify how a given enum is mapped to and from JSON as shown below: It is possible to more precisely specify how a given enum is mapped to and from JSON as shown below:

View File

@@ -37,7 +37,7 @@ When iterating over objects, values are ordered with respect to the `object_comp
The reason for the order is the lexicographic ordering of the object keys "one", "three", "two". The reason for the order is the lexicographic ordering of the object keys "one", "three", "two".
### Access object key during iteration ### Access object keys during iteration
The JSON iterators have two member functions, `key()` and `value()` to access the object key and stored value, respectively. When calling `key()` on a non-object iterator, an [invalid_iterator.207](../home/exceptions.md#jsonexceptioninvalid_iterator207) exception is thrown. The JSON iterators have two member functions, `key()` and `value()` to access the object key and stored value, respectively. When calling `key()` on a non-object iterator, an [invalid_iterator.207](../home/exceptions.md#jsonexceptioninvalid_iterator207) exception is thrown.

View File

@@ -42,7 +42,7 @@ Note `/` does not identify the root (i.e., the whole document), but an object en
JSON Pointers can be created from a string: JSON Pointers can be created from a string:
```cpp ```cpp
json::json_pointer p = "/nested/one"; json::json_pointer p("/nested/one");
``` ```
Furthermore, a user-defined string literal can be used to achieve the same result: Furthermore, a user-defined string literal can be used to achieve the same result:

View File

@@ -64,7 +64,7 @@ configurations to be used in cases where the linker would otherwise output u
To do so, define [`NLOHMANN_JSON_NAMESPACE_NO_VERSION`](../api/macros/nlohmann_json_namespace_no_version.md) to `1`. To do so, define [`NLOHMANN_JSON_NAMESPACE_NO_VERSION`](../api/macros/nlohmann_json_namespace_no_version.md) to `1`.
This applies to version 3.11.2 and above only, versions 3.11.0 and 3.11.1 can apply the technique described in the next This applies to version 3.11.2 and above only; versions 3.11.0 and 3.11.1 can apply the technique described in the next
section to emulate the effect of the `NLOHMANN_JSON_NAMESPACE_NO_VERSION` macro. section to emulate the effect of the `NLOHMANN_JSON_NAMESPACE_NO_VERSION` macro.
!!! danger "Use at your own risk" !!! danger "Use at your own risk"

View File

@@ -0,0 +1,39 @@
# Trailing Commas
Like [comments](comments.md), this library does not support trailing commas in arrays and objects *by default*.
You can set parameter `ignore_trailing_commas` to `#!cpp true` in the [`parse`](../api/basic_json/parse.md) function to allow trailing commas in arrays and objects. Note that a single comma as the only content of the array or object (`[,]` or `{,}`) is not allowed, and multiple trailing commas (`[1,,]`) are not allowed either.
This library does not add trailing commas when serializing JSON data.
For more information, see [JSON With Commas and Comments (JWCC)](https://nigeltao.github.io/blog/2021/json-with-commas-comments.html).
!!! example
Consider the following JSON with trailing commas.
```json
{
"planets": [
"Mercury",
"Venus",
"Earth",
"Mars",
"Jupiter",
"Uranus",
"Neptune",
]
}
```
When calling `parse` without additional argument, a parse error exception is thrown. If `ignore_trailing_commas` is set to `#! true`, the trailing commas are ignored during parsing:
```cpp
--8<-- "examples/trailing_commas.cpp"
```
Output:
```
--8<-- "examples/trailing_commas.output"
```

View File

@@ -520,7 +520,7 @@ The order of object iterators cannot be compared, because JSON objects are unord
### json.exception.invalid_iterator.214 ### json.exception.invalid_iterator.214
Cannot get value for iterator: Either the iterator belongs to a null value or it is an iterator to a primitive type (number, boolean, or string), but the iterator is different to `begin()`. Cannot retrieve value from iterator: The iterator either refers to a null value, or it refers to a primitive type (number, boolean, or string), but does not match the iterator returned by `begin()`.
!!! failure "Example message" !!! failure "Example message"

View File

@@ -67,7 +67,7 @@ The library supports **Unicode input** as follows:
- The strings stored in the library are UTF-8 encoded. When using the default string type (`std::string`), note that its length/size functions return the number of stored bytes rather than the number of characters or glyphs. - The strings stored in the library are UTF-8 encoded. When using the default string type (`std::string`), note that its length/size functions return the number of stored bytes rather than the number of characters or glyphs.
- When you store strings with different encodings in the library, calling [`dump()`](https://nlohmann.github.io/json/classnlohmann_1_1basic__json_a50ec80b02d0f3f51130d4abb5d1cfdc5.html#a50ec80b02d0f3f51130d4abb5d1cfdc5) may throw an exception unless `json::error_handler_t::replace` or `json::error_handler_t::ignore` are used as error handlers. - When you store strings with different encodings in the library, calling [`dump()`](https://nlohmann.github.io/json/classnlohmann_1_1basic__json_a50ec80b02d0f3f51130d4abb5d1cfdc5.html#a50ec80b02d0f3f51130d4abb5d1cfdc5) may throw an exception unless `json::error_handler_t::replace` or `json::error_handler_t::ignore` are used as error handlers.
In most cases, the parser is right to complain, because the input is not UTF-8 encoded. This is especially true for Microsoft Windows where Latin-1 or ISO 8859-1 is often the standard encoding. In most cases, the parser is right to complain, because the input is not UTF-8 encoded. This is especially true for Microsoft Windows, where Latin-1 or ISO 8859-1 is often the standard encoding.
### Wide string handling ### Wide string handling

View File

@@ -1071,7 +1071,7 @@ This release combines a lot of small fixes and improvements. The release is back
- Improved the performance of the serialization by avoiding the re-creation of a locale object. - Improved the performance of the serialization by avoiding the re-creation of a locale object.
- Fixed two MSVC warnings. Compiling the test suite with `/Wall` now only warns about non-inlined functions (C4710) and the deprecation of the constructor from input-stream (C4996). - Fixed two MSVC warnings. Compiling the test suite with `/Wall` now only warns about non-inlined functions (C4710) and the deprecation of the constructor from input-stream (C4996).
- Some project internals: - Some project internals:
- <img align="right" src="https://bestpractices.coreinfrastructure.org/assets/questions_page_badge-17b338c0e8528d695d8676e23f39f17ca2b89bb88176370803ee69aeebcb5be4.png"> The project has qualified for the [Core Infrastructure Initiative Best Practices Badge](https://bestpractices.coreinfrastructure.org/projects/289). While most requirements where already satisfied, some led to a more explicit documentation of quality-ensuring procedures. For instance, static analysis is now executed with every commit on the build server. Furthermore, the [contribution guidelines document](https://github.com/nlohmann/json/blob/develop/.github/CONTRIBUTING.md) how to communicate security issues privately. - <img align="right" src="https://bestpractices.coreinfrastructure.org/assets/questions_page_badge-17b338c0e8528d695d8676e23f39f17ca2b89bb88176370803ee69aeebcb5be4.png"> The project has qualified for the [Core Infrastructure Initiative Best Practices Badge](https://bestpractices.coreinfrastructure.org/projects/289). While most requirements where already satisfied, some led to more explicit documentation of quality-ensuring procedures. For instance, static analysis is now executed with every commit on the build server. Furthermore, the [contribution guidelines document](https://github.com/nlohmann/json/blob/develop/.github/CONTRIBUTING.md) how to communicate security issues privately.
- The test suite has been overworked and split into several files to allow for faster compilation and analysis. The execute the test suite, simply execute `make check`. - The test suite has been overworked and split into several files to allow for faster compilation and analysis. The execute the test suite, simply execute `make check`.
- The continuous integration with [Travis](https://travis-ci.org/nlohmann/json) was extended with Clang versions 3.6.0 to 3.8.1 and now includes 18 different compiler/OS combinations. - The continuous integration with [Travis](https://travis-ci.org/nlohmann/json) was extended with Clang versions 3.6.0 to 3.8.1 and now includes 18 different compiler/OS combinations.
- An 11-day run of [American fuzzy lop](http://lcamtuf.coredump.cx/afl/) checked 962 million inputs on the parser and found no issue. - An 11-day run of [American fuzzy lop](http://lcamtuf.coredump.cx/afl/) checked 962 million inputs on the parser and found no issue.

View File

@@ -18,7 +18,7 @@ and use the namespaced imported target from the generated package configuration:
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.5)
project(ExampleProject LANGUAGES CXX) project(ExampleProject LANGUAGES CXX)
find_package(nlohmann_json 3.11.3 REQUIRED) find_package(nlohmann_json 3.12.0 REQUIRED)
add_executable(example example.cpp) add_executable(example example.cpp)
target_link_libraries(example PRIVATE nlohmann_json::nlohmann_json) target_link_libraries(example PRIVATE nlohmann_json::nlohmann_json)
@@ -77,7 +77,7 @@ to the following.
```cmake title="thirdparty/CMakeLists.txt" ```cmake title="thirdparty/CMakeLists.txt"
if(EXAMPLE_USE_EXTERNAL_JSON) if(EXAMPLE_USE_EXTERNAL_JSON)
find_package(nlohmann_json 3.11.3 REQUIRED) find_package(nlohmann_json 3.12.0 REQUIRED)
else() else()
set(JSON_BuildTests OFF CACHE INTERNAL "") set(JSON_BuildTests OFF CACHE INTERNAL "")
add_subdirectory(nlohmann_json) add_subdirectory(nlohmann_json)
@@ -100,7 +100,7 @@ automatically download a release as a dependency at configure time.
include(FetchContent) include(FetchContent)
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz) FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.12.0/json.tar.xz)
FetchContent_MakeAvailable(json) FetchContent_MakeAvailable(json)
add_executable(example example.cpp) add_executable(example example.cpp)
@@ -115,7 +115,7 @@ automatically download a release as a dependency at configure time.
```cmake ```cmake
FetchContent_Declare(json FetchContent_Declare(json
GIT_REPOSITORY https://github.com/nlohmann/json GIT_REPOSITORY https://github.com/nlohmann/json
GIT_TAG v3.11.3 GIT_TAG v3.12.0
) )
``` ```

View File

@@ -1,5 +1,5 @@
[requires] [requires]
nlohmann_json/3.11.3 nlohmann_json/3.12.0
[generators] [generators]
CMakeToolchain CMakeToolchain

View File

@@ -3,7 +3,7 @@ project(json_example)
include(${CMAKE_SOURCE_DIR}/cmake/CPM.cmake) include(${CMAKE_SOURCE_DIR}/cmake/CPM.cmake)
CPMAddPackage("gh:nlohmann/json@3.11.3") CPMAddPackage("gh:nlohmann/json@3.12.0")
add_executable(json_example example.cpp) add_executable(json_example example.cpp)
target_link_libraries(json_example PRIVATE nlohmann_json::nlohmann_json) target_link_libraries(json_example PRIVATE nlohmann_json::nlohmann_json)

View File

@@ -398,7 +398,7 @@ If you are using [cget](http://cget.readthedocs.io/en/latest/), you can install
cget install nlohmann/json cget install nlohmann/json
``` ```
A specific version can be installed with `cget install nlohmann/json@v3.11.3`. Also, the multiple header version can be A specific version can be installed with `cget install nlohmann/json@v3.12.0`. Also, the multiple header version can be
installed by adding the `-DJSON_MultipleHeaders=ON` flag (i.e., `cget install nlohmann/json -DJSON_MultipleHeaders=ON`). installed by adding the `-DJSON_MultipleHeaders=ON` flag (i.e., `cget install nlohmann/json -DJSON_MultipleHeaders=ON`).
??? example ??? example
@@ -727,7 +727,7 @@ If you are using [`CPM.cmake`](https://github.com/TheLartians/CPM.cmake), add th
[CPM.cmake script](https://github.com/TheLartians/CPM.cmake#adding-cpm) and the following snippet to your CMake project: [CPM.cmake script](https://github.com/TheLartians/CPM.cmake#adding-cpm) and the following snippet to your CMake project:
```cmake ```cmake
CPMAddPackage("gh:nlohmann/json@3.11.3") CPMAddPackage("gh:nlohmann/json@3.12.0")
``` ```
??? example ??? example

View File

@@ -67,6 +67,7 @@ nav:
- features/binary_formats/ubjson.md - features/binary_formats/ubjson.md
- features/binary_values.md - features/binary_values.md
- features/comments.md - features/comments.md
- features/trailing_commas.md
- Element Access: - Element Access:
- features/element_access/index.md - features/element_access/index.md
- features/element_access/unchecked_access.md - features/element_access/unchecked_access.md

View File

@@ -2,7 +2,7 @@ wheel==0.45.1
mkdocs==1.6.1 # documentation framework mkdocs==1.6.1 # documentation framework
mkdocs-git-revision-date-localized-plugin==1.4.5 # plugin "git-revision-date-localized" mkdocs-git-revision-date-localized-plugin==1.4.5 # plugin "git-revision-date-localized"
mkdocs-material==9.6.11 # theme for mkdocs mkdocs-material==9.6.14 # theme for mkdocs
mkdocs-material-extensions==1.3.1 # extensions mkdocs-material-extensions==1.3.1 # extensions
mkdocs-minify-plugin==0.8.0 # plugin "minify" mkdocs-minify-plugin==0.8.0 # plugin "minify"
mkdocs-redirects==1.2.2 # plugin "redirects" mkdocs-redirects==1.2.2 # plugin "redirects"

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>
@@ -12,15 +12,15 @@
#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK #ifndef JSON_SKIP_LIBRARY_VERSION_CHECK
#if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH) #if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH)
#if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 11 || NLOHMANN_JSON_VERSION_PATCH != 3 #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 12 || NLOHMANN_JSON_VERSION_PATCH != 0
#warning "Already included a different version of the library!" #warning "Already included a different version of the library!"
#endif #endif
#endif #endif
#endif #endif
#define NLOHMANN_JSON_VERSION_MAJOR 3 // NOLINT(modernize-macro-to-enum) #define NLOHMANN_JSON_VERSION_MAJOR 3 // NOLINT(modernize-macro-to-enum)
#define NLOHMANN_JSON_VERSION_MINOR 11 // NOLINT(modernize-macro-to-enum) #define NLOHMANN_JSON_VERSION_MINOR 12 // NOLINT(modernize-macro-to-enum)
#define NLOHMANN_JSON_VERSION_PATCH 3 // NOLINT(modernize-macro-to-enum) #define NLOHMANN_JSON_VERSION_PATCH 0 // NOLINT(modernize-macro-to-enum)
#ifndef JSON_DIAGNOSTICS #ifndef JSON_DIAGNOSTICS
#define JSON_DIAGNOSTICS 0 #define JSON_DIAGNOSTICS 0

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>
@@ -13,9 +13,6 @@
#include <forward_list> // forward_list #include <forward_list> // forward_list
#include <iterator> // inserter, front_inserter, end #include <iterator> // inserter, front_inserter, end
#include <map> // map #include <map> // map
#ifdef JSON_HAS_CPP_17
#include <optional> // optional
#endif
#include <string> // string #include <string> // string
#include <tuple> // tuple, make_tuple #include <tuple> // tuple, make_tuple
#include <type_traits> // is_arithmetic, is_same, is_enum, underlying_type, is_convertible #include <type_traits> // is_arithmetic, is_same, is_enum, underlying_type, is_convertible
@@ -32,6 +29,15 @@
#include <nlohmann/detail/string_concat.hpp> #include <nlohmann/detail/string_concat.hpp>
#include <nlohmann/detail/value_t.hpp> #include <nlohmann/detail/value_t.hpp>
// include after macro_scope.hpp
#ifdef JSON_HAS_CPP_17
#include <optional> // optional
#endif
#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
#include <string_view> // u8string_view
#endif
NLOHMANN_JSON_NAMESPACE_BEGIN NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail namespace detail
{ {
@@ -47,7 +53,6 @@ inline void from_json(const BasicJsonType& j, typename std::nullptr_t& n)
} }
#ifdef JSON_HAS_CPP_17 #ifdef JSON_HAS_CPP_17
#ifndef JSON_USE_IMPLICIT_CONVERSIONS
template<typename BasicJsonType, typename T> template<typename BasicJsonType, typename T>
void from_json(const BasicJsonType& j, std::optional<T>& opt) void from_json(const BasicJsonType& j, std::optional<T>& opt)
{ {
@@ -60,8 +65,6 @@ void from_json(const BasicJsonType& j, std::optional<T>& opt)
opt.emplace(j.template get<T>()); opt.emplace(j.template get<T>());
} }
} }
#endif // JSON_USE_IMPLICIT_CONVERSIONS
#endif // JSON_HAS_CPP_17 #endif // JSON_HAS_CPP_17
// overloads for basic_json template parameters // overloads for basic_json template parameters
@@ -395,7 +398,7 @@ inline void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
} }
// overload for arithmetic types, not chosen for basic_json template arguments // overload for arithmetic types, not chosen for basic_json template arguments
// (BooleanType, etc..); note: Is it really necessary to provide explicit // (BooleanType, etc.); note: Is it really necessary to provide explicit
// overloads for boolean_t etc. in case of a custom BooleanType which is not // overloads for boolean_t etc. in case of a custom BooleanType which is not
// an arithmetic type? // an arithmetic type?
template < typename BasicJsonType, typename ArithmeticType, template < typename BasicJsonType, typename ArithmeticType,
@@ -540,7 +543,10 @@ inline void from_json(const BasicJsonType& j, std_fs::path& p)
JSON_THROW(type_error::create(302, concat("type must be string, but is ", j.type_name()), &j)); JSON_THROW(type_error::create(302, concat("type must be string, but is ", j.type_name()), &j));
} }
const auto& s = *j.template get_ptr<const typename BasicJsonType::string_t*>(); const auto& s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
#ifdef JSON_HAS_CPP_20 // Checking for C++20 standard or later can be insufficient in case the
// library support for char8_t is either incomplete or was disabled
// altogether. Use the __cpp_lib_char8_t feature test instead.
#if defined(__cpp_lib_char8_t) && (__cpp_lib_char8_t >= 201907L)
p = std_fs::path(std::u8string_view(reinterpret_cast<const char8_t*>(s.data()), s.size())); p = std_fs::path(std::u8string_view(reinterpret_cast<const char8_t*>(s.data()), s.size()));
#else #else
p = std_fs::u8path(s); // accepts UTF-8 encoded std::string in C++17, deprecated in C++20 p = std_fs::u8path(s); // accepts UTF-8 encoded std::string in C++17, deprecated in C++20

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2009 Florian Loitsch <https://florian.loitsch.com/> // SPDX-FileCopyrightText: 2009 Florian Loitsch <https://florian.loitsch.com/>
@@ -130,7 +130,7 @@ struct diyfp // f * 2^e
// p_lo = p0_lo + (Q << 32) // p_lo = p0_lo + (Q << 32)
// //
// But in this particular case here, the full p_lo is not required. // But in this particular case here, the full p_lo is not required.
// Effectively we only need to add the highest bit in p_lo to p_hi (and // Effectively, we only need to add the highest bit in p_lo to p_hi (and
// Q_hi + 1 does not overflow). // Q_hi + 1 does not overflow).
Q += std::uint64_t{1} << (64u - 32u - 1u); // round, ties up Q += std::uint64_t{1} << (64u - 32u - 1u); // round, ties up
@@ -220,7 +220,7 @@ boundaries compute_boundaries(FloatType value)
// Compute the boundaries m- and m+ of the floating-point value // Compute the boundaries m- and m+ of the floating-point value
// v = f * 2^e. // v = f * 2^e.
// //
// Determine v- and v+, the floating-point predecessor and successor if v, // Determine v- and v+, the floating-point predecessor and successor of v,
// respectively. // respectively.
// //
// v- = v - 2^e if f != 2^(p-1) or e == e_min (A) // v- = v - 2^e if f != 2^(p-1) or e == e_min (A)
@@ -375,7 +375,7 @@ inline cached_power get_cached_power_for_binary_exponent(int e)
// (A smaller distance gamma-alpha would require a larger table.) // (A smaller distance gamma-alpha would require a larger table.)
// NB: // NB:
// Actually this function returns c, such that -60 <= e_c + e + 64 <= -34. // Actually, this function returns c, such that -60 <= e_c + e + 64 <= -34.
constexpr int kCachedPowersMinDecExp = -300; constexpr int kCachedPowersMinDecExp = -300;
constexpr int kCachedPowersDecStep = 8; constexpr int kCachedPowersDecStep = 8;
@@ -687,8 +687,8 @@ inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent,
decimal_exponent += n; decimal_exponent += n;
// We may now just stop. But instead look if the buffer could be // We may now just stop. But instead, it looks as if the buffer
// decremented to bring V closer to w. // could be decremented to bring V closer to w.
// //
// pow10 = 10^n is now 1 ulp in the decimal representation V. // pow10 = 10^n is now 1 ulp in the decimal representation V.
// The rounding procedure works with diyfp's with an implicit // The rounding procedure works with diyfp's with an implicit
@@ -1095,7 +1095,7 @@ char* to_chars(char* first, const char* last, FloatType value)
// Compute v = buffer * 10^decimal_exponent. // Compute v = buffer * 10^decimal_exponent.
// The decimal digits are stored in the buffer, which needs to be interpreted // The decimal digits are stored in the buffer, which needs to be interpreted
// as an unsigned decimal integer. // as an unsigned decimal integer.
// len is the length of the buffer, i.e. the number of decimal digits. // len is the length of the buffer, i.e., the number of decimal digits.
int len = 0; int len = 0;
int decimal_exponent = 0; int decimal_exponent = 0;
dtoa_impl::grisu2(first, len, decimal_exponent, value); dtoa_impl::grisu2(first, len, decimal_exponent, value);

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>
@@ -15,7 +15,8 @@
#include <algorithm> // copy #include <algorithm> // copy
#include <iterator> // begin, end #include <iterator> // begin, end
#include <string> // string #include <memory> // allocator_traits
#include <string> // basic_string, char_traits
#include <tuple> // tuple, get #include <tuple> // tuple, get
#include <type_traits> // is_same, is_constructible, is_floating_point, is_enum, underlying_type #include <type_traits> // is_same, is_constructible, is_floating_point, is_enum, underlying_type
#include <utility> // move, forward, declval, pair #include <utility> // move, forward, declval, pair
@@ -267,7 +268,7 @@ struct external_constructor<value_t::object>
#ifdef JSON_HAS_CPP_17 #ifdef JSON_HAS_CPP_17
template<typename BasicJsonType, typename T, template<typename BasicJsonType, typename T,
enable_if_t<std::is_constructible<BasicJsonType, T>::value, int> = 0> enable_if_t<std::is_constructible<BasicJsonType, T>::value, int> = 0>
void to_json(BasicJsonType& j, const std::optional<T>& opt) void to_json(BasicJsonType& j, const std::optional<T>& opt) noexcept
{ {
if (opt.has_value()) if (opt.has_value())
{ {
@@ -440,15 +441,21 @@ inline void to_json(BasicJsonType& j, const T& t)
} }
#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM #if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
#if defined(__cpp_lib_char8_t)
template<typename BasicJsonType, typename Tr, typename Allocator>
inline void to_json(BasicJsonType& j, const std::basic_string<char8_t, Tr, Allocator>& s)
{
using OtherAllocator = typename std::allocator_traits<Allocator>::template rebind_alloc<char>;
j = std::basic_string<char, std::char_traits<char>, OtherAllocator>(s.begin(), s.end(), s.get_allocator());
}
#endif
template<typename BasicJsonType> template<typename BasicJsonType>
inline void to_json(BasicJsonType& j, const std_fs::path& p) inline void to_json(BasicJsonType& j, const std_fs::path& p)
{ {
#ifdef JSON_HAS_CPP_20 // Returns either a std::string or a std::u8string depending whether library
const std::u8string s = p.u8string(); // support for char8_t is enabled.
j = std::string(s.begin(), s.end()); j = p.u8string();
#else
j = p.u8string(); // returns std::string in C++17
#endif
} }
#endif #endif

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>
@@ -30,7 +30,7 @@
// emitted in every translation unit. This issue cannot be fixed with a // emitted in every translation unit. This issue cannot be fixed with a
// header-only library as there is no implementation file to move these // header-only library as there is no implementation file to move these
// functions to. As a result, we suppress this warning here to avoid client // functions to. As a result, we suppress this warning here to avoid client
// code to stumble over this. See https://github.com/nlohmann/json/issues/4087 // code stumbling over this. See https://github.com/nlohmann/json/issues/4087
// for a discussion. // for a discussion.
#if defined(__clang__) #if defined(__clang__)
#pragma clang diagnostic push #pragma clang diagnostic push

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>
@@ -53,7 +53,7 @@ enum class cbor_tag_handler_t
@note from https://stackoverflow.com/a/1001328/266378 @note from https://stackoverflow.com/a/1001328/266378
*/ */
static inline bool little_endianness(int num = 1) noexcept inline bool little_endianness(int num = 1) noexcept
{ {
return *reinterpret_cast<char*>(&num) == 1; return *reinterpret_cast<char*>(&num) == 1;
} }
@@ -334,7 +334,7 @@ class binary_reader
return get_number<std::uint64_t, true>(input_format_t::bson, value) && sax->number_unsigned(value); return get_number<std::uint64_t, true>(input_format_t::bson, value) && sax->number_unsigned(value);
} }
default: // anything else not supported (yet) default: // anything else is not supported (yet)
{ {
std::array<char, 3> cr{{}}; std::array<char, 3> cr{{}};
static_cast<void>((std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(element_type))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) static_cast<void>((std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(element_type))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
@@ -731,7 +731,7 @@ class binary_reader
case 0xD2: case 0xD2:
case 0xD3: case 0xD3:
case 0xD4: case 0xD4:
case 0xD8: // tagged item (1 bytes follow) case 0xD8: // tagged item (1 byte follows)
case 0xD9: // tagged item (2 bytes follow) case 0xD9: // tagged item (2 bytes follow)
case 0xDA: // tagged item (4 bytes follow) case 0xDA: // tagged item (4 bytes follow)
case 0xDB: // tagged item (8 bytes follow) case 0xDB: // tagged item (8 bytes follow)
@@ -783,7 +783,7 @@ class binary_reader
case cbor_tag_handler_t::store: case cbor_tag_handler_t::store:
{ {
binary_t b; binary_t b;
// use binary subtype and store in binary container // use binary subtype and store in a binary container
switch (current) switch (current)
{ {
case 0xD8: case 0xD8:
@@ -852,7 +852,7 @@ class binary_reader
const auto byte1 = static_cast<unsigned char>(byte1_raw); const auto byte1 = static_cast<unsigned char>(byte1_raw);
const auto byte2 = static_cast<unsigned char>(byte2_raw); const auto byte2 = static_cast<unsigned char>(byte2_raw);
// code from RFC 7049, Appendix D, Figure 3: // Code from RFC 7049, Appendix D, Figure 3:
// As half-precision floating-point numbers were only added // As half-precision floating-point numbers were only added
// to IEEE 754 in 2008, today's programming platforms often // to IEEE 754 in 2008, today's programming platforms often
// still only have limited support for them. It is very // still only have limited support for them. It is very
@@ -2159,7 +2159,7 @@ class binary_reader
{ {
break; break;
} }
if (is_ndarray) // ndarray dimensional vector can only contain integers, and can not embed another array if (is_ndarray) // ndarray dimensional vector can only contain integers and cannot embed another array
{ {
return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, "ndarray dimensional vector is not allowed", "size"), nullptr)); return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, "ndarray dimensional vector is not allowed", "size"), nullptr));
} }
@@ -2192,8 +2192,16 @@ class binary_reader
result = 1; result = 1;
for (auto i : dim) for (auto i : dim)
{ {
// Pre-multiplication overflow check: if i > 0 and result > SIZE_MAX/i, then result*i would overflow.
// This check must happen before multiplication since overflow detection after the fact is unreliable
// as modular arithmetic can produce any value, not just 0 or SIZE_MAX.
if (JSON_HEDLEY_UNLIKELY(i > 0 && result > (std::numeric_limits<std::size_t>::max)() / i))
{
return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, exception_message(input_format, "excessive ndarray size caused overflow", "size"), nullptr));
}
result *= i; result *= i;
if (result == 0 || result == npos) // because dim elements shall not have zeros, result = 0 means overflow happened; it also can't be npos as it is used to initialize size in get_ubjson_size_type() // Additional post-multiplication check to catch any edge cases the pre-check might miss
if (result == 0 || result == npos)
{ {
return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, exception_message(input_format, "excessive ndarray size caused overflow", "size"), nullptr)); return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, exception_message(input_format, "excessive ndarray size caused overflow", "size"), nullptr));
} }
@@ -2409,7 +2417,7 @@ class binary_reader
const auto byte1 = static_cast<unsigned char>(byte1_raw); const auto byte1 = static_cast<unsigned char>(byte1_raw);
const auto byte2 = static_cast<unsigned char>(byte2_raw); const auto byte2 = static_cast<unsigned char>(byte2_raw);
// code from RFC 7049, Appendix D, Figure 3: // Code from RFC 7049, Appendix D, Figure 3:
// As half-precision floating-point numbers were only added // As half-precision floating-point numbers were only added
// to IEEE 754 in 2008, today's programming platforms often // to IEEE 754 in 2008, today's programming platforms often
// still only have limited support for them. It is very // still only have limited support for them. It is very
@@ -2697,7 +2705,7 @@ class binary_reader
bool get_ubjson_high_precision_number() bool get_ubjson_high_precision_number()
{ {
// get size of following number string // get the size of the following number string
std::size_t size{}; std::size_t size{};
bool no_ndarray = true; bool no_ndarray = true;
auto res = get_ubjson_size_value(size, no_ndarray); auto res = get_ubjson_size_value(size, no_ndarray);
@@ -2795,7 +2803,7 @@ class binary_reader
chars_read += new_chars_read; chars_read += new_chars_read;
if (JSON_HEDLEY_UNLIKELY(new_chars_read < sizeof(T))) if (JSON_HEDLEY_UNLIKELY(new_chars_read < sizeof(T)))
{ {
// in case of failure, advance position by 1 to report failing location // in case of failure, advance position by 1 to report the failing location
++chars_read; ++chars_read;
sax->parse_error(chars_read, "<end of file>", parse_error::create(110, chars_read, exception_message(format, "unexpected end of input", context), nullptr)); sax->parse_error(chars_read, "<end of file>", parse_error::create(110, chars_read, exception_message(format, "unexpected end of input", context), nullptr));
return false; return false;
@@ -2826,17 +2834,22 @@ class binary_reader
{ {
return; return;
} }
if constexpr(std::is_integral_v<NumberType>) else if constexpr(std::is_integral_v<NumberType>)
{ {
number = std::byteswap(number); number = std::byteswap(number);
return; return;
} }
#endif else
auto* ptr = reinterpret_cast<std::uint8_t*>(&number);
for (std::size_t i = 0; i < sz / 2; ++i)
{ {
std::swap(ptr[i], ptr[sz - i - 1]); #endif
auto* ptr = reinterpret_cast<std::uint8_t*>(&number);
for (std::size_t i = 0; i < sz / 2; ++i)
{
std::swap(ptr[i], ptr[sz - i - 1]);
}
#ifdef __cpp_lib_byteswap
} }
#endif
} }
/* /*

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>
@@ -108,7 +108,7 @@ class input_stream_adapter
: is(&i), sb(i.rdbuf()) : is(&i), sb(i.rdbuf())
{} {}
// delete because of pointer members // deleted because of pointer members
input_stream_adapter(const input_stream_adapter&) = delete; input_stream_adapter(const input_stream_adapter&) = delete;
input_stream_adapter& operator=(input_stream_adapter&) = delete; input_stream_adapter& operator=(input_stream_adapter&) = delete;
input_stream_adapter& operator=(input_stream_adapter&&) = delete; input_stream_adapter& operator=(input_stream_adapter&&) = delete;
@@ -122,7 +122,7 @@ class input_stream_adapter
// std::istream/std::streambuf use std::char_traits<char>::to_int_type, to // std::istream/std::streambuf use std::char_traits<char>::to_int_type, to
// ensure that std::char_traits<char>::eof() and the character 0xFF do not // ensure that std::char_traits<char>::eof() and the character 0xFF do not
// end up as the same value, e.g. 0xFFFFFFFF. // end up as the same value, e.g., 0xFFFFFFFF.
std::char_traits<char>::int_type get_character() std::char_traits<char>::int_type get_character()
{ {
auto res = sb->sbumpc(); auto res = sb->sbumpc();
@@ -344,7 +344,7 @@ class wide_string_input_adapter
typename std::char_traits<char>::int_type get_character() noexcept typename std::char_traits<char>::int_type get_character() noexcept
{ {
// check if buffer needs to be filled // check if the buffer needs to be filled
if (utf8_bytes_index == utf8_bytes_filled) if (utf8_bytes_index == utf8_bytes_filled)
{ {
fill_buffer<sizeof(WideCharType)>(); fill_buffer<sizeof(WideCharType)>();

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>
@@ -260,7 +260,7 @@ class json_sax_dom_parser
JSON_ASSERT(!ref_stack.empty()); JSON_ASSERT(!ref_stack.empty());
JSON_ASSERT(ref_stack.back()->is_object()); JSON_ASSERT(ref_stack.back()->is_object());
// add null at given key and store the reference for later // add null at the given key and store the reference for later
object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val)); object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val));
return true; return true;
} }
@@ -576,11 +576,11 @@ class json_sax_dom_callback_parser
{ {
BasicJsonType k = BasicJsonType(val); BasicJsonType k = BasicJsonType(val);
// check callback for key // check callback for the key
const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::key, k); const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::key, k);
key_keep_stack.push_back(keep); key_keep_stack.push_back(keep);
// add discarded value at given key and store the reference for later // add discarded value at the given key and store the reference for later
if (keep && ref_stack.back()) if (keep && ref_stack.back())
{ {
object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val) = discarded); object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val) = discarded);

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>
@@ -127,7 +127,7 @@ class lexer : public lexer_base<BasicJsonType>
, decimal_point_char(static_cast<char_int_type>(get_decimal_point())) , decimal_point_char(static_cast<char_int_type>(get_decimal_point()))
{} {}
// delete because of pointer members // deleted because of pointer members
lexer(const lexer&) = delete; lexer(const lexer&) = delete;
lexer(lexer&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) lexer(lexer&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
lexer& operator=(lexer&) = delete; lexer& operator=(lexer&) = delete;
@@ -262,10 +262,10 @@ class lexer : public lexer_base<BasicJsonType>
while (true) while (true)
{ {
// get next character // get the next character
switch (get()) switch (get())
{ {
// end of file while parsing string // end of file while parsing the string
case char_traits<char_type>::eof(): case char_traits<char_type>::eof():
{ {
error_message = "invalid string: missing closing quote"; error_message = "invalid string: missing closing quote";
@@ -351,7 +351,7 @@ class lexer : public lexer_base<BasicJsonType>
(static_cast<unsigned int>(codepoint1) << 10u) (static_cast<unsigned int>(codepoint1) << 10u)
// low surrogate occupies the least significant 15 bits // low surrogate occupies the least significant 15 bits
+ static_cast<unsigned int>(codepoint2) + static_cast<unsigned int>(codepoint2)
// there is still the 0xD800, 0xDC00 and 0x10000 noise // there is still the 0xD800, 0xDC00, and 0x10000 noise
// in the result, so we have to subtract with: // in the result, so we have to subtract with:
// (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00 // (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00
- 0x35FDC00u); - 0x35FDC00u);
@@ -377,7 +377,7 @@ class lexer : public lexer_base<BasicJsonType>
} }
} }
// result of the above calculation yields a proper codepoint // the result of the above calculation yields a proper codepoint
JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF); JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF);
// translate codepoint into bytes // translate codepoint into bytes
@@ -828,7 +828,7 @@ class lexer : public lexer_base<BasicJsonType>
break; break;
} }
// remaining bytes (80..C1 and F5..FF) are ill-formed // the remaining bytes (80..C1 and F5..FF) are ill-formed
default: default:
{ {
error_message = "invalid string: ill-formed UTF-8 byte"; error_message = "invalid string: ill-formed UTF-8 byte";
@@ -973,7 +973,7 @@ class lexer : public lexer_base<BasicJsonType>
reset(); reset();
// the type of the parsed number; initially set to unsigned; will be // the type of the parsed number; initially set to unsigned; will be
// changed if minus sign, decimal point or exponent is read // changed if minus sign, decimal point, or exponent is read
token_type number_type = token_type::value_unsigned; token_type number_type = token_type::value_unsigned;
// state (init): we just found out we need to scan a number // state (init): we just found out we need to scan a number
@@ -1345,7 +1345,7 @@ scan_number_done:
if (next_unget) if (next_unget)
{ {
// just reset the next_unget variable and work with current // only reset the next_unget variable and work with current
next_unget = false; next_unget = false;
} }
else else
@@ -1524,7 +1524,7 @@ scan_number_done:
return token_type::parse_error; return token_type::parse_error;
} }
// read next character and ignore whitespace // read the next character and ignore whitespace
skip_whitespace(); skip_whitespace();
// ignore comments // ignore comments

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>
@@ -71,10 +71,12 @@ class parser
explicit parser(InputAdapterType&& adapter, explicit parser(InputAdapterType&& adapter,
parser_callback_t<BasicJsonType> cb = nullptr, parser_callback_t<BasicJsonType> cb = nullptr,
const bool allow_exceptions_ = true, const bool allow_exceptions_ = true,
const bool skip_comments = false) const bool ignore_comments = false,
const bool ignore_trailing_commas_ = false)
: callback(std::move(cb)) : callback(std::move(cb))
, m_lexer(std::move(adapter), skip_comments) , m_lexer(std::move(adapter), ignore_comments)
, allow_exceptions(allow_exceptions_) , allow_exceptions(allow_exceptions_)
, ignore_trailing_commas(ignore_trailing_commas_)
{ {
// read first token // read first token
get_token(); get_token();
@@ -106,7 +108,7 @@ class parser
exception_message(token_type::end_of_input, "value"), nullptr)); exception_message(token_type::end_of_input, "value"), nullptr));
} }
// in case of an error, return discarded value // in case of an error, return a discarded value
if (sdp.is_errored()) if (sdp.is_errored())
{ {
result = value_t::discarded; result = value_t::discarded;
@@ -133,7 +135,7 @@ class parser
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), nullptr)); parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), nullptr));
} }
// in case of an error, return discarded value // in case of an error, return a discarded value
if (sdp.is_errored()) if (sdp.is_errored())
{ {
result = value_t::discarded; result = value_t::discarded;
@@ -336,7 +338,7 @@ class parser
case token_type::parse_error: case token_type::parse_error:
{ {
// using "uninitialized" to avoid "expected" message // using "uninitialized" to avoid an "expected" message
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized, "value"), nullptr)); parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized, "value"), nullptr));
@@ -384,11 +386,17 @@ class parser
if (states.back()) // array if (states.back()) // array
{ {
// comma -> next value // comma -> next value
// or end of array (ignore_trailing_commas = true)
if (get_token() == token_type::value_separator) if (get_token() == token_type::value_separator)
{ {
// parse a new value // parse a new value
get_token(); get_token();
continue;
// if ignore_trailing_commas and last_token is ], we can continue to "closing ]"
if (!(ignore_trailing_commas && last_token == token_type::end_array))
{
continue;
}
} }
// closing ] // closing ]
@@ -417,32 +425,39 @@ class parser
// states.back() is false -> object // states.back() is false -> object
// comma -> next value // comma -> next value
// or end of object (ignore_trailing_commas = true)
if (get_token() == token_type::value_separator) if (get_token() == token_type::value_separator)
{ {
// parse key
if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string))
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), nullptr));
}
if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
{
return false;
}
// parse separator (:)
if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), nullptr));
}
// parse values
get_token(); get_token();
continue;
// if ignore_trailing_commas and last_token is }, we can continue to "closing }"
if (!(ignore_trailing_commas && last_token == token_type::end_object))
{
// parse key
if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string))
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), nullptr));
}
if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
{
return false;
}
// parse separator (:)
if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), nullptr));
}
// parse values
get_token();
continue;
}
} }
// closing } // closing }
@@ -513,6 +528,8 @@ class parser
lexer_t m_lexer; lexer_t m_lexer;
/// whether to throw exceptions in case of errors /// whether to throw exceptions in case of errors
const bool allow_exceptions = true; const bool allow_exceptions = true;
/// whether trailing commas in objects and arrays should be ignored (true) or signaled as errors (false)
const bool ignore_trailing_commas = false;
}; };
} // namespace detail } // namespace detail

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>
@@ -23,7 +23,7 @@ NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail namespace detail
{ {
// forward declare, to be able to friend it later on // forward declare to be able to friend it later on
template<typename IteratorType> class iteration_proxy; template<typename IteratorType> class iteration_proxy;
template<typename IteratorType> class iteration_proxy_value; template<typename IteratorType> class iteration_proxy_value;

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>
@@ -21,9 +21,9 @@ namespace detail
@brief an iterator for primitive JSON types @brief an iterator for primitive JSON types
This class models an iterator for primitive JSON types (boolean, number, This class models an iterator for primitive JSON types (boolean, number,
string). It's only purpose is to allow the iterator/const_iterator classes string). Its only purpose is to allow the iterator/const_iterator classes
to "iterate" over primitive values. Internally, the iterator is modeled by to "iterate" over primitive values. Internally, the iterator is modeled by
a `difference_type` variable. Value begin_value (`0`) models the begin, a `difference_type` variable. Value begin_value (`0`) models the begin and
end_value (`1`) models past the end. end_value (`1`) models past the end.
*/ */
class primitive_iterator_t class primitive_iterator_t

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>
@@ -285,7 +285,7 @@ class json_pointer
{ {
if (reference_token == "0") if (reference_token == "0")
{ {
// start a new array if reference token is 0 // start a new array if the reference token is 0
result = &result->operator[](0); result = &result->operator[](0);
} }
else else
@@ -314,7 +314,7 @@ class json_pointer
The following code is only reached if there exists a reference The following code is only reached if there exists a reference
token _and_ the current value is primitive. In this case, we have token _and_ the current value is primitive. In this case, we have
an error situation, because primitive values may only occur as an error situation, because primitive values may only occur as
single value; that is, with an empty list of reference tokens. a single value; that is, with an empty list of reference tokens.
*/ */
case detail::value_t::string: case detail::value_t::string:
case detail::value_t::boolean: case detail::value_t::boolean:
@@ -358,7 +358,7 @@ class json_pointer
// convert null values to arrays or objects before continuing // convert null values to arrays or objects before continuing
if (ptr->is_null()) if (ptr->is_null())
{ {
// check if reference token is a number // check if the reference token is a number
const bool nums = const bool nums =
std::all_of(reference_token.begin(), reference_token.end(), std::all_of(reference_token.begin(), reference_token.end(),
[](const unsigned char x) [](const unsigned char x)
@@ -366,7 +366,7 @@ class json_pointer
return std::isdigit(x); return std::isdigit(x);
}); });
// change value to array for numbers or "-" or to object otherwise // change value to an array for numbers or "-" or to object otherwise
*ptr = (nums || reference_token == "-") *ptr = (nums || reference_token == "-")
? detail::value_t::array ? detail::value_t::array
: detail::value_t::object; : detail::value_t::object;
@@ -609,7 +609,7 @@ class json_pointer
{ {
if (JSON_HEDLEY_UNLIKELY(!('1' <= reference_token[0] && reference_token[0] <= '9'))) if (JSON_HEDLEY_UNLIKELY(!('1' <= reference_token[0] && reference_token[0] <= '9')))
{ {
// first char should be between '1' and '9' // the first char should be between '1' and '9'
return false; return false;
} }
for (std::size_t i = 1; i < reference_token.size(); i++) for (std::size_t i = 1; i < reference_token.size(); i++)
@@ -673,7 +673,7 @@ class json_pointer
return result; return result;
} }
// check if nonempty reference string begins with slash // check if a nonempty reference string begins with slash
if (JSON_HEDLEY_UNLIKELY(reference_string[0] != '/')) if (JSON_HEDLEY_UNLIKELY(reference_string[0] != '/'))
{ {
JSON_THROW(detail::parse_error::create(107, 1, detail::concat("JSON pointer must be empty or begin with '/' - was: '", reference_string, "'"), nullptr)); JSON_THROW(detail::parse_error::create(107, 1, detail::concat("JSON pointer must be empty or begin with '/' - was: '", reference_string, "'"), nullptr));
@@ -747,7 +747,7 @@ class json_pointer
} }
else else
{ {
// iterate array and use index as reference string // iterate array and use index as a reference string
for (std::size_t i = 0; i < value.m_data.m_value.array->size(); ++i) for (std::size_t i = 0; i < value.m_data.m_value.array->size(); ++i)
{ {
flatten(detail::concat<string_t>(reference_string, '/', std::to_string(i)), flatten(detail::concat<string_t>(reference_string, '/', std::to_string(i)),
@@ -785,7 +785,7 @@ class json_pointer
case detail::value_t::discarded: case detail::value_t::discarded:
default: default:
{ {
// add primitive value with its reference string // add a primitive value with its reference string
result[reference_string] = value; result[reference_string] = value;
break; break;
} }
@@ -821,17 +821,17 @@ class json_pointer
JSON_THROW(detail::type_error::create(315, "values in object must be primitive", &element.second)); JSON_THROW(detail::type_error::create(315, "values in object must be primitive", &element.second));
} }
// assign value to reference pointed to by JSON pointer; Note that if // Assign the value to the reference pointed to by JSON pointer. Note
// the JSON pointer is "" (i.e., points to the whole value), function // that if the JSON pointer is "" (i.e., points to the whole value),
// get_and_create returns a reference to result itself. An assignment // function get_and_create returns a reference to the result itself.
// will then create a primitive value. // An assignment will then create a primitive value.
json_pointer(element.first).get_and_create(result) = element.second; json_pointer(element.first).get_and_create(result) = element.second;
} }
return result; return result;
} }
// can't use conversion operator because of ambiguity // can't use the conversion operator because of ambiguity
json_pointer<string_t> convert() const& json_pointer<string_t> convert() const&
{ {
json_pointer<string_t> result; json_pointer<string_t> result;
@@ -926,7 +926,7 @@ class json_pointer
}; };
#if !JSON_HAS_THREE_WAY_COMPARISON #if !JSON_HAS_THREE_WAY_COMPARISON
// functions cannot be defined inside class due to ODR violations // functions cannot be defined inside the class due to ODR violations
template<typename RefStringTypeLhs, typename RefStringTypeRhs> template<typename RefStringTypeLhs, typename RefStringTypeRhs>
inline bool operator==(const json_pointer<RefStringTypeLhs>& lhs, inline bool operator==(const json_pointer<RefStringTypeLhs>& lhs,
const json_pointer<RefStringTypeRhs>& rhs) noexcept const json_pointer<RefStringTypeRhs>& rhs) noexcept

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>
@@ -31,9 +31,15 @@
#endif #endif
// C++ language standard detection // C++ language standard detection
// if the user manually specified the used c++ version this is skipped // if the user manually specified the used C++ version, this is skipped
#if !defined(JSON_HAS_CPP_23) && !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11) #if !defined(JSON_HAS_CPP_26) && !defined(JSON_HAS_CPP_23) && !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11)
#if (defined(__cplusplus) && __cplusplus > 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG > 202002L) #if (defined(__cplusplus) && __cplusplus > 202302L) || (defined(_MSVC_LANG) && _MSVC_LANG > 202302L)
#define JSON_HAS_CPP_26
#define JSON_HAS_CPP_23
#define JSON_HAS_CPP_20
#define JSON_HAS_CPP_17
#define JSON_HAS_CPP_14
#elif (defined(__cplusplus) && __cplusplus > 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG > 202002L)
#define JSON_HAS_CPP_23 #define JSON_HAS_CPP_23
#define JSON_HAS_CPP_20 #define JSON_HAS_CPP_20
#define JSON_HAS_CPP_17 #define JSON_HAS_CPP_17
@@ -128,7 +134,7 @@
#endif #endif
#ifndef JSON_HAS_RANGES #ifndef JSON_HAS_RANGES
// ranges header shipping in GCC 11.1.0 (released 2021-04-27) has syntax error // ranges header shipping in GCC 11.1.0 (released 2021-04-27) has a syntax error
#if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427 #if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427
#define JSON_HAS_RANGES 0 #define JSON_HAS_RANGES 0
#elif defined(__cpp_lib_ranges) #elif defined(__cpp_lib_ranges)
@@ -205,7 +211,7 @@
#define JSON_ASSERT(x) assert(x) #define JSON_ASSERT(x) assert(x)
#endif #endif
// allow to access some private functions (needed by the test suite) // allow accessing some private functions (needed by the test suite)
#if defined(JSON_TESTS_PRIVATE) #if defined(JSON_TESTS_PRIVATE)
#define JSON_PRIVATE_UNLESS_TESTED public #define JSON_PRIVATE_UNLESS_TESTED public
#else #else

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>
@@ -35,6 +35,7 @@
#undef JSON_HAS_CPP_17 #undef JSON_HAS_CPP_17
#undef JSON_HAS_CPP_20 #undef JSON_HAS_CPP_20
#undef JSON_HAS_CPP_23 #undef JSON_HAS_CPP_23
#undef JSON_HAS_CPP_26
#undef JSON_HAS_FILESYSTEM #undef JSON_HAS_FILESYSTEM
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
#undef JSON_HAS_THREE_WAY_COMPARISON #undef JSON_HAS_THREE_WAY_COMPARISON

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>
@@ -13,7 +13,9 @@
#include <tuple> // tuple #include <tuple> // tuple
#include <type_traits> // false_type, is_constructible, is_integral, is_same, true_type #include <type_traits> // false_type, is_constructible, is_integral, is_same, true_type
#include <utility> // declval #include <utility> // declval
#if defined(__cpp_lib_byte) && __cpp_lib_byte >= 201603L
#include <cstddef> // byte
#endif
#include <nlohmann/detail/iterators/iterator_traits.hpp> #include <nlohmann/detail/iterators/iterator_traits.hpp>
#include <nlohmann/detail/macro_scope.hpp> #include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/meta/call_std/begin.hpp> #include <nlohmann/detail/meta/call_std/begin.hpp>
@@ -40,12 +42,12 @@ namespace detail
// Note to maintainers: // Note to maintainers:
// //
// Every trait in this file expects a non CV-qualified type. // Every trait in this file expects a non-CV-qualified type.
// The only exceptions are in the 'aliases for detected' section // The only exceptions are in the 'aliases for detected' section
// (i.e. those of the form: decltype(T::member_function(std::declval<T>()))) // (i.e., those of the form: decltype(T::member_function(std::declval<T>())))
// //
// In this case, T has to be properly CV-qualified to constraint the function arguments // In this case, T has to be properly CV-qualified to constraint the function arguments
// (e.g. to_json(BasicJsonType&, const T&)) // (e.g., to_json(BasicJsonType&, const T&))
template<typename> struct is_basic_json : std::false_type {}; template<typename> struct is_basic_json : std::false_type {};
@@ -53,7 +55,7 @@ NLOHMANN_BASIC_JSON_TPL_DECLARATION
struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type {}; struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type {};
// used by exceptions create() member functions // used by exceptions create() member functions
// true_type for pointer to possibly cv-qualified basic_json or std::nullptr_t // true_type for the pointer to possibly cv-qualified basic_json or std::nullptr_t
// false_type otherwise // false_type otherwise
template<typename BasicJsonContext> template<typename BasicJsonContext>
struct is_basic_json_context : struct is_basic_json_context :
@@ -239,6 +241,30 @@ struct char_traits<signed char> : std::char_traits<char>
} }
}; };
#if defined(__cpp_lib_byte) && __cpp_lib_byte >= 201603L
template<>
struct char_traits<std::byte> : std::char_traits<char>
{
using char_type = std::byte;
using int_type = uint64_t;
static int_type to_int_type(char_type c) noexcept
{
return static_cast<int_type>(std::to_integer<unsigned char>(c));
}
static char_type to_char_type(int_type i) noexcept
{
return std::byte(static_cast<unsigned char>(i));
}
static constexpr int_type eof() noexcept
{
return static_cast<int_type>(std::char_traits<char>::eof());
}
};
#endif
/////////////////// ///////////////////
// is_ functions // // is_ functions //
/////////////////// ///////////////////
@@ -255,7 +281,7 @@ template<class B> struct negation : std::integral_constant < bool, !B::value > {
// Reimplementation of is_constructible and is_default_constructible, due to them being broken for // Reimplementation of is_constructible and is_default_constructible, due to them being broken for
// std::pair and std::tuple until LWG 2367 fix (see https://cplusplus.github.io/LWG/lwg-defects.html#2367). // std::pair and std::tuple until LWG 2367 fix (see https://cplusplus.github.io/LWG/lwg-defects.html#2367).
// This causes compile errors in e.g. clang 3.5 or gcc 4.9. // This causes compile errors in e.g., Clang 3.5 or GCC 4.9.
template <typename T> template <typename T>
struct is_default_constructible : std::is_default_constructible<T> {}; struct is_default_constructible : std::is_default_constructible<T> {};
@@ -335,7 +361,7 @@ using range_value_t = value_type_t<iterator_traits<iterator_t<T>>>;
// The following implementation of is_complete_type is taken from // The following implementation of is_complete_type is taken from
// https://blogs.msdn.microsoft.com/vcblog/2015/12/02/partial-support-for-expression-sfinae-in-vs-2015-update-1/ // https://blogs.msdn.microsoft.com/vcblog/2015/12/02/partial-support-for-expression-sfinae-in-vs-2015-update-1/
// and is written by Xiang Fan who agreed to using it in this library. // and is written by Xiang Fan who agreed to use it in this library.
template<typename T, typename = void> template<typename T, typename = void>
struct is_complete_type : std::false_type {}; struct is_complete_type : std::false_type {};
@@ -572,7 +598,7 @@ decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>()))
template<typename T> template<typename T>
using detect_is_transparent = typename T::is_transparent; using detect_is_transparent = typename T::is_transparent;
// type trait to check if KeyType can be used as object key (without a BasicJsonType) // type trait to check if KeyType can be used as an object key (without a BasicJsonType)
// see is_usable_as_basic_json_key_type below // see is_usable_as_basic_json_key_type below
template<typename Comparator, typename ObjectKeyType, typename KeyTypeCVRef, bool RequireTransparentComparator = true, template<typename Comparator, typename ObjectKeyType, typename KeyTypeCVRef, bool RequireTransparentComparator = true,
bool ExcludeObjectKeyType = RequireTransparentComparator, typename KeyType = uncvref_t<KeyTypeCVRef>> bool ExcludeObjectKeyType = RequireTransparentComparator, typename KeyType = uncvref_t<KeyTypeCVRef>>
@@ -586,7 +612,7 @@ using is_usable_as_key_type = typename std::conditional <
std::true_type, std::true_type,
std::false_type >::type; std::false_type >::type;
// type trait to check if KeyType can be used as object key // type trait to check if KeyType can be used as an object key
// true if: // true if:
// - KeyType is comparable with BasicJsonType::object_t::key_type // - KeyType is comparable with BasicJsonType::object_t::key_type
// - if ExcludeObjectKeyType is true, KeyType is not BasicJsonType::object_t::key_type // - if ExcludeObjectKeyType is true, KeyType is not BasicJsonType::object_t::key_type

View File

@@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3 // | | |__ | | | | | | version 3.12.0
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>

Some files were not shown because too many files have changed in this diff Show More