mirror of
https://github.com/nlohmann/json.git
synced 2026-02-17 09:03:58 +00:00
Compare commits
156 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cd1e38dcc4 | ||
|
|
7c97655f59 | ||
|
|
17b5262e7d | ||
|
|
1b9a9d1f21 | ||
|
|
935c6eeb5a | ||
|
|
e41905fcb0 | ||
|
|
d333f08958 | ||
|
|
3d6c664de2 | ||
|
|
ee32bfc1c2 | ||
|
|
a97041a98f | ||
|
|
f9f8c07792 | ||
|
|
378e091795 | ||
|
|
1f218e1074 | ||
|
|
64f68dc563 | ||
|
|
1c5923e5d6 | ||
|
|
e3ac5a64bf | ||
|
|
e509007df2 | ||
|
|
060414037e | ||
|
|
fd20975a94 | ||
|
|
fde9a86c5a | ||
|
|
1825117e63 | ||
|
|
4a602df34e | ||
|
|
18ff442e63 | ||
|
|
aff5a31d35 | ||
|
|
ac8b22180d | ||
|
|
6325839776 | ||
|
|
b36f4c477c | ||
|
|
960b763ecd | ||
|
|
8c391e04fe | ||
|
|
01da82eae2 | ||
|
|
97f0bdaf9a | ||
|
|
c883fb0f17 | ||
|
|
377c767aa1 | ||
|
|
16b3d841d5 | ||
|
|
199dea11b1 | ||
|
|
0457de21cf | ||
|
|
c35d260c2f | ||
|
|
6a064e026a | ||
|
|
7efe875495 | ||
|
|
a259ecc51e | ||
|
|
3780b41dd0 | ||
|
|
9cca280a4d | ||
|
|
1d597743d8 | ||
|
|
f56c6e2e30 | ||
|
|
360ce457f4 | ||
|
|
5d931c59a3 | ||
|
|
6eab7a2b18 | ||
|
|
1dfe4073e3 | ||
|
|
4ffd5bd18e | ||
|
|
0261bc04d3 | ||
|
|
59da644db4 | ||
|
|
cdb29069da | ||
|
|
58d6aa5831 | ||
|
|
edffad036d | ||
|
|
6adae02ddd | ||
|
|
35c0b3e54c | ||
|
|
fac07e22c5 | ||
|
|
6d4b72d3c3 | ||
|
|
bbd2e1636d | ||
|
|
6e36c721f0 | ||
|
|
e75b94b31e | ||
|
|
aa87ab8b40 | ||
|
|
1ce29fa22f | ||
|
|
5fec803493 | ||
|
|
da92c0e3e7 | ||
|
|
836b7beca4 | ||
|
|
788e5468e4 | ||
|
|
6cc0eaf88f | ||
|
|
5d2754306d | ||
|
|
c71ecde505 | ||
|
|
793878898f | ||
|
|
254395e5f7 | ||
|
|
ab06fc9951 | ||
|
|
a0c1318830 | ||
|
|
6af826d0bd | ||
|
|
546370c9e7 | ||
|
|
bbe337c3a3 | ||
|
|
fe4b66355c | ||
|
|
31c00dc729 | ||
|
|
6cec5aefc9 | ||
|
|
b504dca35a | ||
|
|
660d0b5856 | ||
|
|
b2306145e1 | ||
|
|
8fa0d7bb7e | ||
|
|
233d233439 | ||
|
|
da6b908c4f | ||
|
|
4c6cde72e5 | ||
|
|
a2f0593649 | ||
|
|
80dfb049b3 | ||
|
|
2ca8dabeb9 | ||
|
|
885aa0014e | ||
|
|
7f72eedc2d | ||
|
|
094a3dc105 | ||
|
|
ea870ea247 | ||
|
|
3c616ed688 | ||
|
|
813c329fbb | ||
|
|
97f88ce21d | ||
|
|
44423b4d8f | ||
|
|
3e990876e1 | ||
|
|
b6dcf3edf3 | ||
|
|
07182ebc1d | ||
|
|
f7d46b8803 | ||
|
|
84e5a321eb | ||
|
|
23e69222c5 | ||
|
|
5fa4e66d37 | ||
|
|
c700a9ecbb | ||
|
|
c5a03c2ea0 | ||
|
|
349e4b310e | ||
|
|
8f8315368b | ||
|
|
24ba54e687 | ||
|
|
a3e6e26dc8 | ||
|
|
4b2c8ce6bc | ||
|
|
17d9eacd24 | ||
|
|
f4658de270 | ||
|
|
3d1252bbff | ||
|
|
2d1f9b6a7d | ||
|
|
9dfa722669 | ||
|
|
c920f3f4fb | ||
|
|
15ca78a886 | ||
|
|
58bd97e2b1 | ||
|
|
307c053b9b | ||
|
|
bed648ca55 | ||
|
|
f7973f46d6 | ||
|
|
4c8cdd7afc | ||
|
|
8fcdbf2e77 | ||
|
|
bc889afb4c | ||
|
|
9d69186291 | ||
|
|
32bbd38072 | ||
|
|
c0dae0f510 | ||
|
|
0e61ee8b07 | ||
|
|
93112fbf4d | ||
|
|
a92ccafd2c | ||
|
|
e1a3fb74ba | ||
|
|
d79d12f854 | ||
|
|
31265dc69c | ||
|
|
231f3108ff | ||
|
|
dae5412268 | ||
|
|
0c7a18374c | ||
|
|
8eee62d388 | ||
|
|
f1e34070d2 | ||
|
|
bfbe774d8f | ||
|
|
b0422f8013 | ||
|
|
7b6cf5918b | ||
|
|
9e1a7c85e3 | ||
|
|
e839f58a2a | ||
|
|
01af734d63 | ||
|
|
b13b8748b6 | ||
|
|
b6e2942d1c | ||
|
|
500bdc56bf | ||
|
|
98d70d4676 | ||
|
|
22cd1c9eb9 | ||
|
|
ac20714e2e | ||
|
|
2ac7d023d4 | ||
|
|
32242022f7 | ||
|
|
ac9e668e63 | ||
|
|
df98ca29f8 |
@@ -1,22 +1,17 @@
|
||||
kind: pipeline
|
||||
name: test-on-arm64
|
||||
arm_container:
|
||||
image: gcc:latest
|
||||
|
||||
platform:
|
||||
arch: arm64
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: gcc
|
||||
commands:
|
||||
check_task:
|
||||
check_script:
|
||||
- wget https://github.com/Kitware/CMake/releases/download/v3.20.2/cmake-3.20.2.tar.gz
|
||||
- tar xfz cmake-3.20.2.tar.gz
|
||||
- cd cmake-3.20.2
|
||||
- ./configure
|
||||
- make cmake ctest -j10
|
||||
- make cmake ctest -j4
|
||||
- cd ..
|
||||
- mkdir build
|
||||
- cd build
|
||||
- ../cmake-3.20.2/bin/cmake .. -DJSON_FastTests=ON
|
||||
- make -j10
|
||||
- make -j4
|
||||
- cd tests
|
||||
- ../../cmake-3.20.2/bin/ctest -j10
|
||||
- ../../cmake-3.20.2/bin/ctest -j4
|
||||
20
.clang-tidy
20
.clang-tidy
@@ -1,11 +1,21 @@
|
||||
# TODO: The first three checks are only removed to get the CI going. They have to be addressed at some point.
|
||||
|
||||
Checks: '*,
|
||||
|
||||
-portability-template-virtual-member-function,
|
||||
-bugprone-use-after-move,
|
||||
-hicpp-invalid-access-moved,
|
||||
|
||||
-altera-id-dependent-backward-branch,
|
||||
-altera-struct-pack-align,
|
||||
-altera-unroll-loops,
|
||||
-android-cloexec-fopen,
|
||||
-boost-use-ranges,
|
||||
-bugprone-easily-swappable-parameters,
|
||||
-cert-err58-cpp,
|
||||
-concurrency-mt-unsafe,
|
||||
-cppcoreguidelines-avoid-const-or-ref-data-members,
|
||||
-cppcoreguidelines-avoid-do-while,
|
||||
-cppcoreguidelines-avoid-goto,
|
||||
-cppcoreguidelines-avoid-magic-numbers,
|
||||
-cppcoreguidelines-avoid-non-const-global-variables,
|
||||
@@ -15,6 +25,7 @@ Checks: '*,
|
||||
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
|
||||
-cppcoreguidelines-pro-type-reinterpret-cast,
|
||||
-cppcoreguidelines-pro-type-union-access,
|
||||
-cppcoreguidelines-rvalue-reference-param-not-moved,
|
||||
-cppcoreguidelines-virtual-class-destructor,
|
||||
-fuchsia-default-arguments-calls,
|
||||
-fuchsia-default-arguments-declarations,
|
||||
@@ -33,11 +44,20 @@ Checks: '*,
|
||||
-llvm-header-guard,
|
||||
-llvm-include-order,
|
||||
-llvmlibc-*,
|
||||
-misc-use-anonymous-namespace,
|
||||
-misc-confusable-identifiers,
|
||||
-misc-include-cleaner,
|
||||
-misc-no-recursion,
|
||||
-misc-non-private-member-variables-in-classes,
|
||||
-modernize-concat-nested-namespaces,
|
||||
-modernize-type-traits,
|
||||
-modernize-use-constraints,
|
||||
-modernize-use-designated-initializers,
|
||||
-modernize-use-nodiscard,
|
||||
-modernize-use-ranges,
|
||||
-modernize-use-std-numbers,
|
||||
-modernize-use-trailing-return-type,
|
||||
-performance-enum-size,
|
||||
-readability-function-cognitive-complexity,
|
||||
-readability-function-size,
|
||||
-readability-identifier-length,
|
||||
|
||||
4
.github/CODEOWNERS
vendored
4
.github/CODEOWNERS
vendored
@@ -1,5 +1,5 @@
|
||||
# JSON for Modern C++ has been originally written by Niels Lohmann.
|
||||
# Since 2013 over 140 contributors have helped to improve the library.
|
||||
# JSON for Modern C++ was originally written by Niels Lohmann.
|
||||
# Since 2013, over 250 contributors have helped to improve the library.
|
||||
# This CODEOWNERS file is only to make sure that @nlohmann is requested
|
||||
# for a code review in case of a pull request.
|
||||
|
||||
|
||||
12
.github/CONTRIBUTING.md
vendored
12
.github/CONTRIBUTING.md
vendored
@@ -1,5 +1,3 @@
|
||||
[](http://issuestats.com/github/nlohmann/json) [](http://issuestats.com/github/nlohmann/json)
|
||||
|
||||
# How to contribute
|
||||
|
||||
This project started as a little excuse to exercise some of the cool new C++11 features. Over time, people actually started to use the JSON library (yey!) and started to help improve it by proposing features, finding bugs, or even fixing my mistakes. I am really [thankful](https://github.com/nlohmann/json/blob/master/README.md#thanks) for this and try to keep track of all the helpers.
|
||||
@@ -22,17 +20,17 @@ Clearly describe the issue:
|
||||
- If you propose a change or addition, try to give an **example** how the improved code could look like or how to use it.
|
||||
- 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.
|
||||
|
||||
Please stick to the provided issue templates ([bug report](https://github.com/nlohmann/json/blob/develop/.github/ISSUE_TEMPLATE/Bug_report.md), [feature request](https://github.com/nlohmann/json/blob/develop/.github/ISSUE_TEMPLATE/Feature_request.md), or [question](https://github.com/nlohmann/json/blob/develop/.github/ISSUE_TEMPLATE/question.md)) if possible.
|
||||
Please stick to the provided issue template ([bug report](https://github.com/nlohmann/json/blob/develop/.github/ISSUE_TEMPLATE/bug.yaml) if possible. For questions, feature or support requests, please [open a discussion](https://github.com/nlohmann/json/discussions/new).
|
||||
|
||||
## Files to change
|
||||
|
||||
:exclamation: Before you make any changes, note the single-header file [`single_include/nlohmann/json.hpp`](https://github.com/nlohmann/json/blob/develop/single_include/nlohmann/json.hpp) is **generated** from the source files in the [`include/nlohmann` directory](https://github.com/nlohmann/json/tree/develop/include/nlohmann). Please **do not** edit file `single_include/nlohmann/json.hpp` directly, but change the `include/nlohmann` sources and regenerate file `single_include/nlohmann/json.hpp` by executing `make amalgamate`.
|
||||
:exclamation: Before you make any changes, note the single-header files [`single_include/nlohmann/json.hpp`](https://github.com/nlohmann/json/blob/develop/single_include/nlohmann/json.hpp) and [`single_include/nlohmann/json_fwd.hpp`](https://github.com/nlohmann/json/blob/develop/single_include/nlohmann/json_fwd.hpp) are **generated** from the source files in the [`include/nlohmann` directory](https://github.com/nlohmann/json/tree/develop/include/nlohmann). Please **do not** edit the files `single_include/nlohmann/json.hpp` and `single_include/nlohmann/json_fwd.hpp` directly, but change the `include/nlohmann` sources and regenerate the files by executing `make amalgamate`.
|
||||
|
||||
To make changes, you need to edit the following files:
|
||||
|
||||
1. [`include/nlohmann/*`](https://github.com/nlohmann/json/tree/develop/include/nlohmann) - These files are the sources of the library. Before testing or creating a pull request, execute `make amalgamate` to regenerate `single_include/nlohmann/json.hpp`.
|
||||
1. [`include/nlohmann/*`](https://github.com/nlohmann/json/tree/develop/include/nlohmann) - These files are the sources of the library. Before testing or creating a pull request, execute `make amalgamate` to regenerate `single_include/nlohmann/json.hpp` and `single_include/nlohmann/json_fwd.hpp`.
|
||||
|
||||
2. [`test/src/unit-*.cpp`](https://github.com/nlohmann/json/tree/develop/test/src) - These files contain the [doctest](https://github.com/onqtam/doctest) unit tests which currently cover [100 %](https://coveralls.io/github/nlohmann/json) of the library's code.
|
||||
2. [`tests/src/unit-*.cpp`](https://github.com/nlohmann/json/tree/develop/tests/src) - These files contain the [doctest](https://github.com/onqtam/doctest) unit tests which currently cover [100 %](https://coveralls.io/github/nlohmann/json) of the library's code. Before creating a pull request, execute `make pretty` to make sure that the style is correct, as this will be checked by the CI.
|
||||
|
||||
If you add or change a feature, please also add a unit test to this file. The unit tests can be compiled and executed with
|
||||
|
||||
@@ -55,7 +53,7 @@ To make changes, you need to edit the following files:
|
||||
## Please don't
|
||||
|
||||
- The C++11 support varies between different **compilers** and versions. Please note the [list of supported compilers](https://github.com/nlohmann/json/blob/master/README.md#supported-compilers). Some compilers like GCC 4.7 (and earlier), Clang 3.3 (and earlier), or Microsoft Visual Studio 13.0 and earlier are known not to work due to missing or incomplete C++11 support. Please refrain from proposing changes that work around these compiler's limitations with `#ifdef`s or other means.
|
||||
- Specifically, I am aware of compilation problems with **Microsoft Visual Studio** (there even is an [issue label](https://github.com/nlohmann/json/issues?utf8=✓&q=label%3A%22visual+studio%22+) for these kind of bugs). I understand that even in 2016, complete C++11 support isn't there yet. But please also understand that I do not want to drop features or uglify the code just to make Microsoft's sub-standard compiler happy. The past has shown that there are ways to express the functionality such that the code compiles with the most recent MSVC - unfortunately, this is not the main objective of the project.
|
||||
- Specifically, I am aware of compilation problems with **Microsoft Visual Studio** (there even is an [issue label](https://github.com/nlohmann/json/issues?utf8=✓&q=label%3A%22visual+studio%22+) for this kind of bug). I understand that even in 2016, complete C++11 support isn't there yet. But please also understand that I do not want to drop features or uglify the code just to make Microsoft's sub-standard compiler happy. The past has shown that there are ways to express the functionality such that the code compiles with the most recent MSVC - unfortunately, this is not the main objective of the project.
|
||||
- Please refrain from proposing changes that would **break [JSON](https://json.org) conformance**. If you propose a conformant extension of JSON to be supported by the library, please motivate this extension.
|
||||
- We shall not extend the library to **support comments**. There is quite some [controversy](https://www.reddit.com/r/programming/comments/4v6chu/why_json_doesnt_support_comments_douglas_crockford/) around this topic, and there were quite some [issues](https://github.com/nlohmann/json/issues/376) on this. We believe that JSON is fine without comments.
|
||||
- We do not preserve the **insertion order of object elements**. The [JSON standard](https://tools.ietf.org/html/rfc8259.html) defines objects as "an unordered collection of zero or more name/value pairs". To this end, this library does not preserve insertion order of name/value pairs. (In fact, keys will be traversed in alphabetical order as `std::map` with `std::less` is used by default.) Note this behavior conforms to the standard, and we shall not change it to any other order. If you do want to preserve the insertion order, you can specialize the object type with containers like [`tsl::ordered_map`](https://github.com/Tessil/ordered-map) or [`nlohmann::fifo_map`](https://github.com/nlohmann/fifo_map).
|
||||
|
||||
2
.github/ISSUE_TEMPLATE/bug.yaml
vendored
2
.github/ISSUE_TEMPLATE/bug.yaml
vendored
@@ -76,7 +76,7 @@ body:
|
||||
label: Library version
|
||||
description: >
|
||||
Which version of the library did you use? If it is a released version,
|
||||
please enter the version number (e.g., 3.11.1). Otherwise, please enter
|
||||
please enter the version number (e.g., 3.11.3). Otherwise, please enter
|
||||
the commit hash. If you got the library from another source as the
|
||||
GitHub repository (e.g., via a package manager), please also state
|
||||
this.
|
||||
|
||||
4
.github/PULL_REQUEST_TEMPLATE.md
vendored
4
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -9,11 +9,11 @@ Read the [Contribution Guidelines](https://github.com/nlohmann/json/blob/develop
|
||||
- [ ] Changes are described in the pull request, or an [existing issue is referenced](https://github.com/nlohmann/json/issues).
|
||||
- [ ] The test suite [compiles and runs](https://github.com/nlohmann/json/blob/develop/README.md#execute-unit-tests) without error.
|
||||
- [ ] [Code coverage](https://coveralls.io/github/nlohmann/json) is 100%. Test cases can be added by editing the [test suite](https://github.com/nlohmann/json/tree/develop/test/src).
|
||||
- [ ] The source code is amalgamated; that is, after making changes to the sources in the `include/nlohmann` directory, run `make amalgamate` to create the single-header file `single_include/nlohmann/json.hpp`. The whole process is described [here](https://github.com/nlohmann/json/blob/develop/.github/CONTRIBUTING.md#files-to-change).
|
||||
- [ ] The source code is amalgamated; that is, after making changes to the sources in the `include/nlohmann` directory, run `make amalgamate` to create the single-header files `single_include/nlohmann/json.hpp` and `single_include/nlohmann/json_fwd.hpp`. The whole process is described [here](https://github.com/nlohmann/json/blob/develop/.github/CONTRIBUTING.md#files-to-change).
|
||||
|
||||
## Please don't
|
||||
|
||||
- The C++11 support varies between different **compilers** and versions. Please note the [list of supported compilers](https://github.com/nlohmann/json/blob/master/README.md#supported-compilers). Some compilers like GCC 4.7 (and earlier), Clang 3.3 (and earlier), or Microsoft Visual Studio 13.0 and earlier are known not to work due to missing or incomplete C++11 support. Please refrain from proposing changes that work around these compiler's limitations with `#ifdef`s or other means.
|
||||
- Specifically, I am aware of compilation problems with **Microsoft Visual Studio** (there even is an [issue label](https://github.com/nlohmann/json/issues?utf8=✓&q=label%3A%22visual+studio%22+) for these kind of bugs). I understand that even in 2016, complete C++11 support isn't there yet. But please also understand that I do not want to drop features or uglify the code just to make Microsoft's sub-standard compiler happy. The past has shown that there are ways to express the functionality such that the code compiles with the most recent MSVC - unfortunately, this is not the main objective of the project.
|
||||
- Specifically, I am aware of compilation problems with **Microsoft Visual Studio** (there even is an [issue label](https://github.com/nlohmann/json/issues?utf8=✓&q=label%3A%22visual+studio%22+) for this kind of bug). I understand that even in 2016, complete C++11 support isn't there yet. But please also understand that I do not want to drop features or uglify the code just to make Microsoft's sub-standard compiler happy. The past has shown that there are ways to express the functionality such that the code compiles with the most recent MSVC - unfortunately, this is not the main objective of the project.
|
||||
- Please refrain from proposing changes that would **break [JSON](https://json.org) conformance**. If you propose a conformant extension of JSON to be supported by the library, please motivate this extension.
|
||||
- Please do not open pull requests that address **multiple issues**.
|
||||
|
||||
20
.github/external_ci/appveyor.yml
vendored
20
.github/external_ci/appveyor.yml
vendored
@@ -1,5 +1,19 @@
|
||||
version: '{build}'
|
||||
|
||||
# only build PRs and commits to develop branch
|
||||
# (see https://help.appveyor.com/discussions/questions/55079-two-builds-per-commit-to-pull-request)
|
||||
branches:
|
||||
only:
|
||||
- develop
|
||||
|
||||
only_commits:
|
||||
files:
|
||||
- .github/external_ci/appveyor.yml
|
||||
- cmake/
|
||||
- include/
|
||||
- tests/
|
||||
- CMakeLists.txt
|
||||
|
||||
environment:
|
||||
matrix:
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
@@ -75,9 +89,3 @@ test_script:
|
||||
# occasional timeouts on AppVeyor.
|
||||
# More info: https://github.com/nlohmann/json/pull/1570
|
||||
- if "%configuration%"=="Debug" ctest --exclude-regex "test-unicode" -C "%configuration%" --parallel 2 --output-on-failure
|
||||
|
||||
# only build PRs and commits to develop branch
|
||||
# (see https://help.appveyor.com/discussions/questions/55079-two-builds-per-commit-to-pull-request)
|
||||
branches:
|
||||
only:
|
||||
- develop
|
||||
|
||||
38
.github/labeler.yml
vendored
Normal file
38
.github/labeler.yml
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
version: 1
|
||||
|
||||
labels:
|
||||
- label: "documentation"
|
||||
files:
|
||||
- "README.md"
|
||||
|
||||
- label: "documentation"
|
||||
files:
|
||||
- "docs/.*"
|
||||
|
||||
- label: "tests"
|
||||
files:
|
||||
- "tests/.*"
|
||||
|
||||
- label: "CMake"
|
||||
files:
|
||||
- ".*CMakeLists.txt"
|
||||
|
||||
- label: "CMake"
|
||||
files:
|
||||
- "cmake/.*"
|
||||
|
||||
- label: "CI"
|
||||
files:
|
||||
- "github/workflows/.*"
|
||||
|
||||
- label: "CI"
|
||||
files:
|
||||
- "github/external_ci/.*"
|
||||
|
||||
- label: "S"
|
||||
size-below: 10
|
||||
- label: "M"
|
||||
size-above: 9
|
||||
size-below: 100
|
||||
- label: "L"
|
||||
size-above: 100
|
||||
70
.github/workflows/check_amalgamation.yml
vendored
Normal file
70
.github/workflows/check_amalgamation.yml
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
name: "Check amalgamation"
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
permissions: read-all
|
||||
|
||||
jobs:
|
||||
save:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Save PR number
|
||||
run: |
|
||||
mkdir -p ./pr
|
||||
echo ${{ github.event.number }} > ./pr/number
|
||||
echo ${{ github.event.pull_request.user.login }} > ./pr/author
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: pr
|
||||
path: pr/
|
||||
|
||||
check:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
MAIN_DIR: ${{ github.workspace }}/main
|
||||
INCLUDE_DIR: ${{ github.workspace }}/main/single_include/nlohmann
|
||||
TOOL_DIR: ${{ github.workspace }}/tools/tools/amalgamate
|
||||
ASTYLE_FLAGS: >
|
||||
--style=allman --indent=spaces=4 --indent-modifiers --indent-switches --indent-preproc-block
|
||||
--indent-preproc-define --indent-col1-comments --pad-oper --pad-header --align-pointer=type
|
||||
--align-reference=type --add-brackets --convert-tabs --close-templates --lineend=linux --preserve-date
|
||||
--formatted
|
||||
|
||||
steps:
|
||||
- name: Checkout pull request
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
path: main
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
|
||||
- name: Checkout tools
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
path: tools
|
||||
ref: develop
|
||||
|
||||
- name: Install astyle
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install astyle
|
||||
|
||||
- name: Check amalgamation
|
||||
run: |
|
||||
cd $MAIN_DIR
|
||||
|
||||
rm -fr $INCLUDE_DIR/json.hpp~ $INCLUDE_DIR/json_fwd.hpp~
|
||||
cp $INCLUDE_DIR/json.hpp $INCLUDE_DIR/json.hpp~
|
||||
cp $INCLUDE_DIR/json_fwd.hpp $INCLUDE_DIR/json_fwd.hpp~
|
||||
|
||||
python3 $TOOL_DIR/amalgamate.py -c $TOOL_DIR/config_json.json -s .
|
||||
python3 $TOOL_DIR/amalgamate.py -c $TOOL_DIR/config_json_fwd.json -s .
|
||||
echo "Format (1)"
|
||||
astyle $ASTYLE_FLAGS --suffix=none --quiet $INCLUDE_DIR/json.hpp $INCLUDE_DIR/json_fwd.hpp
|
||||
|
||||
diff $INCLUDE_DIR/json.hpp~ $INCLUDE_DIR/json.hpp
|
||||
diff $INCLUDE_DIR/json_fwd.hpp~ $INCLUDE_DIR/json_fwd.hpp
|
||||
|
||||
astyle $ASTYLE_FLAGS $(find docs/examples include tests -type f \( -name '*.hpp' -o -name '*.cpp' -o -name '*.cu' \) -not -path 'tests/thirdparty/*' -not -path 'tests/abi/include/nlohmann/*' | sort)
|
||||
echo Check
|
||||
find $MAIN_DIR -name '*.orig' -exec false {} \+
|
||||
30
.github/workflows/cifuzz.yml
vendored
Normal file
30
.github/workflows/cifuzz.yml
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
name: CIFuzz
|
||||
on: [pull_request]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
Fuzzing:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Build Fuzzers
|
||||
id: build
|
||||
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
|
||||
with:
|
||||
oss-fuzz-project-name: 'json'
|
||||
dry-run: false
|
||||
language: c++
|
||||
- name: Run Fuzzers
|
||||
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
|
||||
with:
|
||||
oss-fuzz-project-name: 'json'
|
||||
fuzz-seconds: 300
|
||||
dry-run: false
|
||||
language: c++
|
||||
- name: Upload Crash
|
||||
uses: actions/upload-artifact@v4
|
||||
if: failure() && steps.build.outcome == 'success'
|
||||
with:
|
||||
name: artifacts
|
||||
path: ./out/artifacts
|
||||
34
.github/workflows/codeql-analysis.yml
vendored
34
.github/workflows/codeql-analysis.yml
vendored
@@ -10,6 +10,9 @@ on:
|
||||
schedule:
|
||||
- cron: '0 19 * * 1'
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
|
||||
@@ -19,42 +22,23 @@ jobs:
|
||||
CodeQL-Build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
security-events: write
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
# We must fetch at least the immediate parents so that if this is
|
||||
# a pull request then we can check out the head.
|
||||
fetch-depth: 2
|
||||
|
||||
# If this run was triggered by a pull request event, then checkout
|
||||
# the head of the pull request instead of the merge commit.
|
||||
- run: git checkout HEAD^2
|
||||
if: ${{ github.event_name == 'pull_request' }}
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v2
|
||||
# Override language selection by uncommenting this and choosing your languages
|
||||
# with:
|
||||
# languages: go, javascript, csharp, python, cpp, java
|
||||
uses: github/codeql-action/init@v3
|
||||
with:
|
||||
languages: c-cpp
|
||||
|
||||
# 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)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v2
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
|
||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||
# and modify them (or add more) to build your code if your project
|
||||
# uses a compiled language
|
||||
|
||||
#- run: |
|
||||
# make bootstrap
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v2
|
||||
|
||||
75
.github/workflows/comment_check_amalgamation.yml
vendored
Normal file
75
.github/workflows/comment_check_amalgamation.yml
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
name: Comment Check Amalgamation
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["Check amalgamation"]
|
||||
types:
|
||||
- completed
|
||||
|
||||
permissions: {}
|
||||
|
||||
jobs:
|
||||
comment:
|
||||
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
actions: read
|
||||
issues: read
|
||||
pull-requests: write
|
||||
steps:
|
||||
- name: 'Download artifact'
|
||||
uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975 # v6.4.0
|
||||
with:
|
||||
script: |
|
||||
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
run_id: ${{github.event.workflow_run.id }},
|
||||
});
|
||||
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
|
||||
return artifact.name == "pr"
|
||||
})[0];
|
||||
var download = await github.rest.actions.downloadArtifact({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
artifact_id: matchArtifact.id,
|
||||
archive_format: 'zip',
|
||||
});
|
||||
var fs = require('fs');
|
||||
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
|
||||
- run: unzip pr.zip
|
||||
|
||||
- name: 'Comment on PR'
|
||||
uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975 # v6.4.0
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
var fs = require('fs');
|
||||
const author = fs.readFileSync('./author')
|
||||
const issue_number = Number(fs.readFileSync('./number'));
|
||||
const opts = github.rest.issues.listForRepo.endpoint.merge({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
creator: author,
|
||||
state: 'all'
|
||||
})
|
||||
let first = true
|
||||
const issues = await github.paginate(opts)
|
||||
for (const issue of issues) {
|
||||
if (issue.number === issue_number) {
|
||||
continue
|
||||
}
|
||||
if (issue.pull_request) {
|
||||
first = false
|
||||
break
|
||||
}
|
||||
}
|
||||
await github.rest.issues.createComment({
|
||||
issue_number: issue_number,
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
body: '## 🔴 Amalgamation check failed! 🔴\nThe source code has not been amalgamated.'
|
||||
+ (first ? ' @' + author + ' Please read and follow the [Contribution Guidelines]'
|
||||
+ '(https://github.com/nlohmann/json/blob/develop/.github/CONTRIBUTING.md#files-to-change).'
|
||||
: '')
|
||||
})
|
||||
20
.github/workflows/labeler.yml
vendored
Normal file
20
.github/workflows/labeler.yml
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
name: "Pull Request Labeler"
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [opened, synchronize]
|
||||
|
||||
permissions: {}
|
||||
|
||||
jobs:
|
||||
label:
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: write
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: srvaroa/labeler@master
|
||||
env:
|
||||
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
|
||||
96
.github/workflows/macos.yml
vendored
96
.github/workflows/macos.yml
vendored
@@ -9,58 +9,112 @@ on:
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
xcode_1:
|
||||
runs-on: macos-10.15
|
||||
# macos-11 is deprecated
|
||||
# macos-11:
|
||||
# runs-on: macos-11
|
||||
# strategy:
|
||||
# matrix:
|
||||
# xcode: ['11.7', '12.4', '12.5.1', '13.0']
|
||||
# env:
|
||||
# DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
||||
#
|
||||
# steps:
|
||||
# - uses: actions/checkout@v4
|
||||
# - name: Run CMake
|
||||
# run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON
|
||||
# - name: Build
|
||||
# run: cmake --build build --parallel 10
|
||||
# - name: Test
|
||||
# run: cd build ; ctest -j 10 --output-on-failure
|
||||
|
||||
# macos-12 is deprecated (https://github.com/actions/runner-images/issues/10721)
|
||||
# macos-12:
|
||||
# runs-on: macos-12 # https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md
|
||||
# strategy:
|
||||
# matrix:
|
||||
# xcode: ['13.1', '13.2.1', '13.3.1', '13.4.1', '14.0', '14.0.1', '14.1']
|
||||
# env:
|
||||
# DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
||||
#
|
||||
# steps:
|
||||
# - uses: actions/checkout@v4
|
||||
# - name: Run CMake
|
||||
# run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON
|
||||
# - name: Build
|
||||
# run: cmake --build build --parallel 10
|
||||
# - name: Test
|
||||
# run: cd build ; ctest -j 10 --output-on-failure
|
||||
|
||||
macos-13:
|
||||
runs-on: macos-13 # https://github.com/actions/runner-images/blob/main/images/macos/macos-13-Readme.md
|
||||
strategy:
|
||||
matrix:
|
||||
xcode: [12.4, 12.3, 12.2, 12.1.1, 12.1, 12, 11.7, 11.6, 11.5, 11.4.1, 11.3.1, 11.2.1, 10.3]
|
||||
xcode: ['14.1', '14.2', '14.3', '14.3.1', '15.0.1', '15.1', '15.2']
|
||||
env:
|
||||
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: cmake
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON
|
||||
- name: build
|
||||
- name: Build
|
||||
run: cmake --build build --parallel 10
|
||||
- name: test
|
||||
- name: Test
|
||||
run: cd build ; ctest -j 10 --output-on-failure
|
||||
|
||||
xcode_2:
|
||||
runs-on: macos-12
|
||||
macos-14:
|
||||
runs-on: macos-14 # https://github.com/actions/runner-images/blob/main/images/macos/macos-14-Readme.md
|
||||
strategy:
|
||||
matrix:
|
||||
xcode: [13.3.1, 13.3, 13.2.1, 13.2, 13.1]
|
||||
xcode: ['15.3', '15.4']
|
||||
env:
|
||||
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: cmake
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON
|
||||
- name: build
|
||||
- name: Build
|
||||
run: cmake --build build --parallel 10
|
||||
- name: test
|
||||
- name: Test
|
||||
run: cd build ; ctest -j 10 --output-on-failure
|
||||
|
||||
macos-15:
|
||||
runs-on: macos-15 # https://github.com/actions/runner-images/blob/main/images/macos/macos-15-Readme.md
|
||||
strategy:
|
||||
matrix:
|
||||
xcode: ['16.0', '16.1']
|
||||
env:
|
||||
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON
|
||||
- name: Build
|
||||
run: cmake --build build --parallel 10
|
||||
- name: Test
|
||||
run: cd build ; ctest -j 10 --output-on-failure
|
||||
|
||||
xcode_standards:
|
||||
runs-on: macos-latest
|
||||
strategy:
|
||||
matrix:
|
||||
standard: [11, 14, 17, 20]
|
||||
env:
|
||||
DEVELOPER_DIR: /Applications/Xcode_12.4.app/Contents/Developer
|
||||
standard: [11, 14, 17, 20, 23]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: cmake
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_TestStandards=${{ matrix.standard }}
|
||||
- name: build
|
||||
- name: Build
|
||||
run: cmake --build build --parallel 10
|
||||
- name: test
|
||||
- name: Test
|
||||
run: cd build ; ctest -j 10 --output-on-failure
|
||||
|
||||
41
.github/workflows/publish_documentation.yml
vendored
Normal file
41
.github/workflows/publish_documentation.yml
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
name: Publish documentation
|
||||
|
||||
# publish the documentation on every merge to develop branch
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- develop
|
||||
paths:
|
||||
- docs/mkdocs/**
|
||||
- docs/examples/**
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
# we don't want to have concurrent jobs, and we don't want to cancel running jobs to avoid broken publications
|
||||
concurrency:
|
||||
group: documentation
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
publish_documentation:
|
||||
if: github.repository == 'nlohmann/json'
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install and update PlantUML
|
||||
run: sudo apt-get update ; sudo apt-get install -y plantuml
|
||||
|
||||
- name: Install virtual environment
|
||||
run: make install_venv -C docs/mkdocs
|
||||
|
||||
- name: Build documentation
|
||||
run: make build -C docs/mkdocs
|
||||
|
||||
- name: Deploy documentation
|
||||
uses: peaceiris/actions-gh-pages@v4
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: ./docs/mkdocs/site
|
||||
231
.github/workflows/ubuntu.yml
vendored
231
.github/workflows/ubuntu.yml
vendored
@@ -8,6 +8,9 @@ on:
|
||||
- release/*
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
|
||||
@@ -16,22 +19,26 @@ concurrency:
|
||||
jobs:
|
||||
ci_test_clang:
|
||||
runs-on: ubuntu-latest
|
||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
||||
container: silkeh/clang:dev
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: cmake
|
||||
- name: Install git and unzip
|
||||
run: apt-get update ; apt-get install -y git unzip
|
||||
- uses: actions/checkout@v4
|
||||
- name: Get latest CMake and ninja
|
||||
uses: lukka/get-cmake@v3.31.0
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: build
|
||||
- name: Build
|
||||
run: cmake --build build --target ci_test_clang
|
||||
|
||||
ci_test_gcc:
|
||||
runs-on: ubuntu-latest
|
||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: cmake
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: build
|
||||
- name: Build
|
||||
run: cmake --build build --target ci_test_gcc
|
||||
|
||||
ci_static_analysis:
|
||||
@@ -39,120 +46,230 @@ jobs:
|
||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
||||
strategy:
|
||||
matrix:
|
||||
target: [ci_clang_tidy, ci_cppcheck, ci_test_valgrind, ci_test_clang_sanitizer, ci_test_amalgamation, ci_clang_analyze, ci_cpplint, ci_cmake_flags, ci_single_binaries, ci_reproducible_tests, ci_non_git_tests, ci_offline_testdata, ci_infer]
|
||||
target: [ci_cppcheck, ci_test_valgrind, ci_test_amalgamation, ci_test_single_header, ci_single_binaries, ci_infer]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: cmake
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: build
|
||||
- name: Build
|
||||
run: cmake --build build --target ${{ matrix.target }}
|
||||
|
||||
ci_test_single_header:
|
||||
ci_static_analysis_ubuntu:
|
||||
runs-on: ubuntu-latest
|
||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
||||
strategy:
|
||||
matrix:
|
||||
target: [ci_cpplint, ci_reproducible_tests, ci_non_git_tests, ci_offline_testdata]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: cmake
|
||||
- uses: actions/checkout@v4
|
||||
- name: Get latest CMake and ninja
|
||||
uses: lukka/get-cmake@v3.31.0
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: build
|
||||
run: cmake --build build --target ci_test_single_header
|
||||
- name: Build
|
||||
run: cmake --build build --target ${{ matrix.target }}
|
||||
|
||||
ci_static_analysis_clang:
|
||||
runs-on: ubuntu-latest
|
||||
container: silkeh/clang:dev
|
||||
strategy:
|
||||
matrix:
|
||||
target: [ci_clang_tidy, ci_test_clang_sanitizer, ci_clang_analyze]
|
||||
steps:
|
||||
- name: Install git, clang-tools, and unzip
|
||||
run: apt-get update ; apt-get install -y git clang-tools unzip
|
||||
- uses: actions/checkout@v4
|
||||
- name: Get latest CMake and ninja
|
||||
uses: lukka/get-cmake@v3.31.0
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: Build
|
||||
run: cmake --build build --target ${{ matrix.target }}
|
||||
|
||||
ci_cmake_options:
|
||||
runs-on: ubuntu-latest
|
||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
||||
container: ubuntu:focal
|
||||
strategy:
|
||||
matrix:
|
||||
target: [ci_test_diagnostics, ci_test_noexceptions, ci_test_noimplicitconversions, ci_test_legacycomparison, ci_test_noglobaludls]
|
||||
target: [ci_cmake_flags, ci_test_diagnostics, ci_test_noexceptions, ci_test_noimplicitconversions, ci_test_legacycomparison, ci_test_noglobaludls]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: cmake
|
||||
- name: Install build-essential
|
||||
run: apt-get update ; apt-get install -y build-essential unzip wget git
|
||||
- uses: actions/checkout@v4
|
||||
- name: Get latest CMake and ninja
|
||||
uses: lukka/get-cmake@v3.31.0
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: build
|
||||
- name: Build
|
||||
run: cmake --build build --target ${{ matrix.target }}
|
||||
|
||||
ci_test_coverage:
|
||||
runs-on: ubuntu-latest
|
||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
||||
permissions:
|
||||
contents: read
|
||||
checks: write
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: cmake
|
||||
- uses: actions/checkout@v4
|
||||
- name: Install dependencies and de_DE locale
|
||||
run: |
|
||||
sudo apt-get clean
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y build-essential cmake lcov ninja-build make locales gcc-multilib g++-multilib
|
||||
sudo locale-gen de_DE
|
||||
sudo update-locale
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: build
|
||||
- name: Build
|
||||
run: cmake --build build --target ci_test_coverage
|
||||
- name: archive coverage report
|
||||
uses: actions/upload-artifact@v3
|
||||
- name: Archive coverage report
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: code-coverage-report
|
||||
path: /__w/json/json/build/html
|
||||
- name: Coveralls
|
||||
uses: coverallsapp/github-action@master
|
||||
path: ${{ github.workspace }}/build/html
|
||||
- name: Publish report to Coveralls
|
||||
uses: coverallsapp/github-action@v2.3.4
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
path-to-lcov: /__w/json/json/build/json.info.filtered.noexcept
|
||||
path-to-lcov: ${{ github.workspace }}/build/json.info.filtered.noexcept
|
||||
|
||||
ci_test_compilers_gcc_old:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
compiler: ['4.8', '4.9', '5', '6']
|
||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run CMake
|
||||
run: CXX=g++-${{ matrix.compiler }} cmake -S . -B build -DJSON_CI=On
|
||||
- name: Build
|
||||
run: cmake --build build --target ci_test_compiler_g++-${{ matrix.compiler }}
|
||||
|
||||
ci_test_compilers_gcc:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
# older GCC docker images (4, 5, 6) fail to check out code
|
||||
compiler: ['7', '8', '9', '10', '11', '12', '13', '14', 'latest']
|
||||
container: gcc:${{ matrix.compiler }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Get latest CMake and ninja
|
||||
uses: lukka/get-cmake@v3.31.0
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: Build
|
||||
run: cmake --build build --target ci_test_compiler_default
|
||||
|
||||
ci_test_compilers_clang:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
compiler: ['3.5', '3.6', '3.7', '3.8', '3.9', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15-bullseye', '16', '17', '18', '19', 'latest']
|
||||
container: silkeh/clang:${{ matrix.compiler }}
|
||||
steps:
|
||||
- name: Install unzip and git
|
||||
run: apt-get update ; apt-get install -y unzip git
|
||||
- uses: actions/checkout@v4
|
||||
- name: Get latest CMake and ninja
|
||||
uses: lukka/get-cmake@v3.31.0
|
||||
- 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"
|
||||
if: ${{ matrix.compiler == '7' || matrix.compiler == '8' || matrix.compiler == '9' || matrix.compiler == '10' }}
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: Build
|
||||
run: cmake --build build --target ci_test_compiler_default
|
||||
|
||||
ci_test_compilers:
|
||||
runs-on: ubuntu-latest
|
||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
||||
strategy:
|
||||
matrix:
|
||||
compiler: [g++-4.8, g++-4.9, g++-5, g++-6, g++-7, g++-8, g++-9, g++-10, g++-11, clang++-3.5, clang++-3.6, clang++-3.7, clang++-3.8, clang++-3.9, clang++-4.0, clang++-5.0, clang++-6.0, clang++-7, clang++-8, clang++-9, clang++-10, clang++-11, clang++-12, clang++-13, clang++-14]
|
||||
compiler: [g++-4.8]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: cmake
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: build
|
||||
- name: Build
|
||||
run: cmake --build build --target ci_test_compiler_${{ matrix.compiler }}
|
||||
|
||||
ci_test_standards:
|
||||
ci_test_standards_gcc:
|
||||
runs-on: ubuntu-latest
|
||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
||||
strategy:
|
||||
matrix:
|
||||
standard: [11, 14, 17, 20]
|
||||
compiler: [gcc, clang]
|
||||
standard: [11, 14, 17, 20, 23]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: cmake
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: build
|
||||
run: cmake --build build --target ci_test_${{ matrix.compiler }}_cxx${{ matrix.standard }}
|
||||
- name: Build
|
||||
run: cmake --build build --target ci_test_gcc_cxx${{ matrix.standard }}
|
||||
|
||||
ci_test_standards_clang:
|
||||
runs-on: ubuntu-latest
|
||||
container: silkeh/clang:latest
|
||||
strategy:
|
||||
matrix:
|
||||
standard: [11, 14, 17, 20, 23]
|
||||
stdlib: [libcxx, libstdcxx]
|
||||
steps:
|
||||
- name: Install git and unzip
|
||||
run: apt-get update ; apt-get install -y git unzip
|
||||
- uses: actions/checkout@v4
|
||||
- name: Get latest CMake and ninja
|
||||
uses: lukka/get-cmake@v3.31.0
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: Build with libc++
|
||||
run: cmake --build build --target ci_test_clang_libcxx_cxx${{ matrix.standard }}
|
||||
if: ${{ matrix.stdlib == 'libcxx' }}
|
||||
- name: Build with libstdc++
|
||||
run: cmake --build build --target ci_test_clang_cxx${{ matrix.standard }}
|
||||
if: ${{ matrix.stdlib == 'libstdcxx' }}
|
||||
|
||||
ci_cuda_example:
|
||||
runs-on: ubuntu-latest
|
||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: cmake
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: build
|
||||
- name: Build
|
||||
run: cmake --build build --target ci_cuda_example
|
||||
|
||||
ci_icpc:
|
||||
runs-on: ubuntu-latest
|
||||
container: ghcr.io/nlohmann/json-ci:v2.2.0
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: cmake
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: build
|
||||
- name: Build
|
||||
run: |
|
||||
. /opt/intel/oneapi/setvars.sh
|
||||
cmake --build build --target ci_icpc
|
||||
|
||||
ci_reuse_compliance:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-python@v3
|
||||
- name: install REUSE tool
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.11'
|
||||
- name: Install REUSE tool
|
||||
run: python -m pip install reuse
|
||||
- name: REUSE lint
|
||||
- name: Run REUSE lint
|
||||
run: reuse lint
|
||||
|
||||
ci_test_documentation:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
target: [ci_test_examples, ci_test_api_documentation]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: cmake
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: build
|
||||
run: cmake --build build --target ci_test_documentation
|
||||
- name: Build
|
||||
run: cmake --build build --target ${{ matrix.target }}
|
||||
|
||||
99
.github/workflows/windows.yml
vendored
99
.github/workflows/windows.yml
vendored
@@ -9,49 +9,32 @@ on:
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
mingw:
|
||||
runs-on: windows-latest
|
||||
runs-on: windows-2019
|
||||
strategy:
|
||||
matrix:
|
||||
architecture: [x64, x86]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Download MinGW 8.1.0
|
||||
run: |
|
||||
$headers = @{Authorization = 'Bearer ${{ secrets.GITHUB_TOKEN }}'}
|
||||
$uri = 'https://nuget.pkg.github.com/falbrechtskirchinger/download/mingw/8.1.0/mingw.8.1.0.nupkg'
|
||||
Invoke-WebRequest -Uri $uri -Headers $headers -OutFile mingw.8.1.0.nupkg
|
||||
- name: Uninstall MinGW
|
||||
continue-on-error: true
|
||||
run: choco uninstall mingw
|
||||
# Based on egor-tensin/setup-mingw
|
||||
- name: Install MinGW 8.1.0
|
||||
run: |
|
||||
choco install mingw.8.1.0.nupkg ${{ matrix.architecture == 'x86' && '--x86' || '' }}
|
||||
$prefix = "${{ matrix.architecture == 'x64' && 'x86_64-w64-mingw32' || 'i686-w64-mingw32' }}"
|
||||
$mingw = "${{ matrix.architecture == 'x64' && 'mingw64' || 'mingw32' }}"
|
||||
$mingw_install = Join-Path C: ProgramData chocolatey lib mingw tools install
|
||||
$mingw_root = Join-Path $mingw_install $mingw
|
||||
$mingw_bin = Join-Path $mingw_root bin
|
||||
$mingw_lib = Join-Path $mingw_root $prefix lib
|
||||
echo $mingw_bin >> $env:GITHUB_PATH
|
||||
Remove-Item (Join-Path $mingw_lib 'libpthread.dll.a')
|
||||
Remove-Item (Join-Path $mingw_lib 'libwinpthread.dll.a')
|
||||
#- name: Set up MinGW
|
||||
# uses: egor-tensin/setup-mingw@v2
|
||||
# with:
|
||||
# platform: ${{ matrix.architecture }}
|
||||
- name: cmake
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up MinGW
|
||||
uses: egor-tensin/setup-mingw@v2
|
||||
with:
|
||||
platform: ${{ matrix.architecture }}
|
||||
version: 12.2.0 # https://github.com/egor-tensin/setup-mingw/issues/14
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On
|
||||
- name: build
|
||||
- name: Build
|
||||
run: cmake --build build --parallel 10
|
||||
- name: test
|
||||
- name: Test
|
||||
run: cd build ; ctest -j 10 -C Debug --output-on-failure
|
||||
|
||||
msvc2019:
|
||||
@@ -62,28 +45,28 @@ jobs:
|
||||
architecture: [Win32, x64]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: cmake
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -G "Visual Studio 16 2019" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/W4 /WX"
|
||||
if: matrix.build_type == 'Release'
|
||||
- name: cmake
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -G "Visual Studio 16 2019" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DJSON_FastTests=ON -DCMAKE_CXX_FLAGS="/W4 /WX"
|
||||
if: matrix.build_type == 'Debug'
|
||||
- name: build
|
||||
- name: Build
|
||||
run: cmake --build build --config ${{ matrix.build_type }} --parallel 10
|
||||
- name: test
|
||||
- name: Test
|
||||
run: cd build ; ctest -j 10 -C ${{ matrix.build_type }} --output-on-failure
|
||||
|
||||
msvc2019_latest:
|
||||
runs-on: windows-2019
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: cmake
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -G "Visual Studio 16 2019" -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/permissive- /std:c++latest /utf-8 /W4 /WX"
|
||||
- name: build
|
||||
- name: Build
|
||||
run: cmake --build build --config Release --parallel 10
|
||||
- name: test
|
||||
- name: Test
|
||||
run: cd build ; ctest -j 10 -C Release --output-on-failure
|
||||
|
||||
msvc2022:
|
||||
@@ -94,45 +77,45 @@ jobs:
|
||||
architecture: [Win32, x64]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: cmake
|
||||
- uses: actions/checkout@v4
|
||||
- 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: cmake
|
||||
- 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
|
||||
- name: Build
|
||||
run: cmake --build build --config ${{ matrix.build_type }} --parallel 10
|
||||
- name: test
|
||||
- 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@v3
|
||||
- name: cmake
|
||||
- uses: actions/checkout@v4
|
||||
- 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
|
||||
- name: Build
|
||||
run: cmake --build build --config Release --parallel 10
|
||||
- name: test
|
||||
- name: Test
|
||||
run: cd build ; ctest -j 10 -C Release --output-on-failure
|
||||
|
||||
clang:
|
||||
runs-on: windows-2019
|
||||
strategy:
|
||||
matrix:
|
||||
version: [11, 12]
|
||||
version: [11, 12, 13, 14, 15]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: install Clang
|
||||
- uses: actions/checkout@v4
|
||||
- name: Install Clang
|
||||
run: curl -fsSL -o LLVM${{ matrix.version }}.exe https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ matrix.version }}.0.0/LLVM-${{ matrix.version }}.0.0-win64.exe ; 7z x LLVM${{ matrix.version }}.exe -y -o"C:/Program Files/LLVM"
|
||||
- name: cmake
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang++.exe" -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On
|
||||
- name: build
|
||||
- name: Build
|
||||
run: cmake --build build --parallel 10
|
||||
- name: test
|
||||
- name: Test
|
||||
run: cd build ; ctest -j 10 -C Debug --exclude-regex "test-unicode" --output-on-failure
|
||||
|
||||
clang-cl-11:
|
||||
@@ -142,10 +125,10 @@ jobs:
|
||||
architecture: [Win32, x64]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: cmake
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -G "Visual Studio 16 2019" -A ${{ matrix.architecture }} -T ClangCL -DJSON_BuildTests=On
|
||||
- name: build
|
||||
- name: Build
|
||||
run: cmake --build build --config Debug --parallel 10
|
||||
- name: test
|
||||
- name: Test
|
||||
run: cd build ; ctest -j 10 -C Debug --exclude-regex "test-unicode" --output-on-failure
|
||||
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -39,3 +39,6 @@
|
||||
/localhost.pem
|
||||
/localhost-key.pem
|
||||
/serve_header.yml
|
||||
|
||||
# Swift Package Manager build directory
|
||||
/.build
|
||||
4
.lgtm.yml
Normal file
4
.lgtm.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
path_classifiers:
|
||||
thirdparty:
|
||||
- /tools/amalgamate
|
||||
- /tools/cpplint
|
||||
12
.reuse/dep5
12
.reuse/dep5
@@ -4,9 +4,13 @@ Upstream-Contact: Niels Lohmann <mail@nlohmann.me>
|
||||
Source: https://github.com/nlohmann/json
|
||||
|
||||
Files: *
|
||||
Copyright: 2013-2022 Niels Lohmann <https://nlohmann.me>
|
||||
Copyright: 2013-2024 Niels Lohmann <https://nlohmann.me>
|
||||
License: MIT
|
||||
|
||||
Files: include/nlohmann/thirdparty/hedley.hpp
|
||||
Copyright: 2016-2021 Evan Nemerson <evan@nemerson.com>
|
||||
License: CC0
|
||||
|
||||
Files: tests/thirdparty/doctest/*
|
||||
Copyright: 2016-2021 Viktor Kirilov
|
||||
License: MIT
|
||||
@@ -16,7 +20,7 @@ Copyright: 2015-2017 Niels Lohmann
|
||||
License: MIT
|
||||
|
||||
Files: tests/thirdparty/Fuzzer/*
|
||||
Copyright: 2003-2022, LLVM Project.
|
||||
Copyright: 2003-2022 LLVM Project.
|
||||
License: Apache-2.0
|
||||
|
||||
Files: tests/thirdparty/imapdl/*
|
||||
@@ -27,10 +31,6 @@ Files: tools/amalgamate/*
|
||||
Copyright: 2012 Erik Edlund <erik.edlund@32767.se>
|
||||
License: BSD-3-Clause
|
||||
|
||||
Files: tools/cpplint/*
|
||||
Copyright: 2009 Google Inc. All rights reserved.
|
||||
License: BSD-3-Clause
|
||||
|
||||
Files: tools/gdb_pretty_printer
|
||||
Copyright: 2020 Hannes Domani <https://github.com/ssbssa>
|
||||
License: MIT
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++
|
||||
| | |__ | | | | | | version 3.11.1
|
||||
| | |__ | | | | | | version 3.11.3
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
{% for copyright_line in copyright_lines %}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (supporting code)
|
||||
| | |__ | | | | | | version 3.11.1
|
||||
| | |__ | | | | | | version 3.11.3
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
{% for copyright_line in copyright_lines %}
|
||||
|
||||
52
BUILD.bazel
Normal file
52
BUILD.bazel
Normal file
@@ -0,0 +1,52 @@
|
||||
cc_library(
|
||||
name = "json",
|
||||
hdrs = [
|
||||
"include/nlohmann/adl_serializer.hpp",
|
||||
"include/nlohmann/byte_container_with_subtype.hpp",
|
||||
"include/nlohmann/detail/abi_macros.hpp",
|
||||
"include/nlohmann/detail/conversions/from_json.hpp",
|
||||
"include/nlohmann/detail/conversions/to_chars.hpp",
|
||||
"include/nlohmann/detail/conversions/to_json.hpp",
|
||||
"include/nlohmann/detail/exceptions.hpp",
|
||||
"include/nlohmann/detail/hash.hpp",
|
||||
"include/nlohmann/detail/input/binary_reader.hpp",
|
||||
"include/nlohmann/detail/input/input_adapters.hpp",
|
||||
"include/nlohmann/detail/input/json_sax.hpp",
|
||||
"include/nlohmann/detail/input/lexer.hpp",
|
||||
"include/nlohmann/detail/input/parser.hpp",
|
||||
"include/nlohmann/detail/input/position_t.hpp",
|
||||
"include/nlohmann/detail/iterators/internal_iterator.hpp",
|
||||
"include/nlohmann/detail/iterators/iter_impl.hpp",
|
||||
"include/nlohmann/detail/iterators/iteration_proxy.hpp",
|
||||
"include/nlohmann/detail/iterators/iterator_traits.hpp",
|
||||
"include/nlohmann/detail/iterators/json_reverse_iterator.hpp",
|
||||
"include/nlohmann/detail/iterators/primitive_iterator.hpp",
|
||||
"include/nlohmann/detail/json_custom_base_class.hpp",
|
||||
"include/nlohmann/detail/json_pointer.hpp",
|
||||
"include/nlohmann/detail/json_ref.hpp",
|
||||
"include/nlohmann/detail/macro_scope.hpp",
|
||||
"include/nlohmann/detail/macro_unscope.hpp",
|
||||
"include/nlohmann/detail/meta/call_std/begin.hpp",
|
||||
"include/nlohmann/detail/meta/call_std/end.hpp",
|
||||
"include/nlohmann/detail/meta/cpp_future.hpp",
|
||||
"include/nlohmann/detail/meta/detected.hpp",
|
||||
"include/nlohmann/detail/meta/identity_tag.hpp",
|
||||
"include/nlohmann/detail/meta/is_sax.hpp",
|
||||
"include/nlohmann/detail/meta/std_fs.hpp",
|
||||
"include/nlohmann/detail/meta/type_traits.hpp",
|
||||
"include/nlohmann/detail/meta/void_t.hpp",
|
||||
"include/nlohmann/detail/output/binary_writer.hpp",
|
||||
"include/nlohmann/detail/output/output_adapters.hpp",
|
||||
"include/nlohmann/detail/output/serializer.hpp",
|
||||
"include/nlohmann/detail/string_concat.hpp",
|
||||
"include/nlohmann/detail/string_escape.hpp",
|
||||
"include/nlohmann/detail/value_t.hpp",
|
||||
"include/nlohmann/json.hpp",
|
||||
"include/nlohmann/json_fwd.hpp",
|
||||
"include/nlohmann/ordered_map.hpp",
|
||||
"include/nlohmann/thirdparty/hedley/hedley.hpp",
|
||||
"include/nlohmann/thirdparty/hedley/hedley_undef.hpp",
|
||||
],
|
||||
includes = ["include"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
@@ -7,8 +7,8 @@ authors:
|
||||
email: mail@nlohmann.me
|
||||
website: https://nlohmann.me
|
||||
title: "JSON for Modern C++"
|
||||
version: 3.11.1
|
||||
date-released: 2022-01-03
|
||||
version: 3.11.3
|
||||
date-released: 2023-11-28
|
||||
license: MIT
|
||||
repository-code: "https://github.com/nlohmann"
|
||||
url: https://json.nlohmann.me
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
cmake_minimum_required(VERSION 3.1...3.14)
|
||||
|
||||
##
|
||||
## PROJECT
|
||||
## name and version
|
||||
##
|
||||
project(nlohmann_json VERSION 3.11.1 LANGUAGES CXX)
|
||||
project(nlohmann_json VERSION 3.11.3 LANGUAGES CXX)
|
||||
|
||||
##
|
||||
## MAIN_PROJECT CHECK
|
||||
@@ -40,10 +40,10 @@ endif()
|
||||
option(JSON_BuildTests "Build the unit tests when BUILD_TESTING is enabled." ${JSON_BuildTests_INIT})
|
||||
option(JSON_CI "Enable CI build targets." OFF)
|
||||
option(JSON_Diagnostics "Use extended diagnostic messages." OFF)
|
||||
option(JSON_GlobalUDLs "Place use-defined string literals in the global namespace." ON)
|
||||
option(JSON_GlobalUDLs "Place user-defined string literals in the global namespace." ON)
|
||||
option(JSON_ImplicitConversions "Enable implicit conversions." ON)
|
||||
option(JSON_DisableEnumSerialization "Disable default integer enum serialization." OFF)
|
||||
option(JSON_LegacyDiscardedValueComparison "Enable legacy discarded value comparison." OFF)
|
||||
option(JSON_LegacyDiscardedValueComparison "Enable legacy discarded value comparison." OFF)
|
||||
option(JSON_Install "Install CMake targets during install step." ${MAIN_PROJECT})
|
||||
option(JSON_MultipleHeaders "Use non-amalgamated version of the library." ON)
|
||||
option(JSON_SystemInclude "Include as system headers (skip for clang-tidy)." OFF)
|
||||
@@ -57,7 +57,11 @@ endif ()
|
||||
##
|
||||
include(GNUInstallDirs)
|
||||
|
||||
set(NLOHMANN_JSON_TARGET_NAME ${PROJECT_NAME})
|
||||
if (NOT DEFINED NLOHMANN_JSON_TARGET_NAME)
|
||||
# Allow overriding the target name when using FetchContent / add_subdirectory.
|
||||
set(NLOHMANN_JSON_TARGET_NAME ${PROJECT_NAME})
|
||||
endif()
|
||||
|
||||
set(NLOHMANN_JSON_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}" CACHE INTERNAL "")
|
||||
set(NLOHMANN_JSON_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
|
||||
set(NLOHMANN_JSON_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
|
||||
@@ -92,6 +96,10 @@ if (JSON_Diagnostics)
|
||||
message(STATUS "Diagnostics enabled")
|
||||
endif()
|
||||
|
||||
if (NOT JSON_GlobalUDLs)
|
||||
message(STATUS "User-defined string literals are not put in the global namespace")
|
||||
endif()
|
||||
|
||||
if (JSON_SystemInclude)
|
||||
set(NLOHMANN_JSON_SYSTEM_INCLUDE "SYSTEM")
|
||||
endif()
|
||||
@@ -122,7 +130,7 @@ target_include_directories(
|
||||
${NLOHMANN_JSON_TARGET_NAME}
|
||||
${NLOHMANN_JSON_SYSTEM_INCLUDE} INTERFACE
|
||||
$<BUILD_INTERFACE:${NLOHMANN_JSON_INCLUDE_BUILD_DIR}>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
$<INSTALL_INTERFACE:${NLOHMANN_JSON_INCLUDE_INSTALL_DIR}>
|
||||
)
|
||||
|
||||
## add debug view definition file for msvc (natvis)
|
||||
@@ -141,6 +149,7 @@ endif()
|
||||
CONFIGURE_FILE(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/pkg-config.pc.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
|
||||
@ONLY
|
||||
)
|
||||
|
||||
##
|
||||
@@ -206,4 +215,5 @@ if(JSON_Install)
|
||||
FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
|
||||
DESTINATION ${NLOHMANN_JSON_PKGCONFIG_INSTALL_DIR}
|
||||
)
|
||||
include(CPack)
|
||||
endif()
|
||||
|
||||
44
ChangeLog.md
44
ChangeLog.md
@@ -1,9 +1,49 @@
|
||||
# Changelog
|
||||
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [3.11.1](https://github.com/nlohmann/json/releases/tag/3.11.1) (2022-08-01)
|
||||
## [3.11.2](https://github.com/nlohmann/json/releases/tag/3.11.2) (2022-08-12)
|
||||
|
||||
[Full Changelog](https://github.com/nlohmann/json/compare/v3.11.0...3.11.1)
|
||||
[Full Changelog](https://github.com/nlohmann/json/compare/v3.11.1...3.11.2)
|
||||
|
||||
- MSVC natvis visualizer does not work after introduction of inline ABI namespace [\#3696](https://github.com/nlohmann/json/issues/3696)
|
||||
- The use of parenthesis gives compilation errors in some situations [\#3682](https://github.com/nlohmann/json/issues/3682)
|
||||
- extern from/to\_json result in linker error [\#3657](https://github.com/nlohmann/json/issues/3657)
|
||||
- json\_fwd.hpp no longer standalone [\#3656](https://github.com/nlohmann/json/issues/3656)
|
||||
- regression: `.value<size_t>` is compilation error. [\#3655](https://github.com/nlohmann/json/issues/3655)
|
||||
- Regression: no match for 'operator!=' comparing json\_pointer and const char \*/string\_t [\#3654](https://github.com/nlohmann/json/issues/3654)
|
||||
- Regression: call to member function 'value' is ambiguous [\#3652](https://github.com/nlohmann/json/issues/3652)
|
||||
- macOS 10.15 Actions runner image deprecation [\#3612](https://github.com/nlohmann/json/issues/3612)
|
||||
|
||||
- generate\_natvis.py: validate version number; cleanup [\#3698](https://github.com/nlohmann/json/pull/3698) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger))
|
||||
- Add Python script for generating Natvis file and update file for 3.11.2 [\#3697](https://github.com/nlohmann/json/pull/3697) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger))
|
||||
- fix typo in json\_pointer.md [\#3692](https://github.com/nlohmann/json/pull/3692) ([eltociear](https://github.com/eltociear))
|
||||
- Add amalgamated json-fwd.hpp to release [\#3687](https://github.com/nlohmann/json/pull/3687) ([nlohmann](https://github.com/nlohmann))
|
||||
- Documentation updates for 3.11.2 [\#3686](https://github.com/nlohmann/json/pull/3686) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger))
|
||||
- Make json\_pointer usable as map key \(again\) [\#3685](https://github.com/nlohmann/json/pull/3685) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger))
|
||||
- Deprecate json\_pointer/string\_t comparisons [\#3684](https://github.com/nlohmann/json/pull/3684) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger))
|
||||
- Restructure inline namespace and allow version component to be disabled [\#3683](https://github.com/nlohmann/json/pull/3683) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger))
|
||||
- Properly constrain non-string json\_pointer overloads [\#3681](https://github.com/nlohmann/json/pull/3681) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger))
|
||||
- Amalgamate the forward declaration header [\#3679](https://github.com/nlohmann/json/pull/3679) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger))
|
||||
- Fix 'const' qualifier on bool& has no effect [\#3678](https://github.com/nlohmann/json/pull/3678) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger))
|
||||
- Fix whitespace in workflow files [\#3675](https://github.com/nlohmann/json/pull/3675) ([nlohmann](https://github.com/nlohmann))
|
||||
- Attempt to fix labeler permissions [\#3674](https://github.com/nlohmann/json/pull/3674) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger))
|
||||
- Refine 'Publish documentation' workflow [\#3673](https://github.com/nlohmann/json/pull/3673) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger))
|
||||
- Documentation change [\#3672](https://github.com/nlohmann/json/pull/3672) ([nlohmann](https://github.com/nlohmann))
|
||||
- Add labeler action [\#3671](https://github.com/nlohmann/json/pull/3671) ([nlohmann](https://github.com/nlohmann))
|
||||
- Complete contributor list [\#3670](https://github.com/nlohmann/json/pull/3670) ([nlohmann](https://github.com/nlohmann))
|
||||
- Add json\_pointer/string\_t equality comparison operators [\#3664](https://github.com/nlohmann/json/pull/3664) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger))
|
||||
- Reimplement value\(\) access functions [\#3663](https://github.com/nlohmann/json/pull/3663) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger))
|
||||
- Complete contributor list [\#3662](https://github.com/nlohmann/json/pull/3662) ([nlohmann](https://github.com/nlohmann))
|
||||
- Adjust naming of GitHub action jobs [\#3661](https://github.com/nlohmann/json/pull/3661) ([nlohmann](https://github.com/nlohmann))
|
||||
- Publish documentation on push to develop branch [\#3660](https://github.com/nlohmann/json/pull/3660) ([nlohmann](https://github.com/nlohmann))
|
||||
- Add Discord badge to README [\#3651](https://github.com/nlohmann/json/pull/3651) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger))
|
||||
- Miscellaneous small fixes [\#3643](https://github.com/nlohmann/json/pull/3643) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger))
|
||||
- Minor BJData fixes [\#3637](https://github.com/nlohmann/json/pull/3637) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger))
|
||||
- Update CI [\#3626](https://github.com/nlohmann/json/pull/3626) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger))
|
||||
|
||||
## [v3.11.1](https://github.com/nlohmann/json/releases/tag/v3.11.1) (2022-08-01)
|
||||
|
||||
[Full Changelog](https://github.com/nlohmann/json/compare/v3.11.0...v3.11.1)
|
||||
|
||||
- Regression: no matching literal operator for call to 'operator""\_json' [\#3645](https://github.com/nlohmann/json/issues/3645)
|
||||
- \_json operator""\(\) [\#3644](https://github.com/nlohmann/json/issues/3644)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2013-2022 Niels Lohmann
|
||||
Copyright (c) 2013-2024 Niels Lohmann
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
48
Makefile
48
Makefile
@@ -18,8 +18,9 @@ SRCS=$(shell find include -type f | sort)
|
||||
# the list of sources in the tests folder
|
||||
TESTS_SRCS=$(shell find tests -type f \( -name '*.hpp' -o -name '*.cpp' -o -name '*.cu' \) -not -path 'tests/thirdparty/*' -not -path 'tests/abi/include/nlohmann/*' | sort)
|
||||
|
||||
# the single header (amalgamated from the source files)
|
||||
# the single headers (amalgamated from the source files)
|
||||
AMALGAMATED_FILE=single_include/nlohmann/json.hpp
|
||||
AMALGAMATED_FWD_FILE=single_include/nlohmann/json_fwd.hpp
|
||||
|
||||
|
||||
##########################################################################
|
||||
@@ -28,7 +29,7 @@ AMALGAMATED_FILE=single_include/nlohmann/json.hpp
|
||||
|
||||
# main target
|
||||
all:
|
||||
@echo "amalgamate - amalgamate file single_include/nlohmann/json.hpp from the include/nlohmann sources"
|
||||
@echo "amalgamate - amalgamate files single_include/nlohmann/json{,_fwd}.hpp from the include/nlohmann sources"
|
||||
@echo "ChangeLog.md - generate ChangeLog file"
|
||||
@echo "check-amalgamation - check whether sources have been amalgamated"
|
||||
@echo "clean - remove built files"
|
||||
@@ -144,9 +145,9 @@ pvs_studio:
|
||||
# call the Artistic Style pretty printer on all source files
|
||||
pretty:
|
||||
astyle \
|
||||
--style=allman \
|
||||
--indent=spaces=4 \
|
||||
--indent-modifiers \
|
||||
--style=allman \
|
||||
--indent=spaces=4 \
|
||||
--indent-modifiers \
|
||||
--indent-switches \
|
||||
--indent-preproc-block \
|
||||
--indent-preproc-define \
|
||||
@@ -155,35 +156,44 @@ pretty:
|
||||
--pad-header \
|
||||
--align-pointer=type \
|
||||
--align-reference=type \
|
||||
--add-brackets \
|
||||
--add-braces \
|
||||
--convert-tabs \
|
||||
--close-templates \
|
||||
--lineend=linux \
|
||||
--preserve-date \
|
||||
--suffix=none \
|
||||
--formatted \
|
||||
$(SRCS) $(TESTS_SRCS) $(AMALGAMATED_FILE) docs/examples/*.cpp
|
||||
$(SRCS) $(TESTS_SRCS) $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) docs/examples/*.cpp
|
||||
|
||||
# call the Clang-Format on all source files
|
||||
pretty_format:
|
||||
for FILE in $(SRCS) $(TESTS_SRCS) $(AMALGAMATED_FILE) docs/examples/*.cpp; do echo $$FILE; clang-format -i $$FILE; done
|
||||
|
||||
# create single header file
|
||||
amalgamate: $(AMALGAMATED_FILE)
|
||||
|
||||
# call the amalgamation tool and pretty print
|
||||
$(AMALGAMATED_FILE): $(SRCS)
|
||||
tools/amalgamate/amalgamate.py -c tools/amalgamate/config.json -s . --verbose=yes
|
||||
# create single header files and pretty print
|
||||
amalgamate: $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE)
|
||||
$(MAKE) pretty
|
||||
|
||||
# call the amalgamation tool for json.hpp
|
||||
$(AMALGAMATED_FILE): $(SRCS)
|
||||
tools/amalgamate/amalgamate.py -c tools/amalgamate/config_json.json -s . --verbose=yes
|
||||
|
||||
# call the amalgamation tool for json_fwd.hpp
|
||||
$(AMALGAMATED_FWD_FILE): $(SRCS)
|
||||
tools/amalgamate/amalgamate.py -c tools/amalgamate/config_json_fwd.json -s . --verbose=yes
|
||||
|
||||
# check if file single_include/nlohmann/json.hpp has been amalgamated from the nlohmann sources
|
||||
# Note: this target is called by Travis
|
||||
check-amalgamation:
|
||||
@mv $(AMALGAMATED_FILE) $(AMALGAMATED_FILE)~
|
||||
@mv $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_FWD_FILE)~
|
||||
@$(MAKE) amalgamate
|
||||
@diff $(AMALGAMATED_FILE) $(AMALGAMATED_FILE)~ || (echo "===================================================================\n Amalgamation required! Please read the contribution guidelines\n in file .github/CONTRIBUTING.md.\n===================================================================" ; mv $(AMALGAMATED_FILE)~ $(AMALGAMATED_FILE) ; false)
|
||||
@diff $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_FWD_FILE)~ || (echo "===================================================================\n Amalgamation required! Please read the contribution guidelines\n in file .github/CONTRIBUTING.md.\n===================================================================" ; mv $(AMALGAMATED_FWD_FILE)~ $(AMALGAMATED_FWD_FILE) ; false)
|
||||
@mv $(AMALGAMATED_FILE)~ $(AMALGAMATED_FILE)
|
||||
@mv $(AMALGAMATED_FWD_FILE)~ $(AMALGAMATED_FWD_FILE)
|
||||
|
||||
BUILD.bazel: $(SRCS)
|
||||
cmake -P cmake/scripts/gen_bazel_build_file.cmake
|
||||
|
||||
##########################################################################
|
||||
# ChangeLog
|
||||
@@ -215,8 +225,8 @@ json.tar.xz:
|
||||
|
||||
# We use `-X` to make the resulting ZIP file reproducible, see
|
||||
# <https://content.pivotal.io/blog/barriers-to-deterministic-reproducible-zip-files>.
|
||||
include.zip:
|
||||
zip -9 --recurse-paths -X include.zip $(SRCS) $(AMALGAMATED_FILE) meson.build LICENSE.MIT
|
||||
include.zip: BUILD.bazel
|
||||
zip -9 --recurse-paths -X include.zip $(SRCS) $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) BUILD.bazel WORKSPACE.bazel meson.build LICENSE.MIT
|
||||
|
||||
# Create the files for a release and add signatures and hashes.
|
||||
release: include.zip json.tar.xz
|
||||
@@ -224,9 +234,11 @@ release: include.zip json.tar.xz
|
||||
mkdir release_files
|
||||
gpg --armor --detach-sig include.zip
|
||||
gpg --armor --detach-sig $(AMALGAMATED_FILE)
|
||||
gpg --armor --detach-sig $(AMALGAMATED_FWD_FILE)
|
||||
gpg --armor --detach-sig json.tar.xz
|
||||
cp $(AMALGAMATED_FILE) release_files
|
||||
mv $(AMALGAMATED_FILE).asc json.tar.xz json.tar.xz.asc include.zip include.zip.asc release_files
|
||||
cp $(AMALGAMATED_FWD_FILE) release_files
|
||||
mv $(AMALGAMATED_FILE).asc $(AMALGAMATED_FWD_FILE).asc json.tar.xz json.tar.xz.asc include.zip include.zip.asc release_files
|
||||
cd release_files ; shasum -a 256 json.hpp include.zip json.tar.xz > hashes.txt
|
||||
|
||||
|
||||
@@ -267,6 +279,6 @@ serve_header:
|
||||
##########################################################################
|
||||
|
||||
reuse:
|
||||
pipx run reuse addheader --recursive single_include include -tjson --license MIT --copyright "Niels Lohmann <https://nlohmann.me>" --year "2013-2022"
|
||||
pipx run reuse addheader $(TESTS_SRCS) --style=c -tjson_support --license MIT --copyright "Niels Lohmann <https://nlohmann.me>" --year "2013-2022"
|
||||
pipx run reuse annotate --recursive single_include include -tjson --license MIT --copyright "Niels Lohmann <https://nlohmann.me>" --year "2013-2024" --merge-copyrights
|
||||
pipx run reuse annotate $(TESTS_SRCS) -tjson_support --license MIT --copyright "Niels Lohmann <https://nlohmann.me>" --year "2013-2024" --merge-copyrights
|
||||
pipx run reuse lint
|
||||
|
||||
22
Package.swift
Normal file
22
Package.swift
Normal file
@@ -0,0 +1,22 @@
|
||||
// swift-tools-version: 5.9
|
||||
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
||||
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "nlohmann-json",
|
||||
platforms: [
|
||||
.iOS(.v12), .macOS(.v10_13), .tvOS(.v12), .watchOS(.v4)
|
||||
],
|
||||
products: [
|
||||
.library(name: "json", targets: ["json"])
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
name: "json",
|
||||
path: "single_include/nlohmann",
|
||||
publicHeadersPath: "."
|
||||
)
|
||||
],
|
||||
cxxLanguageStandard: .cxx11
|
||||
)
|
||||
1
WORKSPACE.bazel
Normal file
1
WORKSPACE.bazel
Normal file
@@ -0,0 +1 @@
|
||||
workspace(name = "nlohmann_json")
|
||||
119
cmake/ci.cmake
119
cmake/ci.cmake
@@ -13,12 +13,12 @@ execute_process(COMMAND ${ASTYLE_TOOL} --version OUTPUT_VARIABLE ASTYLE_TOOL_VER
|
||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" ASTYLE_TOOL_VERSION "${ASTYLE_TOOL_VERSION}")
|
||||
message(STATUS "🔖 Artistic Style ${ASTYLE_TOOL_VERSION} (${ASTYLE_TOOL})")
|
||||
|
||||
find_program(CLANG_TOOL NAMES clang++-HEAD clang++-15 clang++-14 clang++-13 clang++-12 clang++-11 clang++)
|
||||
find_program(CLANG_TOOL NAMES clang++-HEAD clang++ clang++-20 clang++-19 clang++-18 clang++-17 clang++-16 clang++-15 clang++-14 clang++-13 clang++-12 clang++-11 clang++)
|
||||
execute_process(COMMAND ${CLANG_TOOL} --version OUTPUT_VARIABLE CLANG_TOOL_VERSION ERROR_VARIABLE CLANG_TOOL_VERSION)
|
||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TOOL_VERSION "${CLANG_TOOL_VERSION}")
|
||||
message(STATUS "🔖 Clang ${CLANG_TOOL_VERSION} (${CLANG_TOOL})")
|
||||
|
||||
find_program(CLANG_TIDY_TOOL NAMES clang-tidy-15 clang-tidy-14 clang-tidy-13 clang-tidy-12 clang-tidy-11 clang-tidy)
|
||||
find_program(CLANG_TIDY_TOOL NAMES clang-tidy-17 clang-tidy-16 clang-tidy-15 clang-tidy-14 clang-tidy-13 clang-tidy-12 clang-tidy-11 clang-tidy)
|
||||
execute_process(COMMAND ${CLANG_TIDY_TOOL} --version OUTPUT_VARIABLE CLANG_TIDY_TOOL_VERSION ERROR_VARIABLE CLANG_TIDY_TOOL_VERSION)
|
||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TIDY_TOOL_VERSION "${CLANG_TIDY_TOOL_VERSION}")
|
||||
message(STATUS "🔖 Clang-Tidy ${CLANG_TIDY_TOOL_VERSION} (${CLANG_TIDY_TOOL})")
|
||||
@@ -30,7 +30,7 @@ execute_process(COMMAND ${CPPCHECK_TOOL} --version OUTPUT_VARIABLE CPPCHECK_TOOL
|
||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CPPCHECK_TOOL_VERSION "${CPPCHECK_TOOL_VERSION}")
|
||||
message(STATUS "🔖 Cppcheck ${CPPCHECK_TOOL_VERSION} (${CPPCHECK_TOOL})")
|
||||
|
||||
find_program(GCC_TOOL NAMES g++-latest g++-HEAD g++-11 g++-10)
|
||||
find_program(GCC_TOOL NAMES g++-latest g++-HEAD g++-13 g++-12 g++-11 g++-10)
|
||||
execute_process(COMMAND ${GCC_TOOL} --version OUTPUT_VARIABLE GCC_TOOL_VERSION ERROR_VARIABLE GCC_TOOL_VERSION)
|
||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" GCC_TOOL_VERSION "${GCC_TOOL_VERSION}")
|
||||
message(STATUS "🔖 GCC ${GCC_TOOL_VERSION} (${GCC_TOOL})")
|
||||
@@ -95,7 +95,7 @@ file(GLOB_RECURSE SRC_FILES ${PROJECT_SOURCE_DIR}/include/nlohmann/*.hpp)
|
||||
# -Wno-extra-semi-stmt The library uses std::assert which triggers this warning.
|
||||
# -Wno-padded We do not care about padding warnings.
|
||||
# -Wno-covered-switch-default All switches list all cases and a default case.
|
||||
# -Wno-weak-vtables The library is header-only.
|
||||
# -Wno-unsafe-buffer-usage Otherwise Doctest would not compile.
|
||||
# -Wreserved-identifier See https://github.com/onqtam/doctest/issues/536.
|
||||
|
||||
set(CLANG_CXXFLAGS
|
||||
@@ -107,7 +107,7 @@ set(CLANG_CXXFLAGS
|
||||
-Wno-extra-semi-stmt
|
||||
-Wno-padded
|
||||
-Wno-covered-switch-default
|
||||
-Wno-weak-vtables
|
||||
-Wno-unsafe-buffer-usage
|
||||
-Wno-reserved-identifier
|
||||
)
|
||||
|
||||
@@ -437,7 +437,7 @@ add_custom_target(ci_test_clang
|
||||
# Different C++ Standards.
|
||||
###############################################################################
|
||||
|
||||
foreach(CXX_STANDARD 11 14 17 20)
|
||||
foreach(CXX_STANDARD 11 14 17 20 23)
|
||||
add_custom_target(ci_test_gcc_cxx${CXX_STANDARD}
|
||||
COMMAND CXX=${GCC_TOOL} CXXFLAGS="${GCC_CXXFLAGS}" ${CMAKE_COMMAND}
|
||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||
@@ -459,6 +459,19 @@ foreach(CXX_STANDARD 11 14 17 20)
|
||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD} && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
|
||||
COMMENT "Compile and test with Clang for C++${CXX_STANDARD}"
|
||||
)
|
||||
|
||||
add_custom_target(ci_test_clang_libcxx_cxx${CXX_STANDARD}
|
||||
COMMAND CXX=${CLANG_TOOL} CXXFLAGS="${CLANG_CXXFLAGS}" ${CMAKE_COMMAND}
|
||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||
-DJSON_BuildTests=ON -DJSON_FastTests=ON
|
||||
-DJSON_TestStandards=${CXX_STANDARD}
|
||||
-DCMAKE_CXX_FLAGS="-stdlib=libc++"
|
||||
-DCMAKE_EXE_LINKER_FLAGS="-lc++abi"
|
||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD}
|
||||
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD}
|
||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD} && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
|
||||
COMMENT "Compile and test with Clang for C++${CXX_STANDARD} (libc++)"
|
||||
)
|
||||
endforeach()
|
||||
|
||||
###############################################################################
|
||||
@@ -466,7 +479,7 @@ endforeach()
|
||||
###############################################################################
|
||||
|
||||
add_custom_target(ci_test_noexceptions
|
||||
COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND}
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||
-DJSON_BuildTests=ON -DCMAKE_CXX_FLAGS=-DJSON_NOEXCEPTION -DDOCTEST_TEST_FILTER=--no-throw
|
||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_noexceptions
|
||||
@@ -480,7 +493,7 @@ add_custom_target(ci_test_noexceptions
|
||||
###############################################################################
|
||||
|
||||
add_custom_target(ci_test_noimplicitconversions
|
||||
COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND}
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||
-DJSON_BuildTests=ON -DJSON_ImplicitConversions=OFF
|
||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_noimplicitconversions
|
||||
@@ -494,7 +507,7 @@ add_custom_target(ci_test_noimplicitconversions
|
||||
###############################################################################
|
||||
|
||||
add_custom_target(ci_test_diagnostics
|
||||
COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND}
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||
-DJSON_BuildTests=ON -DJSON_Diagnostics=ON
|
||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_diagnostics
|
||||
@@ -508,7 +521,7 @@ add_custom_target(ci_test_diagnostics
|
||||
###############################################################################
|
||||
|
||||
add_custom_target(ci_test_legacycomparison
|
||||
COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND}
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||
-DJSON_BuildTests=ON -DJSON_LegacyDiscardedValueComparison=ON
|
||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_legacycomparison
|
||||
@@ -522,7 +535,7 @@ add_custom_target(ci_test_legacycomparison
|
||||
###############################################################################
|
||||
|
||||
add_custom_target(ci_test_noglobaludls
|
||||
COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND}
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||
-DJSON_BuildTests=ON -DJSON_FastTests=ON -DJSON_GlobalUDLs=OFF
|
||||
-DCMAKE_CXX_FLAGS=-DJSON_TEST_NO_GLOBAL_UDLS
|
||||
@@ -589,15 +602,22 @@ file(GLOB_RECURSE INDENT_FILES
|
||||
${PROJECT_SOURCE_DIR}/docs/examples/*.cpp
|
||||
)
|
||||
|
||||
set(include_dir ${PROJECT_SOURCE_DIR}/single_include/nlohmann)
|
||||
set(tool_dir ${PROJECT_SOURCE_DIR}/tools/amalgamate)
|
||||
add_custom_target(ci_test_amalgamation
|
||||
COMMAND rm -fr ${PROJECT_SOURCE_DIR}/single_include/nlohmann/json.hpp~
|
||||
COMMAND cp ${PROJECT_SOURCE_DIR}/single_include/nlohmann/json.hpp ${PROJECT_SOURCE_DIR}/single_include/nlohmann/json.hpp~
|
||||
COMMAND ${Python3_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/amalgamate/amalgamate.py -c ${PROJECT_SOURCE_DIR}/tools/amalgamate/config.json -s .
|
||||
COMMAND ${ASTYLE_TOOL} ${ASTYLE_FLAGS} --suffix=none --quiet ${PROJECT_SOURCE_DIR}/single_include/nlohmann/json.hpp
|
||||
COMMAND diff ${PROJECT_SOURCE_DIR}/single_include/nlohmann/json.hpp~ ${PROJECT_SOURCE_DIR}/single_include/nlohmann/json.hpp
|
||||
COMMAND rm -fr ${include_dir}/json.hpp~ ${include_dir}/json_fwd.hpp~
|
||||
COMMAND cp ${include_dir}/json.hpp ${include_dir}/json.hpp~
|
||||
COMMAND cp ${include_dir}/json_fwd.hpp ${include_dir}/json_fwd.hpp~
|
||||
|
||||
COMMAND ${Python3_EXECUTABLE} ${tool_dir}/amalgamate.py -c ${tool_dir}/config_json.json -s .
|
||||
COMMAND ${Python3_EXECUTABLE} ${tool_dir}/amalgamate.py -c ${tool_dir}/config_json_fwd.json -s .
|
||||
COMMAND ${ASTYLE_TOOL} ${ASTYLE_FLAGS} --suffix=none --quiet ${include_dir}/json.hpp ${include_dir}/json_fwd.hpp
|
||||
|
||||
COMMAND diff ${include_dir}/json.hpp~ ${include_dir}/json.hpp
|
||||
COMMAND diff ${include_dir}/json_fwd.hpp~ ${include_dir}/json_fwd.hpp
|
||||
|
||||
COMMAND ${ASTYLE_TOOL} ${ASTYLE_FLAGS} ${INDENT_FILES}
|
||||
COMMAND cd ${PROJECT_SOURCE_DIR} && for FILE in `find . -name '*.orig'`\; do false \; done
|
||||
COMMAND for FILE in `find . -name '*.orig'`\; do false \; done
|
||||
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||
COMMENT "Check amalgamation and indentation"
|
||||
@@ -660,8 +680,11 @@ add_custom_target(ci_cppcheck
|
||||
###############################################################################
|
||||
|
||||
add_custom_target(ci_cpplint
|
||||
COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/cpplint/cpplint.py --filter=-whitespace,-legal,-runtime/references,-runtime/explicit,-runtime/indentation_namespace,-readability/casting,-readability/nolint --quiet --recursive ${SRC_FILES}
|
||||
COMMAND ${Python3_EXECUTABLE} -mvenv venv_cpplint
|
||||
COMMAND venv_cpplint/bin/pip3 --quiet install cpplint
|
||||
COMMAND venv_cpplint/bin/cpplint --filter=-whitespace,-legal,-runtime/references,-runtime/explicit,-runtime/indentation_namespace,-readability/casting,-readability/nolint --quiet --recursive ${SRC_FILES}
|
||||
COMMENT "Check code with cpplint"
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
)
|
||||
|
||||
###############################################################################
|
||||
@@ -826,27 +849,17 @@ add_custom_target(ci_benchmarks
|
||||
###############################################################################
|
||||
|
||||
function(ci_get_cmake version var)
|
||||
if (APPLE)
|
||||
set(${var} ${PROJECT_BINARY_DIR}/cmake-${version}-Darwin64/CMake.app/Contents/bin/cmake)
|
||||
add_custom_command(
|
||||
OUTPUT ${${var}}
|
||||
COMMAND wget -nc https://github.com/Kitware/CMake/releases/download/v${version}/cmake-${version}-Darwin64.tar.gz
|
||||
COMMAND tar xfz cmake-${version}-Darwin64.tar.gz
|
||||
COMMAND rm cmake-${version}-Darwin64.tar.gz
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
COMMENT "Download CMake ${version}"
|
||||
)
|
||||
else()
|
||||
set(${var} ${PROJECT_BINARY_DIR}/cmake-${version}-Linux-x86_64/bin/cmake)
|
||||
add_custom_command(
|
||||
OUTPUT ${${var}}
|
||||
COMMAND wget -nc https://github.com/Kitware/CMake/releases/download/v${version}/cmake-${version}-Linux-x86_64.tar.gz
|
||||
COMMAND tar xfz cmake-${version}-Linux-x86_64.tar.gz
|
||||
COMMAND rm cmake-${version}-Linux-x86_64.tar.gz
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
COMMENT "Download CMake ${version}"
|
||||
)
|
||||
endif()
|
||||
set(${var} ${PROJECT_BINARY_DIR}/cmake-${version}/bin/cmake)
|
||||
add_custom_command(
|
||||
OUTPUT ${${var}}
|
||||
COMMAND wget -nc https://github.com/Kitware/CMake/releases/download/v${version}/cmake-${version}.tar.gz
|
||||
COMMAND tar xfz cmake-${version}.tar.gz
|
||||
COMMAND rm cmake-${version}.tar.gz
|
||||
COMMAND ${CMAKE_COMMAND} -S cmake-${version} -B cmake-${version}
|
||||
COMMAND ${CMAKE_COMMAND} --build cmake-${version} --parallel 10
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
COMMENT "Download CMake ${version}"
|
||||
)
|
||||
set(${var} ${${var}} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
@@ -898,15 +911,10 @@ add_custom_target(ci_cmake_flags
|
||||
# Use more installed compilers.
|
||||
###############################################################################
|
||||
|
||||
foreach(COMPILER g++-4.8 g++-4.9 g++-5 g++-6 g++-7 g++-8 g++-9 g++-10 g++-11 clang++-3.5 clang++-3.6 clang++-3.7 clang++-3.8 clang++-3.9 clang++-4.0 clang++-5.0 clang++-6.0 clang++-7 clang++-8 clang++-9 clang++-10 clang++-11 clang++-12 clang++-13 clang++-14)
|
||||
foreach(COMPILER g++-4.8 g++-4.9 g++-5 g++-6 g++-7 g++-8 g++-9 g++-10 g++-11 clang++-3.5 clang++-3.6 clang++-3.7 clang++-3.8 clang++-3.9 clang++-4.0 clang++-5.0 clang++-6.0 clang++-7 clang++-8 clang++-9 clang++-10 clang++-11 clang++-12 clang++-13 clang++-14 clang++-15 clang++-16 clang++-17 clang++-18 clang++-19 clang++-20)
|
||||
find_program(COMPILER_TOOL NAMES ${COMPILER})
|
||||
if (COMPILER_TOOL)
|
||||
if ("${COMPILER}" STREQUAL "clang++-9")
|
||||
# fix for https://github.com/nlohmann/json/pull/3101#issuecomment-998788786 / https://stackoverflow.com/a/64051725/266378
|
||||
set(ADDITIONAL_FLAGS "-DCMAKE_CXX_FLAGS=--gcc-toolchain=/root/gcc/9")
|
||||
else()
|
||||
unset(ADDITIONAL_FLAGS)
|
||||
endif()
|
||||
unset(ADDITIONAL_FLAGS)
|
||||
|
||||
add_custom_target(ci_test_compiler_${COMPILER}
|
||||
COMMAND CXX=${COMPILER} ${CMAKE_COMMAND}
|
||||
@@ -922,6 +930,17 @@ foreach(COMPILER g++-4.8 g++-4.9 g++-5 g++-6 g++-7 g++-8 g++-9 g++-10 g++-11 cla
|
||||
unset(COMPILER_TOOL CACHE)
|
||||
endforeach()
|
||||
|
||||
add_custom_target(ci_test_compiler_default
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||
-DJSON_BuildTests=ON -DJSON_FastTests=ON
|
||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_compiler_default
|
||||
${ADDITIONAL_FLAGS}
|
||||
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_compiler_default --parallel ${N}
|
||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_compiler_default && ${CMAKE_CTEST_COMMAND} --parallel ${N} --exclude-regex "test-unicode" -LE git_required --output-on-failure
|
||||
COMMENT "Compile and test with default C++ compiler"
|
||||
)
|
||||
|
||||
###############################################################################
|
||||
# CUDA example
|
||||
###############################################################################
|
||||
@@ -953,12 +972,18 @@ add_custom_target(ci_icpc
|
||||
# test documentation
|
||||
###############################################################################
|
||||
|
||||
add_custom_target(ci_test_documentation
|
||||
add_custom_target(ci_test_examples
|
||||
COMMAND make CXX="${GCC_TOOL}" check_output_portable -j8
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/docs
|
||||
COMMENT "Check that all examples compile and create the desired output"
|
||||
)
|
||||
|
||||
add_custom_target(ci_test_api_documentation
|
||||
COMMAND ${Python3_EXECUTABLE} scripts/check_structure.py
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/docs/mkdocs
|
||||
COMMENT "Lint the API documentation"
|
||||
)
|
||||
|
||||
###############################################################################
|
||||
# Clean up all generated files.
|
||||
###############################################################################
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
Name: ${PROJECT_NAME}
|
||||
prefix=@CMAKE_INSTALL_PREFIX@
|
||||
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
|
||||
|
||||
Name: @PROJECT_NAME@
|
||||
Description: JSON for Modern C++
|
||||
Version: ${PROJECT_VERSION}
|
||||
Cflags: -I${CMAKE_INSTALL_FULL_INCLUDEDIR}
|
||||
Version: @PROJECT_VERSION@
|
||||
Cflags: -I${includedir}
|
||||
|
||||
24
cmake/scripts/gen_bazel_build_file.cmake
Normal file
24
cmake/scripts/gen_bazel_build_file.cmake
Normal file
@@ -0,0 +1,24 @@
|
||||
# generate Bazel BUILD file
|
||||
|
||||
set(PROJECT_ROOT "${CMAKE_CURRENT_LIST_DIR}/../..")
|
||||
set(BUILD_FILE "${PROJECT_ROOT}/BUILD.bazel")
|
||||
|
||||
file(GLOB_RECURSE HEADERS LIST_DIRECTORIES false RELATIVE "${PROJECT_ROOT}" "include/*.hpp")
|
||||
|
||||
file(WRITE "${BUILD_FILE}" [=[
|
||||
cc_library(
|
||||
name = "json",
|
||||
hdrs = [
|
||||
]=])
|
||||
|
||||
foreach(header ${HEADERS})
|
||||
file(APPEND "${BUILD_FILE}" " \"${header}\",\n")
|
||||
endforeach()
|
||||
|
||||
file(APPEND "${BUILD_FILE}" [=[
|
||||
],
|
||||
includes = ["include"],
|
||||
visibility = ["//visibility:public"],
|
||||
alwayslink = True,
|
||||
)
|
||||
]=])
|
||||
@@ -259,7 +259,7 @@ function(json_test_should_build_32bit_test build_32bit_var build_32bit_only_var
|
||||
# check if compiler is targeting 32bit by default
|
||||
include(CheckTypeSize)
|
||||
check_type_size("size_t" sizeof_size_t LANGUAGE CXX)
|
||||
if(sizeof_size_t AND ${sizeof_size_t} EQUAL 4)
|
||||
if(${sizeof_size_t} AND ${sizeof_size_t} EQUAL 4)
|
||||
message(STATUS "Auto-enabling 32bit unit test.")
|
||||
set(${build_32bit_var} ON)
|
||||
else()
|
||||
|
||||
BIN
docs/avatars.png
BIN
docs/avatars.png
Binary file not shown.
|
Before Width: | Height: | Size: 1.5 MiB After Width: | Height: | Size: 1.6 MiB |
@@ -1,3 +1,4 @@
|
||||
SHELL=/usr/bin/env bash
|
||||
SED ?= $(shell which gsed 2>/dev/null || which sed)
|
||||
|
||||
MKDOCS_PAGES=$(shell cd ../mkdocs/docs/ && find * -type f -name '*.md' | sort)
|
||||
|
||||
@@ -128,6 +128,8 @@ INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer', 'Class', 'api/
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::back', 'Method', 'api/json_pointer/back/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::empty', 'Method', 'api/json_pointer/empty/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::json_pointer', 'Constructor', 'api/json_pointer/json_pointer/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::operator==', 'Operator', 'api/json_pointer/operator_eq/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::operator!=', 'Operator', 'api/json_pointer/operator_ne/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::operator/', 'Operator', 'api/json_pointer/operator_slash/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::operator/=', 'Operator', 'api/json_pointer/operator_slasheq/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::operator string_t', 'Operator', 'api/json_pointer/operator_string_t/index.html');
|
||||
@@ -173,6 +175,7 @@ INSERT INTO searchIndex(name, type, path) VALUES ('Element Access', 'Guide', 'fe
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('Element Access: Access with default value: value', 'Guide', 'features/element_access/default_value/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('Element Access: Checked access: at', 'Guide', 'features/element_access/checked_access/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('Element Access: Unchecked access: operator[]', 'Guide', 'features/element_access/unchecked_access/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('Integration: Migration Guide', 'Guide', 'integration/migration_guide/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('Integration: CMake', 'Guide', 'integration/cmake/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('Integration: Header only', 'Guide', 'integration/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('Integration: Package Managers', 'Guide', 'integration/package_managers/index.html');
|
||||
@@ -181,6 +184,7 @@ INSERT INTO searchIndex(name, type, path) VALUES ('Iterators', 'Guide', 'feature
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON Merge Patch', 'Guide', 'features/merge_patch/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON Patch and Diff', 'Guide', 'features/json_patch/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON Pointer', 'Guide', 'features/json_pointer/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('nlohmann Namespace', 'Guide', 'features/namespace/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('Types', 'Guide', 'features/types/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('Types: Number Handling', 'Guide', 'features/types/number_handling/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('Object Order', 'Guide', 'features/object_order/index.html');
|
||||
@@ -223,6 +227,7 @@ INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_TYPE_NON_INTR
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_JSON_NAMESPACE', 'Macro', 'api/macros/nlohmann_json_namespace/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_JSON_NAMESPACE_BEGIN', 'Macro', 'api/macros/nlohmann_json_namespace_begin/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_JSON_NAMESPACE_END', 'Macro', 'api/macros/nlohmann_json_namespace_begin/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_JSON_NAMESPACE_NO_VERSION', 'Macro', 'api/macros/nlohmann_json_namespace_no_version/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_JSON_SERIALIZE_ENUM', 'Macro', 'api/macros/nlohmann_json_serialize_enum/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_JSON_VERSION_MAJOR', 'Macro', 'api/macros/nlohmann_json_version_major/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_JSON_VERSION_MINOR', 'Macro', 'api/macros/nlohmann_json_version_major/index.html');
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "JSON for Modern C++",
|
||||
"version": "3.11.1",
|
||||
"version": "3.11.3",
|
||||
"archive": "JSON_for_Modern_C++.tgz",
|
||||
"author": {
|
||||
"name": "Niels Lohmann",
|
||||
|
||||
@@ -35,14 +35,13 @@ int main()
|
||||
// output the changed array
|
||||
std::cout << j["array"] << '\n';
|
||||
|
||||
|
||||
// out_of_range.106
|
||||
try
|
||||
{
|
||||
// try to use an array index with leading '0'
|
||||
json::reference ref = j.at("/array/01"_json_pointer);
|
||||
}
|
||||
catch (json::parse_error& e)
|
||||
catch (const json::parse_error& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
@@ -53,7 +52,7 @@ int main()
|
||||
// try to use an array index that is not a number
|
||||
json::reference ref = j.at("/array/one"_json_pointer);
|
||||
}
|
||||
catch (json::parse_error& e)
|
||||
catch (const json::parse_error& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
@@ -64,7 +63,7 @@ int main()
|
||||
// try to use an invalid array index
|
||||
json::reference ref = j.at("/array/4"_json_pointer);
|
||||
}
|
||||
catch (json::out_of_range& e)
|
||||
catch (const json::out_of_range& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
@@ -75,7 +74,7 @@ int main()
|
||||
// try to use the array index '-'
|
||||
json::reference ref = j.at("/array/-"_json_pointer);
|
||||
}
|
||||
catch (json::out_of_range& e)
|
||||
catch (const json::out_of_range& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
@@ -86,7 +85,7 @@ int main()
|
||||
// try to use a JSON pointer to a nonexistent object key
|
||||
json::const_reference ref = j.at("/foo"_json_pointer);
|
||||
}
|
||||
catch (json::out_of_range& e)
|
||||
catch (const json::out_of_range& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
@@ -97,7 +96,7 @@ int main()
|
||||
// try to use a JSON pointer that cannot be resolved
|
||||
json::reference ref = j.at("/number/foo"_json_pointer);
|
||||
}
|
||||
catch (json::out_of_range& e)
|
||||
catch (const json::out_of_range& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ int main()
|
||||
// try to use an array index that is not a number
|
||||
json::const_reference ref = j.at("/array/one"_json_pointer);
|
||||
}
|
||||
catch (json::parse_error& e)
|
||||
catch (const json::parse_error& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
@@ -40,7 +40,7 @@ int main()
|
||||
// try to use an invalid array index
|
||||
json::const_reference ref = j.at("/array/4"_json_pointer);
|
||||
}
|
||||
catch (json::out_of_range& e)
|
||||
catch (const json::out_of_range& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
@@ -51,7 +51,7 @@ int main()
|
||||
// try to use the array index '-'
|
||||
json::const_reference ref = j.at("/array/-"_json_pointer);
|
||||
}
|
||||
catch (json::out_of_range& e)
|
||||
catch (const json::out_of_range& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
@@ -62,7 +62,7 @@ int main()
|
||||
// try to use a JSON pointer to a nonexistent object key
|
||||
json::const_reference ref = j.at("/foo"_json_pointer);
|
||||
}
|
||||
catch (json::out_of_range& e)
|
||||
catch (const json::out_of_range& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
@@ -73,7 +73,7 @@ int main()
|
||||
// try to use a JSON pointer that cannot be resolved
|
||||
json::const_reference ref = j.at("/number/foo"_json_pointer);
|
||||
}
|
||||
catch (json::out_of_range& e)
|
||||
catch (const json::out_of_range& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ int main()
|
||||
// output changed array
|
||||
std::cout << object << '\n';
|
||||
|
||||
|
||||
// exception type_error.304
|
||||
try
|
||||
{
|
||||
@@ -32,7 +31,7 @@ int main()
|
||||
json str = "I am a string";
|
||||
str.at("the good"sv) = "Another string";
|
||||
}
|
||||
catch (json::type_error& e)
|
||||
catch (const json::type_error& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
@@ -43,7 +42,7 @@ int main()
|
||||
// try to write at a nonexisting key using string_view
|
||||
object.at("the fast"sv) = "il rapido";
|
||||
}
|
||||
catch (json::out_of_range& e)
|
||||
catch (const json::out_of_range& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ int main()
|
||||
// output element with key "the ugly" using string_view
|
||||
std::cout << object.at("the ugly"sv) << '\n';
|
||||
|
||||
|
||||
// exception type_error.304
|
||||
try
|
||||
{
|
||||
@@ -26,7 +25,7 @@ int main()
|
||||
const json str = "I am a string";
|
||||
std::cout << str.at("the good"sv) << '\n';
|
||||
}
|
||||
catch (json::type_error& e)
|
||||
catch (const json::type_error& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
@@ -37,7 +36,7 @@ int main()
|
||||
// try to read from a nonexisting key using string_view
|
||||
std::cout << object.at("the fast"sv) << '\n';
|
||||
}
|
||||
catch (json::out_of_range)
|
||||
catch (const json::out_of_range& e)
|
||||
{
|
||||
std::cout << "out of range" << '\n';
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ int main()
|
||||
// output changed array
|
||||
std::cout << object << '\n';
|
||||
|
||||
|
||||
// exception type_error.304
|
||||
try
|
||||
{
|
||||
@@ -30,7 +29,7 @@ int main()
|
||||
json str = "I am a string";
|
||||
str.at("the good") = "Another string";
|
||||
}
|
||||
catch (json::type_error& e)
|
||||
catch (const json::type_error& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
@@ -41,7 +40,7 @@ int main()
|
||||
// try to write at a nonexisting key
|
||||
object.at("the fast") = "il rapido";
|
||||
}
|
||||
catch (json::out_of_range& e)
|
||||
catch (const json::out_of_range& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ int main()
|
||||
// output element with key "the ugly"
|
||||
std::cout << object.at("the ugly") << '\n';
|
||||
|
||||
|
||||
// exception type_error.304
|
||||
try
|
||||
{
|
||||
@@ -24,7 +23,7 @@ int main()
|
||||
const json str = "I am a string";
|
||||
std::cout << str.at("the good") << '\n';
|
||||
}
|
||||
catch (json::type_error& e)
|
||||
catch (const json::type_error& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
@@ -35,7 +34,7 @@ int main()
|
||||
// try to read from a nonexisting key
|
||||
std::cout << object.at("the fast") << '\n';
|
||||
}
|
||||
catch (json::out_of_range)
|
||||
catch (const json::out_of_range)
|
||||
{
|
||||
std::cout << "out of range" << '\n';
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ int main()
|
||||
// output changed array
|
||||
std::cout << array << '\n';
|
||||
|
||||
|
||||
// exception type_error.304
|
||||
try
|
||||
{
|
||||
@@ -25,7 +24,7 @@ int main()
|
||||
json str = "I am a string";
|
||||
str.at(0) = "Another string";
|
||||
}
|
||||
catch (json::type_error& e)
|
||||
catch (const json::type_error& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
@@ -36,7 +35,7 @@ int main()
|
||||
// try to write beyond the array limit
|
||||
array.at(5) = "sixth";
|
||||
}
|
||||
catch (json::out_of_range& e)
|
||||
catch (const json::out_of_range& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ int main()
|
||||
// output element at index 2 (third element)
|
||||
std::cout << array.at(2) << '\n';
|
||||
|
||||
|
||||
// exception type_error.304
|
||||
try
|
||||
{
|
||||
@@ -19,7 +18,7 @@ int main()
|
||||
const json str = "I am a string";
|
||||
std::cout << str.at(0) << '\n';
|
||||
}
|
||||
catch (json::type_error& e)
|
||||
catch (const json::type_error& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
@@ -30,7 +29,7 @@ int main()
|
||||
// try to read beyond the array limit
|
||||
std::cout << array.at(5) << '\n';
|
||||
}
|
||||
catch (json::out_of_range& e)
|
||||
catch (const json::out_of_range& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ int main()
|
||||
json j_null;
|
||||
j_null.back();
|
||||
}
|
||||
catch (json::invalid_iterator& e)
|
||||
catch (const json::invalid_iterator& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
|
||||
@@ -55,7 +55,6 @@ int main()
|
||||
std::cout << j_mmap << '\n';
|
||||
std::cout << j_ummap << "\n\n";
|
||||
|
||||
|
||||
// ===========
|
||||
// array types
|
||||
// ===========
|
||||
@@ -117,7 +116,6 @@ int main()
|
||||
std::cout << j_mset << '\n';
|
||||
std::cout << j_umset << "\n\n";
|
||||
|
||||
|
||||
// ============
|
||||
// string types
|
||||
// ============
|
||||
@@ -138,7 +136,6 @@ int main()
|
||||
std::cout << j_string_literal << '\n';
|
||||
std::cout << j_stdstring << "\n\n";
|
||||
|
||||
|
||||
// ============
|
||||
// number types
|
||||
// ============
|
||||
@@ -203,7 +200,6 @@ int main()
|
||||
std::cout << j_float_nan << '\n';
|
||||
std::cout << j_double << "\n\n";
|
||||
|
||||
|
||||
// =============
|
||||
// boolean types
|
||||
// =============
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{"one":1,"three":3,"two":2}
|
||||
{"one":1.2,"three":3.4,"two":2.3}
|
||||
{"one":true,"three":false,"two":true}
|
||||
{"one":true,"three":true,"two":true}
|
||||
{"one":true,"three":false,"two":true}
|
||||
|
||||
["one","two",3,4.5,false]
|
||||
[1,2,3,4]
|
||||
|
||||
@@ -25,7 +25,7 @@ int main()
|
||||
{
|
||||
json j_invalid(j_number.begin() + 1, j_number.end());
|
||||
}
|
||||
catch (json::invalid_iterator& e)
|
||||
catch (const json::invalid_iterator& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ int main()
|
||||
{
|
||||
auto b_throw_on_tag = json::from_cbor(vec, true, true, json::cbor_tag_handler_t::error);
|
||||
}
|
||||
catch (json::parse_error& e)
|
||||
catch (const json::parse_error& e)
|
||||
{
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ int main()
|
||||
// try to use an array index with leading '0'
|
||||
j.contains("/array/01"_json_pointer);
|
||||
}
|
||||
catch (json::parse_error& e)
|
||||
catch (const json::parse_error& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
@@ -36,7 +36,7 @@ int main()
|
||||
// try to use an array index that is not a number
|
||||
j.contains("/array/one"_json_pointer);
|
||||
}
|
||||
catch (json::parse_error& e)
|
||||
catch (const json::parse_error& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ int main()
|
||||
{
|
||||
int housenumber = j["address"]["housenumber"];
|
||||
}
|
||||
catch (json::exception& e)
|
||||
catch (const json::exception& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ int main()
|
||||
{
|
||||
int housenumber = j["address"]["housenumber"];
|
||||
}
|
||||
catch (json::exception& e)
|
||||
catch (const json::exception& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ int main()
|
||||
{
|
||||
std::cout << j_invalid.dump() << std::endl;
|
||||
}
|
||||
catch (json::type_error& e)
|
||||
catch (const json::type_error& e)
|
||||
{
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ int main()
|
||||
{
|
||||
std::cout << j_invalid.dump() << std::endl;
|
||||
}
|
||||
catch (json::type_error& e)
|
||||
catch (const json::type_error& e)
|
||||
{
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ int main()
|
||||
json j = {{"foo", "bar"}};
|
||||
json k = j.at("non-existing");
|
||||
}
|
||||
catch (json::exception& e)
|
||||
catch (const json::exception& e)
|
||||
{
|
||||
// output exception information
|
||||
std::cout << "message: " << e.what() << '\n'
|
||||
|
||||
37
docs/examples/from_json__default_constructible.cpp
Normal file
37
docs/examples/from_json__default_constructible.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace ns
|
||||
{
|
||||
// a simple struct to model a person
|
||||
struct person
|
||||
{
|
||||
std::string name;
|
||||
std::string address;
|
||||
int age;
|
||||
};
|
||||
} // namespace ns
|
||||
|
||||
namespace ns
|
||||
{
|
||||
void from_json(const json& j, person& p)
|
||||
{
|
||||
j.at("name").get_to(p.name);
|
||||
j.at("address").get_to(p.address);
|
||||
j.at("age").get_to(p.age);
|
||||
}
|
||||
} // namespace ns
|
||||
|
||||
int main()
|
||||
{
|
||||
json j;
|
||||
j["name"] = "Ned Flanders";
|
||||
j["address"] = "744 Evergreen Terrace";
|
||||
j["age"] = 60;
|
||||
|
||||
auto p = j.template get<ns::person>();
|
||||
|
||||
std::cout << p.name << " (" << p.age << ") lives in " << p.address << std::endl;
|
||||
}
|
||||
1
docs/examples/from_json__default_constructible.output
Normal file
1
docs/examples/from_json__default_constructible.output
Normal file
@@ -0,0 +1 @@
|
||||
Ned Flanders (60) lives in 744 Evergreen Terrace
|
||||
53
docs/examples/from_json__non_default_constructible.cpp
Normal file
53
docs/examples/from_json__non_default_constructible.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace ns
|
||||
{
|
||||
// a simple struct to model a person (not default constructible)
|
||||
struct person
|
||||
{
|
||||
person(std::string n, std::string a, int aa)
|
||||
: name(std::move(n)), address(std::move(a)), age(aa)
|
||||
{}
|
||||
|
||||
std::string name;
|
||||
std::string address;
|
||||
int age;
|
||||
};
|
||||
} // namespace ns
|
||||
|
||||
namespace nlohmann
|
||||
{
|
||||
template <>
|
||||
struct adl_serializer<ns::person>
|
||||
{
|
||||
static ns::person from_json(const json& j)
|
||||
{
|
||||
return {j.at("name"), j.at("address"), j.at("age")};
|
||||
}
|
||||
|
||||
// Here's the catch! You must provide a to_json method! Otherwise, you
|
||||
// will not be able to convert person to json, since you fully
|
||||
// specialized adl_serializer on that type
|
||||
static void to_json(json& j, ns::person p)
|
||||
{
|
||||
j["name"] = p.name;
|
||||
j["address"] = p.address;
|
||||
j["age"] = p.age;
|
||||
}
|
||||
};
|
||||
} // namespace nlohmann
|
||||
|
||||
int main()
|
||||
{
|
||||
json j;
|
||||
j["name"] = "Ned Flanders";
|
||||
j["address"] = "744 Evergreen Terrace";
|
||||
j["age"] = 60;
|
||||
|
||||
auto p = j.template get<ns::person>();
|
||||
|
||||
std::cout << p.name << " (" << p.age << ") lives in " << p.address << std::endl;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Ned Flanders (60) lives in 744 Evergreen Terrace
|
||||
@@ -9,11 +9,11 @@ int main()
|
||||
json value = 17;
|
||||
|
||||
// explicitly getting pointers
|
||||
auto p1 = value.get<const json::number_integer_t*>();
|
||||
auto p2 = value.get<json::number_integer_t*>();
|
||||
auto p3 = value.get<json::number_integer_t* const>();
|
||||
auto p4 = value.get<const json::number_integer_t* const>();
|
||||
auto p5 = value.get<json::number_float_t*>();
|
||||
auto p1 = value.template get<const json::number_integer_t*>();
|
||||
auto p2 = value.template get<json::number_integer_t*>();
|
||||
auto p3 = value.template get<json::number_integer_t* const>();
|
||||
auto p4 = value.template get<const json::number_integer_t* const>();
|
||||
auto p5 = value.template get<json::number_float_t*>();
|
||||
|
||||
// print the pointees
|
||||
std::cout << *p1 << ' ' << *p2 << ' ' << *p3 << ' ' << *p4 << '\n';
|
||||
|
||||
@@ -22,14 +22,14 @@ int main()
|
||||
};
|
||||
|
||||
// use explicit conversions
|
||||
auto v1 = json_types["boolean"].get<bool>();
|
||||
auto v2 = json_types["number"]["integer"].get<int>();
|
||||
auto v3 = json_types["number"]["integer"].get<short>();
|
||||
auto v4 = json_types["number"]["floating-point"].get<float>();
|
||||
auto v5 = json_types["number"]["floating-point"].get<int>();
|
||||
auto v6 = json_types["string"].get<std::string>();
|
||||
auto v7 = json_types["array"].get<std::vector<short>>();
|
||||
auto v8 = json_types.get<std::unordered_map<std::string, json>>();
|
||||
auto v1 = json_types["boolean"].template get<bool>();
|
||||
auto v2 = json_types["number"]["integer"].template get<int>();
|
||||
auto v3 = json_types["number"]["integer"].template get<short>();
|
||||
auto v4 = json_types["number"]["floating-point"].template get<float>();
|
||||
auto v5 = json_types["number"]["floating-point"].template get<int>();
|
||||
auto v6 = json_types["string"].template get<std::string>();
|
||||
auto v7 = json_types["array"].template get<std::vector<short>>();
|
||||
auto v8 = json_types.template get<std::unordered_map<std::string, json>>();
|
||||
|
||||
// print the conversion results
|
||||
std::cout << v1 << '\n';
|
||||
|
||||
@@ -20,7 +20,7 @@ int main()
|
||||
{
|
||||
auto r3 = value.get_ref<json::number_float_t&>();
|
||||
}
|
||||
catch (json::type_error& ex)
|
||||
catch (const json::type_error& ex)
|
||||
{
|
||||
std::cout << ex.what() << '\n';
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ int main()
|
||||
std::vector<short> v7;
|
||||
std::unordered_map<std::string, json> v8;
|
||||
|
||||
|
||||
// use explicit conversions
|
||||
json_types["boolean"].get_to(v1);
|
||||
json_types["number"]["integer"].get_to(v2);
|
||||
|
||||
@@ -12,7 +12,7 @@ int main()
|
||||
json::iterator it = j.begin();
|
||||
auto k = it.key();
|
||||
}
|
||||
catch (json::invalid_iterator& e)
|
||||
catch (const json::invalid_iterator& e)
|
||||
{
|
||||
// output exception information
|
||||
std::cout << "message: " << e.what() << '\n'
|
||||
|
||||
88
docs/examples/json_base_class_t.cpp
Normal file
88
docs/examples/json_base_class_t.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
class visitor_adaptor_with_metadata
|
||||
{
|
||||
public:
|
||||
template <class Fnc>
|
||||
void visit(const Fnc& fnc) const;
|
||||
|
||||
int metadata = 42;
|
||||
private:
|
||||
template <class Ptr, class Fnc>
|
||||
void do_visit(const Ptr& ptr, const Fnc& fnc) const;
|
||||
};
|
||||
|
||||
using json = nlohmann::basic_json <
|
||||
std::map,
|
||||
std::vector,
|
||||
std::string,
|
||||
bool,
|
||||
std::int64_t,
|
||||
std::uint64_t,
|
||||
double,
|
||||
std::allocator,
|
||||
nlohmann::adl_serializer,
|
||||
std::vector<std::uint8_t>,
|
||||
visitor_adaptor_with_metadata
|
||||
>;
|
||||
|
||||
template <class Fnc>
|
||||
void visitor_adaptor_with_metadata::visit(const Fnc& fnc) const
|
||||
{
|
||||
do_visit(json::json_pointer{}, fnc);
|
||||
}
|
||||
|
||||
template <class Ptr, class Fnc>
|
||||
void visitor_adaptor_with_metadata::do_visit(const Ptr& ptr, const Fnc& fnc) const
|
||||
{
|
||||
using value_t = nlohmann::detail::value_t;
|
||||
const json& j = *static_cast<const json*>(this);
|
||||
switch (j.type())
|
||||
{
|
||||
case value_t::object:
|
||||
fnc(ptr, j);
|
||||
for (const auto& entry : j.items())
|
||||
{
|
||||
entry.value().do_visit(ptr / entry.key(), fnc);
|
||||
}
|
||||
break;
|
||||
case value_t::array:
|
||||
fnc(ptr, j);
|
||||
for (std::size_t i = 0; i < j.size(); ++i)
|
||||
{
|
||||
j.at(i).do_visit(ptr / std::to_string(i), fnc);
|
||||
}
|
||||
break;
|
||||
case value_t::null:
|
||||
case value_t::string:
|
||||
case value_t::boolean:
|
||||
case value_t::number_integer:
|
||||
case value_t::number_unsigned:
|
||||
case value_t::number_float:
|
||||
case value_t::binary:
|
||||
fnc(ptr, j);
|
||||
break;
|
||||
case value_t::discarded:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// create a json object
|
||||
json j;
|
||||
j["null"];
|
||||
j["object"]["uint"] = 1U;
|
||||
j["object"].metadata = 21;
|
||||
|
||||
// visit and output
|
||||
j.visit(
|
||||
[&](const json::json_pointer & p,
|
||||
const json & j)
|
||||
{
|
||||
std::cout << (p.empty() ? std::string{"/"} : p.to_string())
|
||||
<< " - metadata = " << j.metadata << " -> " << j.dump() << '\n';
|
||||
});
|
||||
}
|
||||
4
docs/examples/json_base_class_t.output
Normal file
4
docs/examples/json_base_class_t.output
Normal file
@@ -0,0 +1,4 @@
|
||||
/ - metadata = 42 -> {"null":null,"object":{"uint":1}}
|
||||
/null - metadata = 42 -> null
|
||||
/object - metadata = 21 -> {"uint":1}
|
||||
/object/uint - metadata = 42 -> 1
|
||||
@@ -20,7 +20,7 @@ int main()
|
||||
{
|
||||
json::json_pointer p9("foo");
|
||||
}
|
||||
catch (json::parse_error& e)
|
||||
catch (const json::parse_error& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
@@ -30,7 +30,7 @@ int main()
|
||||
{
|
||||
json::json_pointer p10("/foo/~");
|
||||
}
|
||||
catch (json::parse_error& e)
|
||||
catch (const json::parse_error& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
@@ -40,7 +40,7 @@ int main()
|
||||
{
|
||||
json::json_pointer p11("/foo/~3");
|
||||
}
|
||||
catch (json::parse_error& e)
|
||||
catch (const json::parse_error& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
|
||||
19
docs/examples/json_pointer__operator__equal.cpp
Normal file
19
docs/examples/json_pointer__operator__equal.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
int main()
|
||||
{
|
||||
// different JSON pointers
|
||||
json::json_pointer ptr0;
|
||||
json::json_pointer ptr1("");
|
||||
json::json_pointer ptr2("/foo");
|
||||
|
||||
// compare JSON pointers
|
||||
std::cout << std::boolalpha
|
||||
<< "\"" << ptr0 << "\" == \"" << ptr0 << "\": " << (ptr0 == ptr0) << '\n'
|
||||
<< "\"" << ptr0 << "\" == \"" << ptr1 << "\": " << (ptr0 == ptr1) << '\n'
|
||||
<< "\"" << ptr1 << "\" == \"" << ptr2 << "\": " << (ptr1 == ptr2) << '\n'
|
||||
<< "\"" << ptr2 << "\" == \"" << ptr2 << "\": " << (ptr2 == ptr2) << std::endl;
|
||||
}
|
||||
4
docs/examples/json_pointer__operator__equal.output
Normal file
4
docs/examples/json_pointer__operator__equal.output
Normal file
@@ -0,0 +1,4 @@
|
||||
"" == "": true
|
||||
"" == "": true
|
||||
"" == "/foo": false
|
||||
"/foo" == "/foo": true
|
||||
33
docs/examples/json_pointer__operator__equal_stringtype.cpp
Normal file
33
docs/examples/json_pointer__operator__equal_stringtype.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
int main()
|
||||
{
|
||||
// different JSON pointers
|
||||
json::json_pointer ptr0;
|
||||
json::json_pointer ptr1("");
|
||||
json::json_pointer ptr2("/foo");
|
||||
|
||||
// different strings
|
||||
std::string str0("");
|
||||
std::string str1("/foo");
|
||||
std::string str2("bar");
|
||||
|
||||
// compare JSON pointers and strings
|
||||
std::cout << std::boolalpha
|
||||
<< "\"" << ptr0 << "\" == \"" << str0 << "\": " << (ptr0 == str0) << '\n'
|
||||
<< "\"" << str0 << "\" == \"" << ptr1 << "\": " << (str0 == ptr1) << '\n'
|
||||
<< "\"" << ptr2 << "\" == \"" << str1 << "\": " << (ptr2 == str1) << std::endl;
|
||||
|
||||
try
|
||||
{
|
||||
std::cout << "\"" << str2 << "\" == \"" << ptr2 << "\": " << (str2 == ptr2) << std::endl;
|
||||
}
|
||||
catch (const json::parse_error& ex)
|
||||
{
|
||||
std::cout << ex.what() << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
"" == "": true
|
||||
"" == "": true
|
||||
"/foo" == "/foo": true
|
||||
"bar" == "/foo": [json.exception.parse_error.107] parse error at byte 1: JSON pointer must be empty or begin with '/' - was: 'bar'
|
||||
19
docs/examples/json_pointer__operator__notequal.cpp
Normal file
19
docs/examples/json_pointer__operator__notequal.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
int main()
|
||||
{
|
||||
// different JSON pointers
|
||||
json::json_pointer ptr0;
|
||||
json::json_pointer ptr1("");
|
||||
json::json_pointer ptr2("/foo");
|
||||
|
||||
// compare JSON pointers
|
||||
std::cout << std::boolalpha
|
||||
<< "\"" << ptr0 << "\" != \"" << ptr0 << "\": " << (ptr0 != ptr0) << '\n'
|
||||
<< "\"" << ptr0 << "\" != \"" << ptr1 << "\": " << (ptr0 != ptr1) << '\n'
|
||||
<< "\"" << ptr1 << "\" != \"" << ptr2 << "\": " << (ptr1 != ptr2) << '\n'
|
||||
<< "\"" << ptr2 << "\" != \"" << ptr2 << "\": " << (ptr2 != ptr2) << std::endl;
|
||||
}
|
||||
4
docs/examples/json_pointer__operator__notequal.output
Normal file
4
docs/examples/json_pointer__operator__notequal.output
Normal file
@@ -0,0 +1,4 @@
|
||||
"" != "": false
|
||||
"" != "": false
|
||||
"" != "/foo": true
|
||||
"/foo" != "/foo": false
|
||||
@@ -0,0 +1,32 @@
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
int main()
|
||||
{
|
||||
// different JSON pointers
|
||||
json::json_pointer ptr0;
|
||||
json::json_pointer ptr1("");
|
||||
json::json_pointer ptr2("/foo");
|
||||
|
||||
// different strings
|
||||
std::string str0("");
|
||||
std::string str1("/foo");
|
||||
std::string str2("bar");
|
||||
|
||||
// compare JSON pointers and strings
|
||||
std::cout << std::boolalpha
|
||||
<< "\"" << ptr0 << "\" != \"" << str0 << "\": " << (ptr0 != str0) << '\n'
|
||||
<< "\"" << str0 << "\" != \"" << ptr1 << "\": " << (str0 != ptr1) << '\n'
|
||||
<< "\"" << ptr2 << "\" != \"" << str1 << "\": " << (ptr2 != str1) << std::endl;
|
||||
|
||||
try
|
||||
{
|
||||
std::cout << "\"" << str2 << "\" != \"" << ptr2 << "\": " << (str2 != ptr2) << std::endl;
|
||||
}
|
||||
catch (const json::parse_error& ex)
|
||||
{
|
||||
std::cout << ex.what() << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
"" != "": false
|
||||
"" != "": false
|
||||
"/foo" != "/foo": false
|
||||
"bar" != "/foo": [json.exception.parse_error.107] parse error at byte 1: JSON pointer must be empty or begin with '/' - was: 'bar'
|
||||
@@ -2,7 +2,7 @@
|
||||
"compiler": {
|
||||
"c++": "201103",
|
||||
"family": "gcc",
|
||||
"version": "11.3.0"
|
||||
"version": "12.3.0"
|
||||
},
|
||||
"copyright": "(C) 2013-2022 Niels Lohmann",
|
||||
"name": "JSON for Modern C++",
|
||||
@@ -11,7 +11,7 @@
|
||||
"version": {
|
||||
"major": 3,
|
||||
"minor": 11,
|
||||
"patch": 1,
|
||||
"string": "3.11.1"
|
||||
"patch": 3,
|
||||
"string": "3.11.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,15 +45,15 @@ int main()
|
||||
|
||||
// deserialization: json -> person
|
||||
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
||||
auto p2 = j2.get<ns::person>();
|
||||
auto p2 = j2.template get<ns::person>();
|
||||
|
||||
// incomplete deserialization:
|
||||
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
||||
try
|
||||
{
|
||||
auto p3 = j3.get<ns::person>();
|
||||
auto p3 = j3.template get<ns::person>();
|
||||
}
|
||||
catch (json::exception& e)
|
||||
catch (const json::exception& e)
|
||||
{
|
||||
std::cout << "deserialization failed: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
@@ -33,15 +33,15 @@ int main()
|
||||
|
||||
// deserialization: json -> person
|
||||
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
||||
auto p2 = j2.get<ns::person>();
|
||||
auto p2 = j2.template get<ns::person>();
|
||||
|
||||
// incomplete deserialization:
|
||||
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
||||
try
|
||||
{
|
||||
auto p3 = j3.get<ns::person>();
|
||||
auto p3 = j3.template get<ns::person>();
|
||||
}
|
||||
catch (json::exception& e)
|
||||
catch (const json::exception& e)
|
||||
{
|
||||
std::cout << "deserialization failed: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace nlohmann::literals;
|
||||
|
||||
namespace ns
|
||||
{
|
||||
class person
|
||||
{
|
||||
private:
|
||||
std::string name = "John Doe";
|
||||
std::string address = "123 Fake St";
|
||||
int age = -1;
|
||||
|
||||
public:
|
||||
// No default constructor
|
||||
person(std::string name_, std::string address_, int age_)
|
||||
: name(std::move(name_)), address(std::move(address_)), age(age_)
|
||||
{}
|
||||
|
||||
friend void to_json(nlohmann::json& nlohmann_json_j, const person& nlohmann_json_t)
|
||||
{
|
||||
nlohmann_json_j["name"] = nlohmann_json_t.name;
|
||||
nlohmann_json_j["address"] = nlohmann_json_t.address;
|
||||
nlohmann_json_j["age"] = nlohmann_json_t.age;
|
||||
}
|
||||
};
|
||||
} // namespace ns
|
||||
|
||||
int main()
|
||||
{
|
||||
ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60};
|
||||
|
||||
// serialization: person -> json
|
||||
json j = p;
|
||||
std::cout << "serialization: " << j << std::endl;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
serialization: {"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"}
|
||||
@@ -0,0 +1,33 @@
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace nlohmann::literals;
|
||||
|
||||
namespace ns
|
||||
{
|
||||
class person
|
||||
{
|
||||
private:
|
||||
std::string name = "John Doe";
|
||||
std::string address = "123 Fake St";
|
||||
int age = -1;
|
||||
|
||||
public:
|
||||
// No default constructor
|
||||
person(std::string name_, std::string address_, int age_)
|
||||
: name(std::move(name_)), address(std::move(address_)), age(age_)
|
||||
{}
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE(person, name, address, age)
|
||||
};
|
||||
} // namespace ns
|
||||
|
||||
int main()
|
||||
{
|
||||
ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60};
|
||||
|
||||
// serialization: person -> json
|
||||
json j = p;
|
||||
std::cout << "serialization: " << j << std::endl;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
serialization: {"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"}
|
||||
@@ -46,10 +46,10 @@ int main()
|
||||
|
||||
// deserialization: json -> person
|
||||
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
||||
auto p2 = j2.get<ns::person>();
|
||||
auto p2 = j2.template get<ns::person>();
|
||||
|
||||
// incomplete deserialization:
|
||||
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
||||
auto p3 = j3.get<ns::person>();
|
||||
auto p3 = j3.template get<ns::person>();
|
||||
std::cout << "roundtrip: " << json(p3) << std::endl;
|
||||
}
|
||||
|
||||
@@ -33,10 +33,10 @@ int main()
|
||||
|
||||
// deserialization: json -> person
|
||||
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
||||
auto p2 = j2.get<ns::person>();
|
||||
auto p2 = j2.template get<ns::person>();
|
||||
|
||||
// incomplete deserialization:
|
||||
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
||||
auto p3 = j3.get<ns::person>();
|
||||
auto p3 = j3.template get<ns::person>();
|
||||
std::cout << "roundtrip: " << json(p3) << std::endl;
|
||||
}
|
||||
|
||||
@@ -38,15 +38,15 @@ int main()
|
||||
|
||||
// deserialization: json -> person
|
||||
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
||||
auto p2 = j2.get<ns::person>();
|
||||
auto p2 = j2.template get<ns::person>();
|
||||
|
||||
// incomplete deserialization:
|
||||
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
||||
try
|
||||
{
|
||||
auto p3 = j3.get<ns::person>();
|
||||
auto p3 = j3.template get<ns::person>();
|
||||
}
|
||||
catch (json::exception& e)
|
||||
catch (const json::exception& e)
|
||||
{
|
||||
std::cout << "deserialization failed: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
@@ -26,15 +26,15 @@ int main()
|
||||
|
||||
// deserialization: json -> person
|
||||
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
||||
auto p2 = j2.get<ns::person>();
|
||||
auto p2 = j2.template get<ns::person>();
|
||||
|
||||
// incomplete deserialization:
|
||||
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
||||
try
|
||||
{
|
||||
auto p3 = j3.get<ns::person>();
|
||||
auto p3 = j3.template get<ns::person>();
|
||||
}
|
||||
catch (json::exception& e)
|
||||
catch (const json::exception& e)
|
||||
{
|
||||
std::cout << "deserialization failed: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace nlohmann::literals;
|
||||
|
||||
namespace ns
|
||||
{
|
||||
struct person
|
||||
{
|
||||
std::string name;
|
||||
std::string address;
|
||||
int age;
|
||||
};
|
||||
|
||||
void to_json(nlohmann::json& nlohmann_json_j, const person& nlohmann_json_t)
|
||||
{
|
||||
nlohmann_json_j["name"] = nlohmann_json_t.name;
|
||||
nlohmann_json_j["address"] = nlohmann_json_t.address;
|
||||
nlohmann_json_j["age"] = nlohmann_json_t.age;
|
||||
}
|
||||
} // namespace ns
|
||||
|
||||
int main()
|
||||
{
|
||||
ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60};
|
||||
|
||||
// serialization: person -> json
|
||||
json j = p;
|
||||
std::cout << "serialization: " << j << std::endl;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
serialization: {"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"}
|
||||
@@ -0,0 +1,26 @@
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace nlohmann::literals;
|
||||
|
||||
namespace ns
|
||||
{
|
||||
struct person
|
||||
{
|
||||
std::string name;
|
||||
std::string address;
|
||||
int age;
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(person, name, address, age)
|
||||
} // namespace ns
|
||||
|
||||
int main()
|
||||
{
|
||||
ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60};
|
||||
|
||||
// serialization: person -> json
|
||||
json j = p;
|
||||
std::cout << "serialization: " << j << std::endl;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
serialization: {"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"}
|
||||
@@ -44,10 +44,10 @@ int main()
|
||||
|
||||
// deserialization: json -> person
|
||||
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
||||
auto p2 = j2.get<ns::person>();
|
||||
auto p2 = j2.template get<ns::person>();
|
||||
|
||||
// incomplete deserialization:
|
||||
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
||||
auto p3 = j3.get<ns::person>();
|
||||
auto p3 = j3.template get<ns::person>();
|
||||
std::cout << "roundtrip: " << json(p3) << std::endl;
|
||||
}
|
||||
|
||||
@@ -31,10 +31,10 @@ int main()
|
||||
|
||||
// deserialization: json -> person
|
||||
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
||||
auto p2 = j2.get<ns::person>();
|
||||
auto p2 = j2.template get<ns::person>();
|
||||
|
||||
// incomplete deserialization:
|
||||
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
||||
auto p3 = j3.get<ns::person>();
|
||||
auto p3 = j3.template get<ns::person>();
|
||||
std::cout << "roundtrip: " << json(p3) << std::endl;
|
||||
}
|
||||
|
||||
14
docs/examples/nlohmann_json_namespace.cpp
Normal file
14
docs/examples/nlohmann_json_namespace.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
// possible use case: use NLOHMANN_JSON_NAMESPACE instead of nlohmann
|
||||
using json = NLOHMANN_JSON_NAMESPACE::json;
|
||||
|
||||
// macro needed to output the NLOHMANN_JSON_NAMESPACE as string literal
|
||||
#define Q(x) #x
|
||||
#define QUOTE(x) Q(x)
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << QUOTE(NLOHMANN_JSON_NAMESPACE) << std::endl;
|
||||
}
|
||||
1
docs/examples/nlohmann_json_namespace.output
Normal file
1
docs/examples/nlohmann_json_namespace.output
Normal file
@@ -0,0 +1 @@
|
||||
nlohmann::json_abi_v3_11_3
|
||||
33
docs/examples/nlohmann_json_namespace_begin.c++17.cpp
Normal file
33
docs/examples/nlohmann_json_namespace_begin.c++17.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <iostream>
|
||||
#include <optional>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
// partial specialization (see https://json.nlohmann.me/features/arbitrary_types/)
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
template <typename T>
|
||||
struct adl_serializer<std::optional<T>>
|
||||
{
|
||||
static void to_json(json& j, const std::optional<T>& opt)
|
||||
{
|
||||
if (opt == std::nullopt)
|
||||
{
|
||||
j = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
j = *opt;
|
||||
}
|
||||
}
|
||||
};
|
||||
NLOHMANN_JSON_NAMESPACE_END
|
||||
|
||||
int main()
|
||||
{
|
||||
std::optional<int> o1 = 1;
|
||||
std::optional<int> o2 = std::nullopt;
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE::json j;
|
||||
j.push_back(o1);
|
||||
j.push_back(o2);
|
||||
std::cout << j << std::endl;
|
||||
}
|
||||
1
docs/examples/nlohmann_json_namespace_begin.c++17.output
Normal file
1
docs/examples/nlohmann_json_namespace_begin.c++17.output
Normal file
@@ -0,0 +1 @@
|
||||
[1,null]
|
||||
13
docs/examples/nlohmann_json_namespace_no_version.cpp
Normal file
13
docs/examples/nlohmann_json_namespace_no_version.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <iostream>
|
||||
|
||||
#define NLOHMANN_JSON_NAMESPACE_NO_VERSION 1
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
// macro needed to output the NLOHMANN_JSON_NAMESPACE as string literal
|
||||
#define Q(x) #x
|
||||
#define QUOTE(x) Q(x)
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << QUOTE(NLOHMANN_JSON_NAMESPACE) << std::endl;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user