mirror of
https://github.com/nlohmann/json.git
synced 2026-02-17 09:03:58 +00:00
Compare commits
124 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 |
@@ -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.
|
||||
|
||||
|
||||
8
.github/CONTRIBUTING.md
vendored
8
.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,7 +20,7 @@ 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 template ([bug report](https://github.com/nlohmann/json/blob/develop/.github/ISSUE_TEMPLATE/bug.yml) if possible. For questions, feature or support requests, please [open a discussion](https://github.com/nlohmann/json/discussions/new).
|
||||
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
|
||||
|
||||
@@ -32,7 +30,7 @@ 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` and `single_include/nlohmann/json_fwd.hpp`.
|
||||
|
||||
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.
|
||||
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.2). 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.
|
||||
|
||||
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -14,6 +14,6 @@ Read the [Contribution Guidelines](https://github.com/nlohmann/json/blob/develop
|
||||
## 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**.
|
||||
|
||||
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
|
||||
11
.github/workflows/codeql-analysis.yml
vendored
11
.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,14 +22,18 @@ jobs:
|
||||
CodeQL-Build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
security-events: write
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v2
|
||||
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)
|
||||
|
||||
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).'
|
||||
: '')
|
||||
})
|
||||
2
.github/workflows/labeler.yml
vendored
2
.github/workflows/labeler.yml
vendored
@@ -4,6 +4,8 @@ on:
|
||||
pull_request_target:
|
||||
types: [opened, synchronize]
|
||||
|
||||
permissions: {}
|
||||
|
||||
jobs:
|
||||
label:
|
||||
permissions:
|
||||
|
||||
78
.github/workflows/macos.yml
vendored
78
.github/workflows/macos.yml
vendored
@@ -9,21 +9,60 @@ 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-11
|
||||
# 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: ['11.7', '12.4', '12.5.1', '13.0']
|
||||
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
|
||||
- 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
|
||||
@@ -31,16 +70,33 @@ jobs:
|
||||
- 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.1', '13.2.1', '13.3.1', '13.4.1']
|
||||
xcode: ['15.3', '15.4']
|
||||
env:
|
||||
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- 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-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
|
||||
@@ -52,12 +108,10 @@ jobs:
|
||||
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
|
||||
- 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
|
||||
|
||||
15
.github/workflows/publish_documentation.yml
vendored
15
.github/workflows/publish_documentation.yml
vendored
@@ -10,6 +10,9 @@ on:
|
||||
- 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
|
||||
@@ -20,7 +23,7 @@ jobs:
|
||||
if: github.repository == 'nlohmann/json'
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install and update PlantUML
|
||||
run: sudo apt-get update ; sudo apt-get install -y plantuml
|
||||
@@ -28,5 +31,11 @@ jobs:
|
||||
- name: Install virtual environment
|
||||
run: make install_venv -C docs/mkdocs
|
||||
|
||||
- name: Publish documentation
|
||||
run: make publish -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
|
||||
|
||||
169
.github/workflows/ubuntu.yml
vendored
169
.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,9 +19,13 @@ 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: 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
|
||||
@@ -28,7 +35,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: Build
|
||||
@@ -39,32 +46,57 @@ 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
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- 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
|
||||
- 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
|
||||
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: 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
|
||||
@@ -72,56 +104,135 @@ jobs:
|
||||
|
||||
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
|
||||
- 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
|
||||
run: cmake --build build --target ci_test_coverage
|
||||
- name: Archive coverage report
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: code-coverage-report
|
||||
path: ${{ github.workspace }}/build/html
|
||||
- name: Publish report to Coveralls
|
||||
uses: coverallsapp/github-action@master
|
||||
uses: coverallsapp/github-action@v2.3.4
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
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
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- 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
|
||||
- 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 }}
|
||||
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
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: Build
|
||||
@@ -131,7 +242,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
container: ghcr.io/nlohmann/json-ci:v2.2.0
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: Build
|
||||
@@ -142,8 +253,10 @@ jobs:
|
||||
ci_reuse_compliance:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-python@v3
|
||||
- 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: Run REUSE lint
|
||||
@@ -155,7 +268,7 @@ jobs:
|
||||
matrix:
|
||||
target: [ci_test_examples, ci_test_api_documentation]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: Build
|
||||
|
||||
51
.github/workflows/windows.yml
vendored
51
.github/workflows/windows.yml
vendored
@@ -9,44 +9,27 @@ 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 }}
|
||||
- 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
|
||||
@@ -62,7 +45,7 @@ jobs:
|
||||
architecture: [Win32, x64]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- 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'
|
||||
@@ -78,7 +61,7 @@ jobs:
|
||||
runs-on: windows-2019
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- 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
|
||||
@@ -94,7 +77,7 @@ jobs:
|
||||
architecture: [Win32, x64]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- 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'
|
||||
@@ -110,7 +93,7 @@ jobs:
|
||||
runs-on: windows-2022
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- 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
|
||||
@@ -122,10 +105,10 @@ jobs:
|
||||
runs-on: windows-2019
|
||||
strategy:
|
||||
matrix:
|
||||
version: [11, 12]
|
||||
version: [11, 12, 13, 14, 15]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- 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: Run CMake
|
||||
@@ -142,7 +125,7 @@ jobs:
|
||||
architecture: [Win32, x64]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- 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
|
||||
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -39,3 +39,6 @@
|
||||
/localhost.pem
|
||||
/localhost-key.pem
|
||||
/serve_header.yml
|
||||
|
||||
# Swift Package Manager build directory
|
||||
/.build
|
||||
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.2
|
||||
| | |__ | | | | | | 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.2
|
||||
| | |__ | | | | | | 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.2
|
||||
date-released: 2022-08-12
|
||||
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.2 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()
|
||||
|
||||
@@ -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
|
||||
|
||||
12
Makefile
12
Makefile
@@ -156,7 +156,7 @@ pretty:
|
||||
--pad-header \
|
||||
--align-pointer=type \
|
||||
--align-reference=type \
|
||||
--add-brackets \
|
||||
--add-braces \
|
||||
--convert-tabs \
|
||||
--close-templates \
|
||||
--lineend=linux \
|
||||
@@ -192,6 +192,8 @@ check-amalgamation:
|
||||
@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
|
||||
@@ -223,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
|
||||
@@ -277,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
|
||||
)
|
||||
211
README.md
211
README.md
@@ -7,12 +7,13 @@
|
||||
[](https://coveralls.io/github/nlohmann/json?branch=develop)
|
||||
[](https://scan.coverity.com/projects/nlohmann-json)
|
||||
[](https://www.codacy.com/gh/nlohmann/json/dashboard?utm_source=github.com&utm_medium=referral&utm_content=nlohmann/json&utm_campaign=Badge_Grade)
|
||||
[](https://lgtm.com/projects/g/nlohmann/json/context:cpp)
|
||||
[](https://cirrus-ci.com/github/nlohmann/json)
|
||||
[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:json)
|
||||
[](https://wandbox.org/permlink/1mp10JbaANo6FUc7)
|
||||
[](https://json.nlohmann.me)
|
||||
[](https://raw.githubusercontent.com/nlohmann/json/master/LICENSE.MIT)
|
||||
[](https://github.com/nlohmann/json/releases)
|
||||
[](https://vcpkg.link/ports/nlohmann-json)
|
||||
[](https://repology.org/project/nlohmann-json/versions)
|
||||
[](https://github.com/nlohmann/json/releases)
|
||||
[](https://github.com/nlohmann/json/issues)
|
||||
@@ -51,6 +52,7 @@
|
||||
- [Notes](#notes)
|
||||
- [Execute unit tests](#execute-unit-tests)
|
||||
|
||||
|
||||
## Design goals
|
||||
|
||||
There are myriads of [JSON](https://json.org) libraries out there, and each may even have its reason to exist. Our class had these design goals:
|
||||
@@ -74,9 +76,10 @@ See the [contribution guidelines](https://github.com/nlohmann/json/blob/master/.
|
||||
|
||||
You can sponsor this library at [GitHub Sponsors](https://github.com/sponsors/nlohmann).
|
||||
|
||||
### :office: Corporate Sponsor
|
||||
### :raising_hand: Priority Sponsor
|
||||
|
||||
[](https://github.com/codacy)
|
||||
- [Martti Laine](https://github.com/codeclown)
|
||||
- [Paul Harrington](https://github.com/phrrngtn)
|
||||
|
||||
### :label: Named Sponsors
|
||||
|
||||
@@ -85,9 +88,11 @@ You can sponsor this library at [GitHub Sponsors](https://github.com/sponsors/nl
|
||||
- [Steve Sperandeo](https://github.com/homer6)
|
||||
- [Robert Jefe Lindstädt](https://github.com/eljefedelrodeodeljefe)
|
||||
- [Steve Wagner](https://github.com/ciroque)
|
||||
- [Lion Yang](https://github.com/LionNatsu)
|
||||
|
||||
Thanks everyone!
|
||||
|
||||
|
||||
## Support
|
||||
|
||||
:question: If you have a **question**, please check if it is already answered in the [**FAQ**](https://json.nlohmann.me/home/faq/) or the [**Q&A**](https://github.com/nlohmann/json/discussions/categories/q-a) section. If not, please [**ask a new question**](https://github.com/nlohmann/json/discussions/new) there.
|
||||
@@ -100,6 +105,7 @@ Thanks everyone!
|
||||
|
||||
There is also a [**docset**](https://github.com/Kapeli/Dash-User-Contributions/tree/master/docsets/JSON_for_Modern_C%2B%2B) for the documentation browsers [Dash](https://kapeli.com/dash), [Velocity](https://velocity.silverlakesoftware.com), and [Zeal](https://zealdocs.org) that contains the full [documentation](https://json.nlohmann.me) as offline resource.
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
Here are some examples to give you an idea how to use the class.
|
||||
@@ -268,7 +274,7 @@ Note that without appending the `_json` suffix, the passed string literal is not
|
||||
value. That is, `json j = "{ \"happy\": true, \"pi\": 3.141 }"` would just store the string
|
||||
`"{ "happy": true, "pi": 3.141 }"` rather than parsing the actual object.
|
||||
|
||||
The string literal should be brought into scope with with `using namespace nlohmann::literals;`
|
||||
The string literal should be brought into scope with `using namespace nlohmann::literals;`
|
||||
(see [`json::parse()`](https://json.nlohmann.me/api/operator_literal_json/)).
|
||||
|
||||
The above example can also be expressed explicitly using [`json::parse()`](https://json.nlohmann.me/api/basic_json/parse/):
|
||||
@@ -300,7 +306,7 @@ Note the difference between serialization and assignment:
|
||||
json j_string = "this is a string";
|
||||
|
||||
// retrieve the string value
|
||||
auto cpp_string = j_string.get<std::string>();
|
||||
auto cpp_string = j_string.template get<std::string>();
|
||||
// retrieve the string value (alternative when a variable already exists)
|
||||
std::string cpp_string2;
|
||||
j_string.get_to(cpp_string2);
|
||||
@@ -309,7 +315,7 @@ j_string.get_to(cpp_string2);
|
||||
std::string serialized_string = j_string.dump();
|
||||
|
||||
// output of original string
|
||||
std::cout << cpp_string << " == " << cpp_string2 << " == " << j_string.get<std::string>() << '\n';
|
||||
std::cout << cpp_string << " == " << cpp_string2 << " == " << j_string.template get<std::string>() << '\n';
|
||||
// output of serialized value
|
||||
std::cout << j_string << " == " << serialized_string << std::endl;
|
||||
```
|
||||
@@ -383,7 +389,7 @@ struct MyIterator {
|
||||
using iterator_category = std::input_iterator_tag;
|
||||
|
||||
MyIterator& operator++() {
|
||||
MyContainer.advance();
|
||||
target->advance();
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -392,7 +398,7 @@ struct MyIterator {
|
||||
}
|
||||
|
||||
reference operator*() const {
|
||||
return target.get_current();
|
||||
return target->get_current();
|
||||
}
|
||||
|
||||
MyContainer* target = nullptr;
|
||||
@@ -482,7 +488,7 @@ for (auto& element : j) {
|
||||
}
|
||||
|
||||
// getter/setter
|
||||
const auto tmp = j[0].get<std::string>();
|
||||
const auto tmp = j[0].template get<std::string>();
|
||||
j[1] = 42;
|
||||
bool foo = j.at(2);
|
||||
|
||||
@@ -690,7 +696,7 @@ You can switch off implicit conversions by defining `JSON_USE_IMPLICIT_CONVERSIO
|
||||
// strings
|
||||
std::string s1 = "Hello, world!";
|
||||
json js = s1;
|
||||
auto s2 = js.get<std::string>();
|
||||
auto s2 = js.template get<std::string>();
|
||||
// NOT RECOMMENDED
|
||||
std::string s3 = js;
|
||||
std::string s4;
|
||||
@@ -699,7 +705,7 @@ s4 = js;
|
||||
// Booleans
|
||||
bool b1 = true;
|
||||
json jb = b1;
|
||||
auto b2 = jb.get<bool>();
|
||||
auto b2 = jb.template get<bool>();
|
||||
// NOT RECOMMENDED
|
||||
bool b3 = jb;
|
||||
bool b4;
|
||||
@@ -708,7 +714,7 @@ b4 = jb;
|
||||
// numbers
|
||||
int i = 42;
|
||||
json jn = i;
|
||||
auto f = jn.get<double>();
|
||||
auto f = jn.template get<double>();
|
||||
// NOT RECOMMENDED
|
||||
double f2 = jb;
|
||||
double f3;
|
||||
@@ -751,9 +757,9 @@ j["age"] = p.age;
|
||||
|
||||
// convert from JSON: copy each value from the JSON object
|
||||
ns::person p {
|
||||
j["name"].get<std::string>(),
|
||||
j["address"].get<std::string>(),
|
||||
j["age"].get<int>()
|
||||
j["name"].template get<std::string>(),
|
||||
j["address"].template get<std::string>(),
|
||||
j["age"].template get<int>()
|
||||
};
|
||||
```
|
||||
|
||||
@@ -770,7 +776,7 @@ std::cout << j << std::endl;
|
||||
// {"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"}
|
||||
|
||||
// conversion: json -> person
|
||||
auto p2 = j.get<ns::person>();
|
||||
auto p2 = j.template get<ns::person>();
|
||||
|
||||
// that's it
|
||||
assert(p == p2);
|
||||
@@ -797,13 +803,13 @@ namespace ns {
|
||||
```
|
||||
|
||||
That's all! When calling the `json` constructor with your type, your custom `to_json` method will be automatically called.
|
||||
Likewise, when calling `get<your_type>()` or `get_to(your_type&)`, the `from_json` method will be called.
|
||||
Likewise, when calling `template get<your_type>()` or `get_to(your_type&)`, the `from_json` method will be called.
|
||||
|
||||
Some important things:
|
||||
|
||||
* Those methods **MUST** be in your type's namespace (which can be the global namespace), or the library will not be able to locate them (in this example, they are in namespace `ns`, where `person` is defined).
|
||||
* Those methods **MUST** be available (e.g., proper headers must be included) everywhere you use these conversions. Look at [issue 1108](https://github.com/nlohmann/json/issues/1108) for errors that may occur otherwise.
|
||||
* When using `get<your_type>()`, `your_type` **MUST** be [DefaultConstructible](https://en.cppreference.com/w/cpp/named_req/DefaultConstructible). (There is a way to bypass this requirement described later.)
|
||||
* When using `template get<your_type>()`, `your_type` **MUST** be [DefaultConstructible](https://en.cppreference.com/w/cpp/named_req/DefaultConstructible). (There is a way to bypass this requirement described later.)
|
||||
* In function `from_json`, use function [`at()`](https://json.nlohmann.me/api/basic_json/at/) to access the object values rather than `operator[]`. In case a key does not exist, `at` throws an exception that you can handle, whereas `operator[]` exhibits undefined behavior.
|
||||
* You do not need to add serializers or deserializers for STL types like `std::vector`: the library already implements these.
|
||||
|
||||
@@ -888,8 +894,8 @@ namespace nlohmann {
|
||||
if (j.is_null()) {
|
||||
opt = boost::none;
|
||||
} else {
|
||||
opt = j.get<T>(); // same as above, but with
|
||||
// adl_serializer<T>::from_json
|
||||
opt = j.template get<T>(); // same as above, but with
|
||||
// adl_serializer<T>::from_json
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -916,7 +922,7 @@ namespace nlohmann {
|
||||
// note: the return type is no longer 'void', and the method only takes
|
||||
// one argument
|
||||
static move_only_type from_json(const json& j) {
|
||||
return {j.get<int>()};
|
||||
return {j.template get<int>()};
|
||||
}
|
||||
|
||||
// Here's the catch! You must provide a to_json method! Otherwise, you
|
||||
@@ -1020,11 +1026,11 @@ assert(j == "stopped");
|
||||
|
||||
// json string to enum
|
||||
json j3 = "running";
|
||||
assert(j3.get<TaskState>() == TS_RUNNING);
|
||||
assert(j3.template get<TaskState>() == TS_RUNNING);
|
||||
|
||||
// undefined json value to enum (where the first map entry above is the default)
|
||||
json jPi = 3.14;
|
||||
assert(jPi.get<TaskState>() == TS_INVALID );
|
||||
assert(jPi.template get<TaskState>() == TS_INVALID );
|
||||
```
|
||||
|
||||
Just as in [Arbitrary Type Conversions](#arbitrary-types-conversions) above,
|
||||
@@ -1032,7 +1038,7 @@ Just as in [Arbitrary Type Conversions](#arbitrary-types-conversions) above,
|
||||
- It MUST be available (e.g., proper headers must be included) everywhere you use the conversions.
|
||||
|
||||
Other Important points:
|
||||
- When using `get<ENUM_TYPE>()`, undefined JSON values will default to the first pair specified in your map. Select this default pair carefully.
|
||||
- When using `template get<ENUM_TYPE>()`, undefined JSON values will default to the first pair specified in your map. Select this default pair carefully.
|
||||
- If an enum or JSON value is specified more than once in your map, the first matching occurrence from the top of the map will be returned when converting to or from JSON.
|
||||
|
||||
### Binary formats (BSON, CBOR, MessagePack, UBJSON, and BJData)
|
||||
@@ -1109,11 +1115,11 @@ auto cbor = json::to_msgpack(j); // 0xD5 (fixext2), 0x10, 0xCA, 0xFE
|
||||
|
||||
## Supported compilers
|
||||
|
||||
Though it's 2022 already, the support for C++11 is still a bit sparse. Currently, the following compilers are known to work:
|
||||
Though it's 2024 already, the support for C++11 is still a bit sparse. Currently, the following compilers are known to work:
|
||||
|
||||
- GCC 4.8 - 12.0 (and possibly later)
|
||||
- Clang 3.4 - 15.0 (and possibly later)
|
||||
- Apple Clang 9.1 - 13.1 (and possibly later)
|
||||
- GCC 4.8 - 14.2 (and possibly later)
|
||||
- Clang 3.4 - 20.0 (and possibly later)
|
||||
- Apple Clang 9.1 - 16.1 (and possibly later)
|
||||
- Intel C++ Compiler 17.0.2 (and possibly later)
|
||||
- Nvidia CUDA Compiler 11.0.221 (and possibly later)
|
||||
- Microsoft Visual C++ 2015 / Build Tools 14.0.25123.0 (and possibly later)
|
||||
@@ -1140,51 +1146,68 @@ Please note:
|
||||
|
||||
- Unsupported versions of GCC and Clang are rejected by `#error` directives. This can be switched off by defining `JSON_SKIP_UNSUPPORTED_COMPILER_CHECK`. Note that you can expect no support in this case.
|
||||
|
||||
The following compilers are currently used in continuous integration at [AppVeyor](https://ci.appveyor.com/project/nlohmann/json), [Drone CI](https://cloud.drone.io/nlohmann/json), and [GitHub Actions](https://github.com/nlohmann/json/actions):
|
||||
The following compilers are currently used in continuous integration at [AppVeyor](https://ci.appveyor.com/project/nlohmann/json), [Cirrus CI](https://cirrus-ci.com/github/nlohmann/json), and [GitHub Actions](https://github.com/nlohmann/json/actions):
|
||||
|
||||
| Compiler | Operating System | CI Provider |
|
||||
|--------------------------------------------------------------------------------------------------------|--------------------|----------------|
|
||||
| Apple Clang 11.0.3 (clang-1103.0.32.62); Xcode 11.7 | macOS 11.6.8 | GitHub Actions |
|
||||
| Apple Clang 12.0.0 (clang-1200.0.32.29); Xcode 12.4 | macOS 11.6.8 | GitHub Actions |
|
||||
| Apple Clang 12.0.5 (clang-1205.0.22.11); Xcode 12.5.1 | macOS 11.6.8 | GitHub Actions |
|
||||
| Apple Clang 13.0.0 (clang-1300.0.29.3); Xcode 13.0 | macOS 11.6.8 | GitHub Actions |
|
||||
| Apple Clang 13.0.0 (clang-1300.0.29.3); Xcode 13.1 | macOS 12.4 | GitHub Actions |
|
||||
| Apple Clang 13.0.0 (clang-1300.0.29.30); Xcode 13.2.1 | macOS 12.4 | GitHub Actions |
|
||||
| Apple Clang 13.1.6 (clang-1316.0.21.2.3); Xcode 13.3.1 | macOS 12.4 | GitHub Actions |
|
||||
| Apple Clang 13.1.6 (clang-1316.0.21.2.5); Xcode 13.4.1 | macOS 12.4 | GitHub Actions |
|
||||
| Clang 3.5.2 (3.5.2-3ubuntu1) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| Clang 3.6.2 (3.6.2-3ubuntu2) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| Clang 3.7.1 (3.7.1-2ubuntu2) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| Clang 3.8.0 (3.8.0-2ubuntu4) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| Clang 3.9.1 (3.9.1-4ubuntu3\~16.04.2) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| Clang 4.0.0 (4.0.0-1ubuntu1\~16.04.2) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| Clang 5.0.0 (5.0.0-3\~16.04.1) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| Clang 6.0.1 (6.0.1-14) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| Clang 7.0.1 (7.0.1-12) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| Clang 8.0.1 (8.0.1-9) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| Clang 9.0.1 (9.0.1-12) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| Clang 10.0.0 (10.0.0-4ubuntu1) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| Apple Clang 14.0.0 (clang-1400.0.29.202); Xcode 14.1 | macOS 13.7 | GitHub Actions |
|
||||
| Apple Clang 14.0.0 (clang-1400.0.29.202); Xcode 14.2 | macOS 13.7 | GitHub Actions |
|
||||
| Apple Clang 14.0.3 (clang-1403.0.22.14.1); Xcode 14.3 | macOS 13.7 | GitHub Actions |
|
||||
| Apple Clang 14.0.3 (clang-1403.0.22.14.1); Xcode 14.3.1 | macOS 13.7.1 | GitHub Actions |
|
||||
| Apple Clang 15.0.0 (clang-1500.0.40.1); Xcode 15.0.1 | macOS 13.7 | GitHub Actions |
|
||||
| Apple Clang 15.0.0 (clang-1500.1.0.2.5); Xcode 15.1 | macOS 13.7 | GitHub Actions |
|
||||
| Apple Clang 15.0.0 (clang-1500.1.0.2.5); Xcode 15.2 | macOS 13.7 | GitHub Actions |
|
||||
| Apple Clang 15.0.0 (clang-1500.3.9.4); Xcode 15.3 | macOS 14.7 | GitHub Actions |
|
||||
| Apple Clang 15.0.0 (clang-1500.3.9.4); Xcode 15.4 | macOS 14.7 | GitHub Actions |
|
||||
| Apple Clang 16.0.0 (clang-1600.0.26.3); Xcode 16.0 | macOS 15.0.1 | GitHub Actions |
|
||||
| Apple Clang 16.0.0 (clang-1600.0.26.4); Xcode 16.1 | macOS 15.0.1 | GitHub Actions |
|
||||
| Clang 3.5.2 | Ubuntu 22.04.1 LTS | GitHub Actions |
|
||||
| Clang 3.6.2 | Ubuntu 22.04.1 LTS | GitHub Actions |
|
||||
| Clang 3.7.1 | Ubuntu 22.04.1 LTS | GitHub Actions |
|
||||
| Clang 3.8.1 | Ubuntu 22.04.1 LTS | GitHub Actions |
|
||||
| Clang 3.9.1 | Ubuntu 22.04.1 LTS | GitHub Actions |
|
||||
| Clang 4.0.1 | Ubuntu 22.04.1 LTS | GitHub Actions |
|
||||
| Clang 5.0.2 | Ubuntu 22.04.1 LTS | GitHub Actions |
|
||||
| Clang 6.0.1 | Ubuntu 22.04.1 LTS | GitHub Actions |
|
||||
| Clang 7.0.1 | Ubuntu 22.04.1 LTS | GitHub Actions |
|
||||
| Clang 8.0.0 | Ubuntu 22.04.1 LTS | GitHub Actions |
|
||||
| Clang 9.0.0 | Ubuntu 22.04.1 LTS | GitHub Actions |
|
||||
| Clang 10.0.0 | Ubuntu 22.04.1 LTS | GitHub Actions |
|
||||
| Clang 10.0.0 with GNU-like command-line | Windows-10.0.17763 | GitHub Actions |
|
||||
| Clang 11.0.0 with GNU-like command-line | Windows-10.0.17763 | GitHub Actions |
|
||||
| Clang 11.0.0 with MSVC-like command-line | Windows-10.0.17763 | GitHub Actions |
|
||||
| Clang 11.0.0 (11.0.0-2~ubuntu20.04.1) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| Clang 12.0.0 (12.0.0-3ubuntu1~20.04.3) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| Clang 13.0.1 (13.0.1-++20211015123032+cf15ccdeb6d5-1exp120211015003613.5) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| Clang 14.0.5-++20220603124341+2f0a69c32a4c-1~exp1~20220603124352.149 | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| Clang 15.0.0 (15.0.0-++20220530052901+b7d2b160c3ba-1~exp1~20220530172952.268) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| GCC 4.8.5 (Ubuntu 4.8.5-4ubuntu2) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| GCC 4.9.3 (Ubuntu 4.9.3-13ubuntu2) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| GCC 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.12) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| GCC 6.4.0 (Ubuntu 6.4.0-17ubuntu1) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| GCC 7.5.0 (Ubuntu 7.5.0-6ubuntu2) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| Clang 11.0.0 | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| Clang 12.0.0 | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| Clang 12.0.0 with GNU-like command-line | Windows-10.0.17763 | GitHub Actions |
|
||||
| Clang 13.0.0 | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| Clang 13.0.0 with GNU-like command-line | Windows-10.0.17763 | GitHub Actions |
|
||||
| Clang 14.0.0 | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| Clang 14.0.0 with GNU-like command-line | Windows-10.0.17763 | GitHub Actions |
|
||||
| Clang 15.0.0 with GNU-like command-line | Windows-10.0.17763 | GitHub Actions |
|
||||
| Clang 15.0.4 | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| Clang 16.0.0 (16.0.0-++20221031071727+500876226c60-1~exp1~20221031071831.439) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| Clang 16.0.6 (++20231112084702+7cbf1a259152-1~exp1~20231112084757.16) | Ubuntu 20.04.1 LTS | GitHub Actions |
|
||||
| Clang 17.0.6 (++20231208085813+6009708b4367-1~exp1~20231208085906.81) | Ubuntu 20.04.1 LTS | GitHub Actions |
|
||||
| Clang 18.1.8 (++20240731024826+3b5b5c1ec4a3-1~exp1~20240731144843.145) | Ubuntu 20.04.1 LTS | GitHub Actions |
|
||||
| Clang 19.1.2 (++20241016063422+7ba7d8e2f7b6-1~exp1~20241016063541.55) | Ubuntu 20.04.1 LTS | GitHub Actions |
|
||||
| Clang 20.0.0 (++20241022113049+f1ade1f874db-1~exp1~20241022113104.1036) | Ubuntu 22.04.1 LTS | GitHub Actions |
|
||||
| GCC 4.8.5 (Ubuntu 4.8.5-4ubuntu8) | Ubuntu 20.04.4 LTS | GitHub Actions |
|
||||
| GCC 4.9.3 (Ubuntu 4.9.3-13ubuntu2) | Ubuntu 20.04.4 LTS | GitHub Actions |
|
||||
| GCC 4.8.5 (Ubuntu 4.8.5-4ubuntu2) | Ubuntu 20.04.4 LTS | GitHub Actions |
|
||||
| GCC 5.5.0 (Ubuntu 5.5.0-12ubuntu1) | Ubuntu 20.04.4 LTS | GitHub Actions |
|
||||
| GCC 6.4.0 (Ubuntu 6.4.0-17ubuntu1) | Ubuntu 20.04.4 LTS | GitHub Actions |
|
||||
| GCC 7.5.0 | Ubuntu 22.04.1 LTS | GitHub Actions |
|
||||
| GCC 8.1.0 (i686-posix-dwarf-rev0, Built by MinGW-W64 project) | Windows-10.0.17763 | GitHub Actions |
|
||||
| GCC 8.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project) | Windows-10.0.17763 | GitHub Actions |
|
||||
| GCC 8.4.0 (Ubuntu 8.4.0-3ubuntu2) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| GCC 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| GCC 10.2.0 (Ubuntu 10.2.0-5ubuntu1~20.04) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| GCC 11.1.0 | Ubuntu (aarch64) | Drone CI |
|
||||
| GCC 11.1.0 (Ubuntu 11.1.0-1ubuntu1~20.04) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| GCC 13.0.0 13.0.0 20220605 (experimental) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| GCC 8.5.0 | Ubuntu 22.04.1 LTS | GitHub Actions |
|
||||
| GCC 9.5.0 | Ubuntu 22.04.1 LTS | GitHub Actions |
|
||||
| GCC 10.5.0 | Ubuntu 22.04.1 LTS | GitHub Actions |
|
||||
| GCC 11.1.0 | Ubuntu (aarch64) | Cirrus CI |
|
||||
| GCC 11.5.0 | Ubuntu 22.04.1 LTS | GitHub Actions |
|
||||
| GCC 12.4.0 | Ubuntu 22.04.1 LTS | GitHub Actions |
|
||||
| GCC 13.0.0 20220605 (experimental) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| GCC 13.3.0 | Ubuntu 22.04.1 LTS | GitHub Actions |
|
||||
| GCC 14.2.0 | Ubuntu 22.04.1 LTS | GitHub Actions |
|
||||
| Intel C++ Compiler 2021.5.0.20211109 | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| NVCC 11.0.221 | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||
| Visual Studio 14 2015 MSVC 19.0.24241.7 (Build Engine version 14.0.25420.1) | Windows-6.3.9600 | AppVeyor |
|
||||
@@ -1262,7 +1285,7 @@ Example:
|
||||
```cmake
|
||||
include(FetchContent)
|
||||
|
||||
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz)
|
||||
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz)
|
||||
FetchContent_MakeAvailable(json)
|
||||
|
||||
target_link_libraries(foo PRIVATE nlohmann_json::nlohmann_json)
|
||||
@@ -1309,7 +1332,9 @@ endif()
|
||||
|
||||
If you are using the [Meson Build System](https://mesonbuild.com), add this source tree as a [meson subproject](https://mesonbuild.com/Subprojects.html#using-a-subproject). You may also use the `include.zip` published in this project's [Releases](https://github.com/nlohmann/json/releases) to reduce the size of the vendored source tree. Alternatively, you can get a wrap file by downloading it from [Meson WrapDB](https://wrapdb.mesonbuild.com/nlohmann_json), or simply use `meson wrap install nlohmann_json`. Please see the meson project for any issues regarding the packaging.
|
||||
|
||||
The provided `meson.build` can also be used as an alternative to cmake for installing `nlohmann_json` system-wide in which case a pkg-config file is installed. To use it, simply have your build system require the `nlohmann_json` pkg-config dependency. In Meson, it is preferred to use the [`dependency()`](https://mesonbuild.com/Reference-manual.html#dependency) object with a subproject fallback, rather than using the subproject directly.
|
||||
The provided `meson.build` can also be used as an alternative to CMake for installing `nlohmann_json` system-wide in which case a pkg-config file is installed. To use it, simply have your build system require the `nlohmann_json` pkg-config dependency. In Meson, it is preferred to use the [`dependency()`](https://mesonbuild.com/Reference-manual.html#dependency) object with a subproject fallback, rather than using the subproject directly.
|
||||
|
||||
If you are using [Bazel](https://bazel.build/) you can simply reference this repository using `http_archive` or `git_repository` and depend on `@nlohmann_json//:json`.
|
||||
|
||||
If you are using [Conan](https://www.conan.io/) to manage your dependencies, merely add [`nlohmann_json/x.y.z`](https://conan.io/center/nlohmann_json) to your `conanfile`'s requires, where `x.y.z` is the release version you want to use. Please file issues [here](https://github.com/conan-io/conan-center-index/issues) if you experience problems with the packages.
|
||||
|
||||
@@ -1325,6 +1350,8 @@ If you are using [cget](https://cget.readthedocs.io/en/latest/), you can install
|
||||
|
||||
If you are using [CocoaPods](https://cocoapods.org), you can use the library by adding pod `"nlohmann_json", '~>3.1.2'` to your podfile (see [an example](https://bitbucket.org/benman/nlohmann_json-cocoapod/src/master/)). Please file issues [here](https://bitbucket.org/benman/nlohmann_json-cocoapod/issues?status=new&status=open).
|
||||
|
||||
If you are using [Swift Package Manager](https://swift.org/package-manager/), you can use the library by adding a package dependency to this repository. And target dependency as `.product(name: "nlohmann-json", package: "json")`.
|
||||
|
||||
If you are using [NuGet](https://www.nuget.org), you can use the package [nlohmann.json](https://www.nuget.org/packages/nlohmann.json/). Please check [this extensive description](https://github.com/nlohmann/json/issues/1132#issuecomment-452250255) on how to use the package. Please file issues [here](https://github.com/hnkb/nlohmann-json-nuget/issues).
|
||||
|
||||
If you are using [conda](https://conda.io/), you can use the package [nlohmann_json](https://github.com/conda-forge/nlohmann_json-feedstock) from [conda-forge](https://conda-forge.org) executing `conda install -c conda-forge nlohmann_json`. Please file issues [here](https://github.com/conda-forge/nlohmann_json-feedstock/issues).
|
||||
@@ -1364,11 +1391,11 @@ json = dependency('nlohmann_json', required: true)
|
||||
|
||||
## License
|
||||
|
||||
<img align="right" src="https://opensource.org/trademarks/opensource/OSI-Approved-License-100x137.png">
|
||||
<img align="right" src="https://149753425.v2.pressablecdn.com/wp-content/uploads/2009/06/OSIApproved_100X125.png" alt="OSI approved license">
|
||||
|
||||
The class is licensed under the [MIT License](https://opensource.org/licenses/MIT):
|
||||
|
||||
Copyright © 2013-2022 [Niels Lohmann](https://nlohmann.me)
|
||||
Copyright © 2013-2024 [Niels Lohmann](https://nlohmann.me)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
@@ -1378,13 +1405,19 @@ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR I
|
||||
|
||||
* * *
|
||||
|
||||
The class contains the UTF-8 Decoder from Bjoern Hoehrmann which is licensed under the [MIT License](https://opensource.org/licenses/MIT) (see above). Copyright © 2008-2009 [Björn Hoehrmann](https://bjoern.hoehrmann.de/) <bjoern@hoehrmann.de>
|
||||
- The class contains the UTF-8 Decoder from Bjoern Hoehrmann which is licensed under the [MIT License](https://opensource.org/licenses/MIT) (see above). Copyright © 2008-2009 [Björn Hoehrmann](https://bjoern.hoehrmann.de/) <bjoern@hoehrmann.de>
|
||||
- The class contains a slightly modified version of the Grisu2 algorithm from Florian Loitsch which is licensed under the [MIT License](https://opensource.org/licenses/MIT) (see above). Copyright © 2009 [Florian Loitsch](https://florian.loitsch.com/)
|
||||
- The class contains a copy of [Hedley](https://nemequ.github.io/hedley/) from Evan Nemerson which is licensed as [CC0-1.0](https://creativecommons.org/publicdomain/zero/1.0/).
|
||||
- The class contains parts of [Google Abseil](https://github.com/abseil/abseil-cpp) which is licensed under the [Apache 2.0 License](https://opensource.org/licenses/Apache-2.0).
|
||||
|
||||
The class contains a slightly modified version of the Grisu2 algorithm from Florian Loitsch which is licensed under the [MIT License](https://opensource.org/licenses/MIT) (see above). Copyright © 2009 [Florian Loitsch](https://florian.loitsch.com/)
|
||||
<img align="right" src="https://git.fsfe.org/reuse/reuse-ci/raw/branch/master/reuse-horizontal.png" alt="REUSE Software">
|
||||
|
||||
The class contains a copy of [Hedley](https://nemequ.github.io/hedley/) from Evan Nemerson which is licensed as [CC0-1.0](https://creativecommons.org/publicdomain/zero/1.0/).
|
||||
The library is compliant to version 3.3 of the [**REUSE specification**](https://reuse.software):
|
||||
|
||||
The class contains parts of [Google Abseil](https://github.com/abseil/abseil-cpp) which is licensed under the [Apache 2.0 License](https://opensource.org/licenses/Apache-2.0).
|
||||
- Every source file contains an SPDX copyright header.
|
||||
- The full text of all licenses used in the repository can be found in the `LICENSES` folder.
|
||||
- File `.reuse/dep5` contains an overview of all files' copyrights and licenses.
|
||||
- Run `pipx run reuse lint` to verify the project's REUSE compliance and `pipx run reuse spdx` to generate a SPDX SBOM.
|
||||
|
||||
## Contact
|
||||
|
||||
@@ -1718,6 +1751,36 @@ I deeply appreciate the help of the following people.
|
||||
314. [Berkus Decker](https://github.com/berkus) fixed a typo in the README.
|
||||
315. [Illia Polishchuk](https://github.com/effolkronium) improved the CMake testing.
|
||||
316. [Ikko Ashimine](https://github.com/eltociear) fixed a typo.
|
||||
317. [Raphael Grimm](https://github.com/barcode) added the possibility to define a custom base class.
|
||||
318. [tocic](https://github.com/tocic) fixed typos in the documentation.
|
||||
319. [Vertexwahn](https://github.com/Vertexwahn) added Bazel build support.
|
||||
320. [Dirk Stolle](https://github.com/striezel) fixed typos in the documentation.
|
||||
321. [DavidKorczynski](https://github.com/DavidKorczynski) added a CIFuzz CI GitHub action.
|
||||
322. [Finkman](https://github.com/Finkman) fixed the debug pretty-printer.
|
||||
323. [Florian Segginger](https://github.com/floriansegginger) bumped the years in the README.
|
||||
324. [haadfida](https://github.com/haadfida) cleaned up the badges of used services.
|
||||
325. [Arsen Arsenović](https://github.com/ArsenArsen) fixed a build error.
|
||||
326. [theevilone45](https://github.com/theevilone45) fixed a typo in a CMake file.
|
||||
327. [Sergei Trofimovich](https://github.com/trofi) fixed the custom allocator support.
|
||||
328. [Joyce](https://github.com/joycebrum) fixed some security issues in the GitHub workflows.
|
||||
329. [Nicolas Jakob](https://github.com/njakob) add vcpkg version badge.
|
||||
330. [Tomerkm](https://github.com/Tomerkm) added tests.
|
||||
331. [No.](https://github.com/tusooa) fixed the use of `get<>` calls.
|
||||
332. [taro](https://github.com/tarolling) fixed a typo in the `CODEOWNERS` file.
|
||||
333. [Ikko Eltociear Ashimine](https://github.com/eltociear) fixed a typo.
|
||||
334. [Felix Yan](https://github.com/felixonmars) fixed a typo in the README.
|
||||
335. [HO-COOH](https://github.com/HO-COOH) fixed a parentheses in the documentation.
|
||||
336. [Ivor Wanders](https://github.com/iwanders) fixed the examples to catch exception by `const&`.
|
||||
337. [miny1233](https://github.com/miny1233) fixed a parentheses in the documentation.
|
||||
338. [tomalakgeretkal](https://github.com/tomalakgeretkal) fixed a compilation error.
|
||||
339. [alferov](https://github.com/ALF-ONE) fixed a compilation error.
|
||||
340. [Craig Scott](https://github.com/craigscott-crascit) fixed a deprecation warning in CMake.
|
||||
341. [Vyacheslav Zhdanovskiy](https://github.com/ZeronSix) added macros for serialization-only types.
|
||||
342. [Mathieu Westphal](https://github.com/mwestphal) fixed typos.
|
||||
343. [scribam](https://github.com/scribam) fixed the MinGW workflow.
|
||||
344. [Aleksei Sapitskii](https://github.com/aleksproger) added support for Apple's Swift Package Manager.
|
||||
345. [Benjamin Buch](https://github.com/bebuch) fixed the installation path in CMake.
|
||||
346. [Colby Haskell](https://github.com/colbychaskell) clarified the parse error message in case a file cannot be opened.
|
||||
|
||||
Thanks a lot for helping out! Please [let me know](mailto:mail@nlohmann.me) if I forgot someone.
|
||||
|
||||
@@ -1839,7 +1902,7 @@ json/tests/src/make_test_data_available.hpp:23: FATAL ERROR: REQUIRE( utils::che
|
||||
|
||||
In case you have downloaded the library rather than checked out the code via Git, test `cmake_fetch_content_configure` will fail. Please execute `ctest -LE git_required` to skip these tests. See [issue #2189](https://github.com/nlohmann/json/issues/2189) for more information.
|
||||
|
||||
Some tests change the installed files and hence make the whole process not reproducible. Please execute `ctest -LE not_reproducible` to skip these tests. See [issue #2324](https://github.com/nlohmann/json/issues/2324) for more information.
|
||||
Some tests change the installed files and hence make the whole process not reproducible. Please execute `ctest -LE not_reproducible` to skip these tests. See [issue #2324](https://github.com/nlohmann/json/issues/2324) for more information. Furthermore, assertions must be switched off to ensure reproducible builds (see [discussion 4494](https://github.com/nlohmann/json/discussions/4494)).
|
||||
|
||||
Note you need to call `cmake -LE "not_reproducible|git_required"` to exclude both labels. See [issue #2596](https://github.com/nlohmann/json/issues/2596) for more information.
|
||||
|
||||
|
||||
1
WORKSPACE.bazel
Normal file
1
WORKSPACE.bazel
Normal file
@@ -0,0 +1 @@
|
||||
workspace(name = "nlohmann_json")
|
||||
@@ -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
|
||||
@@ -667,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}
|
||||
)
|
||||
|
||||
###############################################################################
|
||||
@@ -833,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()
|
||||
|
||||
@@ -905,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}
|
||||
@@ -929,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
|
||||
###############################################################################
|
||||
|
||||
@@ -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.6 MiB After Width: | Height: | Size: 1.6 MiB |
@@ -175,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');
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "JSON for Modern C++",
|
||||
"version": "3.11.2",
|
||||
"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
|
||||
// =============
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -31,7 +31,7 @@ int main()
|
||||
j["address"] = "744 Evergreen Terrace";
|
||||
j["age"] = 60;
|
||||
|
||||
auto p = j.get<ns::person>();
|
||||
auto p = j.template get<ns::person>();
|
||||
|
||||
std::cout << p.name << " (" << p.age << ") lives in " << p.address << std::endl;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ int main()
|
||||
j["address"] = "744 Evergreen Terrace";
|
||||
j["age"] = 60;
|
||||
|
||||
auto p = j.get<ns::person>();
|
||||
auto p = j.template get<ns::person>();
|
||||
|
||||
std::cout << p.name << " (" << p.age << ") lives in " << p.address << std::endl;
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"compiler": {
|
||||
"c++": "201103",
|
||||
"family": "gcc",
|
||||
"version": "12.1.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": 2,
|
||||
"string": "3.11.2"
|
||||
"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;
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
nlohmann::json_abi_v3_11_2
|
||||
nlohmann::json_abi_v3_11_3
|
||||
|
||||
@@ -44,16 +44,16 @@ int main()
|
||||
// deserialization
|
||||
json j_running = "running";
|
||||
json j_blue = "blue";
|
||||
auto running = j_running.get<ns::TaskState>();
|
||||
auto blue = j_blue.get<ns::Color>();
|
||||
auto running = j_running.template get<ns::TaskState>();
|
||||
auto blue = j_blue.template get<ns::Color>();
|
||||
std::cout << j_running << " -> " << running
|
||||
<< ", " << j_blue << " -> " << static_cast<int>(blue) << std::endl;
|
||||
|
||||
// deserializing undefined JSON value to enum
|
||||
// (where the first map entry above is the default)
|
||||
json j_pi = 3.14;
|
||||
auto invalid = j_pi.get<ns::TaskState>();
|
||||
auto unknown = j_pi.get<ns::Color>();
|
||||
auto invalid = j_pi.template get<ns::TaskState>();
|
||||
auto unknown = j_pi.template get<ns::Color>();
|
||||
std::cout << j_pi << " -> " << invalid << ", "
|
||||
<< j_pi << " -> " << static_cast<int>(unknown) << std::endl;
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ int main()
|
||||
|
||||
// deserialization
|
||||
json j_rot = "rot";
|
||||
auto rot = j_rot.get<ns::Color>();
|
||||
auto red = j_red.get<ns::Color>();
|
||||
auto rot = j_rot.template get<ns::Color>();
|
||||
auto red = j_red.template get<ns::Color>();
|
||||
std::cout << j_rot << " -> " << static_cast<int>(rot) << std::endl;
|
||||
std::cout << j_red << " -> " << static_cast<int>(red) << std::endl;
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
JSON for Modern C++ version 3.11.2
|
||||
JSON for Modern C++ version 3.11.3
|
||||
|
||||
@@ -21,7 +21,7 @@ int main()
|
||||
// can only create an object from a list of pairs
|
||||
json j_invalid_object = json::object({{ "one", 1, 2 }});
|
||||
}
|
||||
catch (json::type_error& e)
|
||||
catch (const json::type_error& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ int main()
|
||||
{
|
||||
bool v1 = json_types["string"];
|
||||
}
|
||||
catch (json::type_error& e)
|
||||
catch (const json::type_error& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ int main()
|
||||
json string = "foo";
|
||||
json discarded = json(json::value_t::discarded);
|
||||
|
||||
|
||||
// output values and comparisons
|
||||
std::cout << array_1 << " <=> " << array_2 << " := " << to_string(array_1 <=> array_2) << '\n'; // *NOPAD*
|
||||
std::cout << object_1 << " <=> " << object_2 << " := " << to_string(object_1 <=> object_2) << '\n'; // *NOPAD*
|
||||
|
||||
@@ -31,7 +31,6 @@ int main()
|
||||
json number = 17;
|
||||
json string = "17";
|
||||
|
||||
|
||||
// output values and comparisons
|
||||
std::cout << std::boolalpha << std::fixed;
|
||||
std::cout << boolean << " <=> " << true << " := " << to_string(boolean <=> true) << '\n'; // *NOPAD*
|
||||
|
||||
@@ -21,7 +21,7 @@ int main()
|
||||
}])"_json;
|
||||
value.patch(patch);
|
||||
}
|
||||
catch (json::other_error& e)
|
||||
catch (const json::other_error& e)
|
||||
{
|
||||
// output exception information
|
||||
std::cout << "message: " << e.what() << '\n'
|
||||
|
||||
@@ -11,7 +11,7 @@ int main()
|
||||
json j = {1, 2, 3, 4};
|
||||
j.at(4) = 10;
|
||||
}
|
||||
catch (json::out_of_range& e)
|
||||
catch (const json::out_of_range& e)
|
||||
{
|
||||
// output exception information
|
||||
std::cout << "message: " << e.what() << '\n'
|
||||
|
||||
@@ -17,7 +17,7 @@ int main()
|
||||
{
|
||||
json j = json::parse(text);
|
||||
}
|
||||
catch (json::parse_error& e)
|
||||
catch (const json::parse_error& e)
|
||||
{
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ int main()
|
||||
json j_complete = json::parse(ss);
|
||||
std::cout << std::setw(4) << j_complete << "\n\n";
|
||||
|
||||
|
||||
// define parser callback
|
||||
json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed)
|
||||
{
|
||||
|
||||
@@ -28,7 +28,6 @@ int main()
|
||||
json j_complete = json::parse(text);
|
||||
std::cout << std::setw(4) << j_complete << "\n\n";
|
||||
|
||||
|
||||
// define parser callback
|
||||
json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed)
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@ int main()
|
||||
// parsing input with a syntax error
|
||||
json::parse("[1,2,3,]");
|
||||
}
|
||||
catch (json::parse_error& e)
|
||||
catch (const json::parse_error& e)
|
||||
{
|
||||
// output exception information
|
||||
std::cout << "message: " << e.what() << '\n'
|
||||
|
||||
@@ -11,7 +11,7 @@ int main()
|
||||
json j = "string";
|
||||
j.push_back("another string");
|
||||
}
|
||||
catch (json::type_error& e)
|
||||
catch (const json::type_error& e)
|
||||
{
|
||||
// output exception information
|
||||
std::cout << "message: " << e.what() << '\n'
|
||||
|
||||
BIN
docs/json.gif
BIN
docs/json.gif
Binary file not shown.
|
Before Width: | Height: | Size: 1.6 MiB After Width: | Height: | Size: 1.6 MiB |
@@ -21,7 +21,7 @@ style_check:
|
||||
clean:
|
||||
rm -fr docs/images/json.gif docs/examples
|
||||
|
||||
# publish site to GitHub pages
|
||||
# publish site to GitHub pages (not working in GitHub Actions; need special action)
|
||||
publish: prepare_files
|
||||
venv/bin/mkdocs gh-deploy --clean --force
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_
|
||||
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}))
|
||||
```
|
||||
|
||||
This function is usually called by the [`get()`](../basic_json/get.md) function of the [basic_json](../basic_json)
|
||||
This function is usually called by the [`get()`](../basic_json/get.md) function of the [basic_json](../basic_json/index.md)
|
||||
class (either explicitly or via the conversion operators).
|
||||
|
||||
1. This function is chosen for default-constructible value types.
|
||||
@@ -37,7 +37,7 @@ Copy of the JSON value, converted to `ValueType`
|
||||
??? example "Example: (1) Default-constructible type"
|
||||
|
||||
The example below shows how a `from_json` function can be implemented for a user-defined type. This function is
|
||||
called by the `adl_serializer` when `get<ns::person>()` is called.
|
||||
called by the `adl_serializer` when `template get<ns::person>()` is called.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/from_json__default_constructible.cpp"
|
||||
|
||||
@@ -7,7 +7,7 @@ static auto to_json(BasicJsonType& j, TargetType && val) noexcept(
|
||||
-> decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)), void())
|
||||
```
|
||||
|
||||
This function is usually called by the constructors of the [basic_json](../basic_json) class.
|
||||
This function is usually called by the constructors of the [basic_json](../basic_json/index.md) class.
|
||||
|
||||
## Parameters
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ constructor.
|
||||
|
||||
## See also
|
||||
|
||||
[List of exceptions](127.0.0.1:8000/home/exceptions/)
|
||||
[List of exceptions](../../home/exceptions.md)
|
||||
|
||||
## Version history
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@ template<
|
||||
class NumberFloatType = double,
|
||||
template<typename U> class AllocatorType = std::allocator,
|
||||
template<typename T, typename SFINAE = void> class JSONSerializer = adl_serializer,
|
||||
class BinaryType = std::vector<std::uint8_t>
|
||||
class BinaryType = std::vector<std::uint8_t>,
|
||||
class CustomBaseClass = void
|
||||
>
|
||||
class basic_json;
|
||||
```
|
||||
@@ -32,6 +33,7 @@ class basic_json;
|
||||
| `AllocatorType` | type of the allocator to use | |
|
||||
| `JSONSerializer` | the serializer to resolve internal calls to `to_json()` and `from_json()` | [`json_serializer`](json_serializer.md) |
|
||||
| `BinaryType` | type for binary arrays | [`binary_t`](binary_t.md) |
|
||||
| `CustomBaseClass` | extension point for user code | [`json_base_class_t`](json_base_class_t.md) |
|
||||
|
||||
## Specializations
|
||||
|
||||
@@ -71,7 +73,7 @@ The class satisfies the following concept requirements:
|
||||
- [EqualityComparable](https://en.cppreference.com/w/cpp/named_req/EqualityComparable): JSON values can be compared with
|
||||
`==`, see [`operator==`](operator_eq.md).
|
||||
- [LessThanComparable](https://en.cppreference.com/w/cpp/named_req/LessThanComparable): JSON values can be compared with
|
||||
`<`, see [`operator<`](operator_le).
|
||||
`<`, see [`operator<`](operator_le.md).
|
||||
- [Swappable](https://en.cppreference.com/w/cpp/named_req/Swappable): Any JSON lvalue or rvalue of can be swapped with
|
||||
any lvalue or rvalue of other compatible types, using unqualified function `swap`.
|
||||
- [NullablePointer](https://en.cppreference.com/w/cpp/named_req/NullablePointer): JSON values can be compared against
|
||||
@@ -86,7 +88,7 @@ The class satisfies the following concept requirements:
|
||||
|
||||
## Member types
|
||||
|
||||
- [**adl_serializer**](../adl_serializer) - the default serializer
|
||||
- [**adl_serializer**](../adl_serializer/index.md) - the default serializer
|
||||
- [**value_t**](value_t.md) - the JSON type enumeration
|
||||
- [**json_pointer**](../json_pointer/index.md) - JSON Pointer implementation
|
||||
- [**json_serializer**](json_serializer.md) - type of the serializer to for conversions from/to JSON
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user