mirror of
https://github.com/nlohmann/json.git
synced 2026-03-24 18:02:47 +00:00
Compare commits
83 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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
|
arm_container:
|
||||||
name: test-on-arm64
|
image: gcc:latest
|
||||||
|
|
||||||
platform:
|
check_task:
|
||||||
arch: arm64
|
check_script:
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: build
|
|
||||||
image: gcc
|
|
||||||
commands:
|
|
||||||
- wget https://github.com/Kitware/CMake/releases/download/v3.20.2/cmake-3.20.2.tar.gz
|
- 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
|
- tar xfz cmake-3.20.2.tar.gz
|
||||||
- cd cmake-3.20.2
|
- cd cmake-3.20.2
|
||||||
- ./configure
|
- ./configure
|
||||||
- make cmake ctest -j10
|
- make cmake ctest -j4
|
||||||
- cd ..
|
- cd ..
|
||||||
- mkdir build
|
- mkdir build
|
||||||
- cd build
|
- cd build
|
||||||
- ../cmake-3.20.2/bin/cmake .. -DJSON_FastTests=ON
|
- ../cmake-3.20.2/bin/cmake .. -DJSON_FastTests=ON
|
||||||
- make -j10
|
- make -j4
|
||||||
- cd tests
|
- cd tests
|
||||||
- ../../cmake-3.20.2/bin/ctest -j10
|
- ../../cmake-3.20.2/bin/ctest -j4
|
||||||
@@ -6,6 +6,8 @@ Checks: '*,
|
|||||||
-bugprone-easily-swappable-parameters,
|
-bugprone-easily-swappable-parameters,
|
||||||
-cert-err58-cpp,
|
-cert-err58-cpp,
|
||||||
-concurrency-mt-unsafe,
|
-concurrency-mt-unsafe,
|
||||||
|
-cppcoreguidelines-avoid-const-or-ref-data-members,
|
||||||
|
-cppcoreguidelines-avoid-do-while,
|
||||||
-cppcoreguidelines-avoid-goto,
|
-cppcoreguidelines-avoid-goto,
|
||||||
-cppcoreguidelines-avoid-magic-numbers,
|
-cppcoreguidelines-avoid-magic-numbers,
|
||||||
-cppcoreguidelines-avoid-non-const-global-variables,
|
-cppcoreguidelines-avoid-non-const-global-variables,
|
||||||
@@ -15,6 +17,7 @@ Checks: '*,
|
|||||||
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
|
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
|
||||||
-cppcoreguidelines-pro-type-reinterpret-cast,
|
-cppcoreguidelines-pro-type-reinterpret-cast,
|
||||||
-cppcoreguidelines-pro-type-union-access,
|
-cppcoreguidelines-pro-type-union-access,
|
||||||
|
-cppcoreguidelines-rvalue-reference-param-not-moved,
|
||||||
-cppcoreguidelines-virtual-class-destructor,
|
-cppcoreguidelines-virtual-class-destructor,
|
||||||
-fuchsia-default-arguments-calls,
|
-fuchsia-default-arguments-calls,
|
||||||
-fuchsia-default-arguments-declarations,
|
-fuchsia-default-arguments-declarations,
|
||||||
@@ -33,11 +36,17 @@ Checks: '*,
|
|||||||
-llvm-header-guard,
|
-llvm-header-guard,
|
||||||
-llvm-include-order,
|
-llvm-include-order,
|
||||||
-llvmlibc-*,
|
-llvmlibc-*,
|
||||||
|
-misc-use-anonymous-namespace,
|
||||||
|
-misc-confusable-identifiers,
|
||||||
|
-misc-include-cleaner,
|
||||||
-misc-no-recursion,
|
-misc-no-recursion,
|
||||||
-misc-non-private-member-variables-in-classes,
|
-misc-non-private-member-variables-in-classes,
|
||||||
-modernize-concat-nested-namespaces,
|
-modernize-concat-nested-namespaces,
|
||||||
|
-modernize-type-traits,
|
||||||
|
-modernize-use-constraints,
|
||||||
-modernize-use-nodiscard,
|
-modernize-use-nodiscard,
|
||||||
-modernize-use-trailing-return-type,
|
-modernize-use-trailing-return-type,
|
||||||
|
-performance-enum-size,
|
||||||
-readability-function-cognitive-complexity,
|
-readability-function-cognitive-complexity,
|
||||||
-readability-function-size,
|
-readability-function-size,
|
||||||
-readability-identifier-length,
|
-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.
|
# JSON for Modern C++ was originally written by Niels Lohmann.
|
||||||
# Since 2013 over 140 contributors have helped to improve the library.
|
# Since 2013, over 250 contributors have helped to improve the library.
|
||||||
# This CODEOWNERS file is only to make sure that @nlohmann is requested
|
# This CODEOWNERS file is only to make sure that @nlohmann is requested
|
||||||
# for a code review in case of a pull request.
|
# for a code review in case of a pull request.
|
||||||
|
|
||||||
|
|||||||
4
.github/CONTRIBUTING.md
vendored
4
.github/CONTRIBUTING.md
vendored
@@ -32,7 +32,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`.
|
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
|
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 +55,7 @@ To make changes, you need to edit the following files:
|
|||||||
## Please don't
|
## 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.
|
- 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 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 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).
|
- 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
|
label: Library version
|
||||||
description: >
|
description: >
|
||||||
Which version of the library did you use? If it is a released version,
|
Which version of the library did you use? If it is a released version,
|
||||||
please enter the version number (e.g., 3.11.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
|
the commit hash. If you got the library from another source as the
|
||||||
GitHub repository (e.g., via a package manager), please also state
|
GitHub repository (e.g., via a package manager), please also state
|
||||||
this.
|
this.
|
||||||
|
|||||||
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
|
## 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.
|
- 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 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**.
|
- 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@v2
|
||||||
|
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@v3
|
||||||
|
with:
|
||||||
|
path: main
|
||||||
|
ref: ${{ github.event.pull_request.head.sha }}
|
||||||
|
|
||||||
|
- name: Checkout tools
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
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@v3
|
||||||
|
if: failure() && steps.build.outcome == 'success'
|
||||||
|
with:
|
||||||
|
name: artifacts
|
||||||
|
path: ./out/artifacts
|
||||||
7
.github/workflows/codeql-analysis.yml
vendored
7
.github/workflows/codeql-analysis.yml
vendored
@@ -10,6 +10,9 @@ on:
|
|||||||
schedule:
|
schedule:
|
||||||
- cron: '0 19 * * 1'
|
- cron: '0 19 * * 1'
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
|
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
|
||||||
@@ -19,6 +22,8 @@ jobs:
|
|||||||
CodeQL-Build:
|
CodeQL-Build:
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
security-events: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
@@ -27,6 +32,8 @@ jobs:
|
|||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v2
|
uses: github/codeql-action/init@v2
|
||||||
|
with:
|
||||||
|
languages: c-cpp
|
||||||
|
|
||||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
# If this step fails, then you should remove it and run the build manually (see below)
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
|
|||||||
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:
|
pull_request_target:
|
||||||
types: [opened, synchronize]
|
types: [opened, synchronize]
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
label:
|
label:
|
||||||
permissions:
|
permissions:
|
||||||
|
|||||||
9
.github/workflows/macos.yml
vendored
9
.github/workflows/macos.yml
vendored
@@ -9,6 +9,9 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
|
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
@@ -35,7 +38,7 @@ jobs:
|
|||||||
runs-on: macos-12
|
runs-on: macos-12
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
xcode: ['13.1', '13.2.1', '13.3.1', '13.4.1']
|
xcode: ['13.1', '13.2.1', '13.3.1', '13.4.1', '14.0', '14.0.1', '14.1']
|
||||||
env:
|
env:
|
||||||
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
||||||
|
|
||||||
@@ -52,9 +55,7 @@ jobs:
|
|||||||
runs-on: macos-latest
|
runs-on: macos-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
standard: [11, 14, 17, 20]
|
standard: [11, 14, 17, 20, 23]
|
||||||
env:
|
|
||||||
DEVELOPER_DIR: /Applications/Xcode_12.4.app/Contents/Developer
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|||||||
13
.github/workflows/publish_documentation.yml
vendored
13
.github/workflows/publish_documentation.yml
vendored
@@ -10,6 +10,9 @@ on:
|
|||||||
- docs/examples/**
|
- docs/examples/**
|
||||||
workflow_dispatch:
|
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
|
# we don't want to have concurrent jobs, and we don't want to cancel running jobs to avoid broken publications
|
||||||
concurrency:
|
concurrency:
|
||||||
group: documentation
|
group: documentation
|
||||||
@@ -28,5 +31,11 @@ jobs:
|
|||||||
- name: Install virtual environment
|
- name: Install virtual environment
|
||||||
run: make install_venv -C docs/mkdocs
|
run: make install_venv -C docs/mkdocs
|
||||||
|
|
||||||
- name: Publish documentation
|
- name: Build documentation
|
||||||
run: make publish -C docs/mkdocs
|
run: make build -C docs/mkdocs
|
||||||
|
|
||||||
|
- name: Deploy documentation
|
||||||
|
uses: peaceiris/actions-gh-pages@v3
|
||||||
|
with:
|
||||||
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
publish_dir: ./docs/mkdocs/site
|
||||||
|
|||||||
110
.github/workflows/ubuntu.yml
vendored
110
.github/workflows/ubuntu.yml
vendored
@@ -8,6 +8,9 @@ on:
|
|||||||
- release/*
|
- release/*
|
||||||
pull_request:
|
pull_request:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
|
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
|
||||||
@@ -16,9 +19,13 @@ concurrency:
|
|||||||
jobs:
|
jobs:
|
||||||
ci_test_clang:
|
ci_test_clang:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
container: silkeh/clang:dev
|
||||||
steps:
|
steps:
|
||||||
|
- name: Install git and unzip
|
||||||
|
run: apt-get update ; apt-get install -y git unzip
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
- name: Get latest CMake and ninja
|
||||||
|
uses: lukka/get-cmake@v3.27.7
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -39,7 +46,7 @@ jobs:
|
|||||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
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:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
@@ -47,24 +54,49 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: cmake --build build --target ${{ matrix.target }}
|
run: cmake --build build --target ${{ matrix.target }}
|
||||||
|
|
||||||
ci_test_single_header:
|
ci_static_analysis_ubuntu:
|
||||||
runs-on: ubuntu-latest
|
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:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
- name: Get latest CMake and ninja
|
||||||
|
uses: lukka/get-cmake@v3.27.7
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
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@v3
|
||||||
|
- name: Get latest CMake and ninja
|
||||||
|
uses: lukka/get-cmake@v3.27.7
|
||||||
|
- name: Run CMake
|
||||||
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
|
- name: Build
|
||||||
|
run: cmake --build build --target ${{ matrix.target }}
|
||||||
|
|
||||||
ci_cmake_options:
|
ci_cmake_options:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
container: ubuntu:focal
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
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:
|
steps:
|
||||||
|
- name: Install build-essential
|
||||||
|
run: apt-get update ; apt-get install -y build-essential unzip wget git
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
- name: Get latest CMake and ninja
|
||||||
|
uses: lukka/get-cmake@v3.27.7
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -73,6 +105,9 @@ jobs:
|
|||||||
ci_test_coverage:
|
ci_test_coverage:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
checks: write
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
@@ -90,12 +125,47 @@ jobs:
|
|||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
path-to-lcov: ${{ github.workspace }}/build/json.info.filtered.noexcept
|
path-to-lcov: ${{ github.workspace }}/build/json.info.filtered.noexcept
|
||||||
|
|
||||||
|
ci_test_compilers_gcc:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
compiler: ['4', '5', '6', '7', '8', '9', '10', '11', '12', 'latest']
|
||||||
|
container: gcc:${{ matrix.compiler }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Get latest CMake and ninja
|
||||||
|
uses: lukka/get-cmake@v3.27.7
|
||||||
|
- 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', '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@v3
|
||||||
|
- name: Get latest CMake and ninja
|
||||||
|
uses: lukka/get-cmake@v3.27.7
|
||||||
|
- 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:
|
ci_test_compilers:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
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:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
@@ -103,19 +173,35 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: cmake --build build --target ci_test_compiler_${{ matrix.compiler }}
|
run: cmake --build build --target ci_test_compiler_${{ matrix.compiler }}
|
||||||
|
|
||||||
ci_test_standards:
|
ci_test_standards_gcc:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
standard: [11, 14, 17, 20]
|
standard: [11, 14, 17, 20, 23]
|
||||||
compiler: [gcc, clang]
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
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]
|
||||||
|
steps:
|
||||||
|
- name: Install git and unzip
|
||||||
|
run: apt-get update ; apt-get install -y git unzip
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Get latest CMake and ninja
|
||||||
|
uses: lukka/get-cmake@v3.27.7
|
||||||
|
- name: Run CMake
|
||||||
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
|
- name: Build
|
||||||
|
run: cmake --build build --target ci_test_clang_cxx${{ matrix.standard }}
|
||||||
|
|
||||||
ci_cuda_example:
|
ci_cuda_example:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|||||||
37
.github/workflows/windows.yml
vendored
37
.github/workflows/windows.yml
vendored
@@ -9,44 +9,27 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
|
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
mingw:
|
mingw:
|
||||||
runs-on: windows-latest
|
runs-on: windows-2019
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
architecture: [x64, x86]
|
architecture: [x64, x86]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Download MinGW 8.1.0
|
- name: Set up MinGW
|
||||||
run: |
|
uses: egor-tensin/setup-mingw@v2
|
||||||
$headers = @{Authorization = 'Bearer ${{ secrets.GITHUB_TOKEN }}'}
|
with:
|
||||||
$uri = 'https://nuget.pkg.github.com/falbrechtskirchinger/download/mingw/8.1.0/mingw.8.1.0.nupkg'
|
platform: ${{ matrix.architecture }}
|
||||||
Invoke-WebRequest -Uri $uri -Headers $headers -OutFile mingw.8.1.0.nupkg
|
version: 12.2.0 # https://github.com/egor-tensin/setup-mingw/issues/14
|
||||||
- name: Uninstall MinGW
|
|
||||||
continue-on-error: true
|
|
||||||
run: choco uninstall mingw
|
|
||||||
# Based on egor-tensin/setup-mingw
|
|
||||||
- name: Install MinGW 8.1.0
|
|
||||||
run: |
|
|
||||||
choco install mingw.8.1.0.nupkg ${{ matrix.architecture == 'x86' && '--x86' || '' }}
|
|
||||||
$prefix = "${{ matrix.architecture == 'x64' && 'x86_64-w64-mingw32' || 'i686-w64-mingw32' }}"
|
|
||||||
$mingw = "${{ matrix.architecture == 'x64' && 'mingw64' || 'mingw32' }}"
|
|
||||||
$mingw_install = Join-Path C: ProgramData chocolatey lib mingw tools install
|
|
||||||
$mingw_root = Join-Path $mingw_install $mingw
|
|
||||||
$mingw_bin = Join-Path $mingw_root bin
|
|
||||||
$mingw_lib = Join-Path $mingw_root $prefix lib
|
|
||||||
echo $mingw_bin >> $env:GITHUB_PATH
|
|
||||||
Remove-Item (Join-Path $mingw_lib 'libpthread.dll.a')
|
|
||||||
Remove-Item (Join-Path $mingw_lib 'libwinpthread.dll.a')
|
|
||||||
#- name: Set up MinGW
|
|
||||||
# uses: egor-tensin/setup-mingw@v2
|
|
||||||
# with:
|
|
||||||
# platform: ${{ matrix.architecture }}
|
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On
|
run: cmake -S . -B build -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -122,7 +105,7 @@ jobs:
|
|||||||
runs-on: windows-2019
|
runs-on: windows-2019
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
version: [11, 12]
|
version: [11, 12, 13, 14, 15]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -39,3 +39,6 @@
|
|||||||
/localhost.pem
|
/localhost.pem
|
||||||
/localhost-key.pem
|
/localhost-key.pem
|
||||||
/serve_header.yml
|
/serve_header.yml
|
||||||
|
|
||||||
|
# Swift Package Manager build directory
|
||||||
|
/.build
|
||||||
@@ -27,10 +27,6 @@ Files: tools/amalgamate/*
|
|||||||
Copyright: 2012 Erik Edlund <erik.edlund@32767.se>
|
Copyright: 2012 Erik Edlund <erik.edlund@32767.se>
|
||||||
License: BSD-3-Clause
|
License: BSD-3-Clause
|
||||||
|
|
||||||
Files: tools/cpplint/*
|
|
||||||
Copyright: 2009 Google Inc. All rights reserved.
|
|
||||||
License: BSD-3-Clause
|
|
||||||
|
|
||||||
Files: tools/gdb_pretty_printer
|
Files: tools/gdb_pretty_printer
|
||||||
Copyright: 2020 Hannes Domani <https://github.com/ssbssa>
|
Copyright: 2020 Hannes Domani <https://github.com/ssbssa>
|
||||||
License: MIT
|
License: MIT
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
__ _____ _____ _____
|
__ _____ _____ _____
|
||||||
__| | __| | | | JSON for Modern C++
|
__| | __| | | | JSON for Modern C++
|
||||||
| | |__ | | | | | | version 3.11.2
|
| | |__ | | | | | | version 3.11.3
|
||||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||||
|
|
||||||
{% for copyright_line in copyright_lines %}
|
{% for copyright_line in copyright_lines %}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
__ _____ _____ _____
|
__ _____ _____ _____
|
||||||
__| | __| | | | JSON for Modern C++ (supporting code)
|
__| | __| | | | JSON for Modern C++ (supporting code)
|
||||||
| | |__ | | | | | | version 3.11.2
|
| | |__ | | | | | | version 3.11.3
|
||||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||||
|
|
||||||
{% for copyright_line in copyright_lines %}
|
{% for copyright_line in copyright_lines %}
|
||||||
|
|||||||
53
BUILD.bazel
Normal file
53
BUILD.bazel
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
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"],
|
||||||
|
alwayslink = True,
|
||||||
|
)
|
||||||
@@ -7,8 +7,8 @@ authors:
|
|||||||
email: mail@nlohmann.me
|
email: mail@nlohmann.me
|
||||||
website: https://nlohmann.me
|
website: https://nlohmann.me
|
||||||
title: "JSON for Modern C++"
|
title: "JSON for Modern C++"
|
||||||
version: 3.11.2
|
version: 3.11.3
|
||||||
date-released: 2022-08-12
|
date-released: 2023-11-28
|
||||||
license: MIT
|
license: MIT
|
||||||
repository-code: "https://github.com/nlohmann"
|
repository-code: "https://github.com/nlohmann"
|
||||||
url: https://json.nlohmann.me
|
url: https://json.nlohmann.me
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
cmake_minimum_required(VERSION 3.1)
|
cmake_minimum_required(VERSION 3.1...3.14)
|
||||||
|
|
||||||
##
|
##
|
||||||
## PROJECT
|
## PROJECT
|
||||||
## name and version
|
## name and version
|
||||||
##
|
##
|
||||||
project(nlohmann_json VERSION 3.11.2 LANGUAGES CXX)
|
project(nlohmann_json VERSION 3.11.3 LANGUAGES CXX)
|
||||||
|
|
||||||
##
|
##
|
||||||
## MAIN_PROJECT CHECK
|
## MAIN_PROJECT CHECK
|
||||||
@@ -43,7 +43,7 @@ option(JSON_Diagnostics "Use extended diagnostic messages." O
|
|||||||
option(JSON_GlobalUDLs "Place use-defined string literals in the global namespace." ON)
|
option(JSON_GlobalUDLs "Place use-defined string literals in the global namespace." ON)
|
||||||
option(JSON_ImplicitConversions "Enable implicit conversions." ON)
|
option(JSON_ImplicitConversions "Enable implicit conversions." ON)
|
||||||
option(JSON_DisableEnumSerialization "Disable default integer enum serialization." OFF)
|
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_Install "Install CMake targets during install step." ${MAIN_PROJECT})
|
||||||
option(JSON_MultipleHeaders "Use non-amalgamated version of the library." ON)
|
option(JSON_MultipleHeaders "Use non-amalgamated version of the library." ON)
|
||||||
option(JSON_SystemInclude "Include as system headers (skip for clang-tidy)." OFF)
|
option(JSON_SystemInclude "Include as system headers (skip for clang-tidy)." OFF)
|
||||||
@@ -122,7 +122,7 @@ target_include_directories(
|
|||||||
${NLOHMANN_JSON_TARGET_NAME}
|
${NLOHMANN_JSON_TARGET_NAME}
|
||||||
${NLOHMANN_JSON_SYSTEM_INCLUDE} INTERFACE
|
${NLOHMANN_JSON_SYSTEM_INCLUDE} INTERFACE
|
||||||
$<BUILD_INTERFACE:${NLOHMANN_JSON_INCLUDE_BUILD_DIR}>
|
$<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)
|
## add debug view definition file for msvc (natvis)
|
||||||
|
|||||||
9
Makefile
9
Makefile
@@ -156,7 +156,8 @@ pretty:
|
|||||||
--pad-header \
|
--pad-header \
|
||||||
--align-pointer=type \
|
--align-pointer=type \
|
||||||
--align-reference=type \
|
--align-reference=type \
|
||||||
--add-brackets \
|
--add-braces \
|
||||||
|
--squeeze-lines=2 \
|
||||||
--convert-tabs \
|
--convert-tabs \
|
||||||
--close-templates \
|
--close-templates \
|
||||||
--lineend=linux \
|
--lineend=linux \
|
||||||
@@ -192,6 +193,8 @@ check-amalgamation:
|
|||||||
@mv $(AMALGAMATED_FILE)~ $(AMALGAMATED_FILE)
|
@mv $(AMALGAMATED_FILE)~ $(AMALGAMATED_FILE)
|
||||||
@mv $(AMALGAMATED_FWD_FILE)~ $(AMALGAMATED_FWD_FILE)
|
@mv $(AMALGAMATED_FWD_FILE)~ $(AMALGAMATED_FWD_FILE)
|
||||||
|
|
||||||
|
BUILD.bazel: $(SRCS)
|
||||||
|
cmake -P cmake/scripts/gen_bazel_build_file.cmake
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# ChangeLog
|
# ChangeLog
|
||||||
@@ -223,8 +226,8 @@ json.tar.xz:
|
|||||||
|
|
||||||
# We use `-X` to make the resulting ZIP file reproducible, see
|
# We use `-X` to make the resulting ZIP file reproducible, see
|
||||||
# <https://content.pivotal.io/blog/barriers-to-deterministic-reproducible-zip-files>.
|
# <https://content.pivotal.io/blog/barriers-to-deterministic-reproducible-zip-files>.
|
||||||
include.zip:
|
include.zip: BUILD.bazel
|
||||||
zip -9 --recurse-paths -X include.zip $(SRCS) $(AMALGAMATED_FILE) meson.build LICENSE.MIT
|
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.
|
# Create the files for a release and add signatures and hashes.
|
||||||
release: include.zip json.tar.xz
|
release: include.zip json.tar.xz
|
||||||
|
|||||||
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
|
||||||
|
)
|
||||||
165
README.md
165
README.md
@@ -7,12 +7,13 @@
|
|||||||
[](https://coveralls.io/github/nlohmann/json?branch=develop)
|
[](https://coveralls.io/github/nlohmann/json?branch=develop)
|
||||||
[](https://scan.coverity.com/projects/nlohmann-json)
|
[](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://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://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:json)
|
||||||
[](https://wandbox.org/permlink/1mp10JbaANo6FUc7)
|
[](https://wandbox.org/permlink/1mp10JbaANo6FUc7)
|
||||||
[](https://json.nlohmann.me)
|
[](https://json.nlohmann.me)
|
||||||
[](https://raw.githubusercontent.com/nlohmann/json/master/LICENSE.MIT)
|
[](https://raw.githubusercontent.com/nlohmann/json/master/LICENSE.MIT)
|
||||||
[](https://github.com/nlohmann/json/releases)
|
[](https://github.com/nlohmann/json/releases)
|
||||||
|
[](https://vcpkg.link/ports/nlohmann-json)
|
||||||
[](https://repology.org/project/nlohmann-json/versions)
|
[](https://repology.org/project/nlohmann-json/versions)
|
||||||
[](https://github.com/nlohmann/json/releases)
|
[](https://github.com/nlohmann/json/releases)
|
||||||
[](https://github.com/nlohmann/json/issues)
|
[](https://github.com/nlohmann/json/issues)
|
||||||
@@ -76,7 +77,7 @@ You can sponsor this library at [GitHub Sponsors](https://github.com/sponsors/nl
|
|||||||
|
|
||||||
### :office: Corporate Sponsor
|
### :office: Corporate Sponsor
|
||||||
|
|
||||||
[](https://github.com/codacy)
|
[](https://github.com/codacy/About)
|
||||||
|
|
||||||
### :label: Named Sponsors
|
### :label: Named Sponsors
|
||||||
|
|
||||||
@@ -85,6 +86,7 @@ You can sponsor this library at [GitHub Sponsors](https://github.com/sponsors/nl
|
|||||||
- [Steve Sperandeo](https://github.com/homer6)
|
- [Steve Sperandeo](https://github.com/homer6)
|
||||||
- [Robert Jefe Lindstädt](https://github.com/eljefedelrodeodeljefe)
|
- [Robert Jefe Lindstädt](https://github.com/eljefedelrodeodeljefe)
|
||||||
- [Steve Wagner](https://github.com/ciroque)
|
- [Steve Wagner](https://github.com/ciroque)
|
||||||
|
- [Lion Yang](https://github.com/LionNatsu)
|
||||||
|
|
||||||
Thanks everyone!
|
Thanks everyone!
|
||||||
|
|
||||||
@@ -268,7 +270,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
|
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.
|
`"{ "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/)).
|
(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/):
|
The above example can also be expressed explicitly using [`json::parse()`](https://json.nlohmann.me/api/basic_json/parse/):
|
||||||
@@ -300,7 +302,7 @@ Note the difference between serialization and assignment:
|
|||||||
json j_string = "this is a string";
|
json j_string = "this is a string";
|
||||||
|
|
||||||
// retrieve the string value
|
// 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)
|
// retrieve the string value (alternative when a variable already exists)
|
||||||
std::string cpp_string2;
|
std::string cpp_string2;
|
||||||
j_string.get_to(cpp_string2);
|
j_string.get_to(cpp_string2);
|
||||||
@@ -309,7 +311,7 @@ j_string.get_to(cpp_string2);
|
|||||||
std::string serialized_string = j_string.dump();
|
std::string serialized_string = j_string.dump();
|
||||||
|
|
||||||
// output of original string
|
// 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
|
// output of serialized value
|
||||||
std::cout << j_string << " == " << serialized_string << std::endl;
|
std::cout << j_string << " == " << serialized_string << std::endl;
|
||||||
```
|
```
|
||||||
@@ -482,7 +484,7 @@ for (auto& element : j) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getter/setter
|
// getter/setter
|
||||||
const auto tmp = j[0].get<std::string>();
|
const auto tmp = j[0].template get<std::string>();
|
||||||
j[1] = 42;
|
j[1] = 42;
|
||||||
bool foo = j.at(2);
|
bool foo = j.at(2);
|
||||||
|
|
||||||
@@ -690,7 +692,7 @@ You can switch off implicit conversions by defining `JSON_USE_IMPLICIT_CONVERSIO
|
|||||||
// strings
|
// strings
|
||||||
std::string s1 = "Hello, world!";
|
std::string s1 = "Hello, world!";
|
||||||
json js = s1;
|
json js = s1;
|
||||||
auto s2 = js.get<std::string>();
|
auto s2 = js.template get<std::string>();
|
||||||
// NOT RECOMMENDED
|
// NOT RECOMMENDED
|
||||||
std::string s3 = js;
|
std::string s3 = js;
|
||||||
std::string s4;
|
std::string s4;
|
||||||
@@ -699,7 +701,7 @@ s4 = js;
|
|||||||
// Booleans
|
// Booleans
|
||||||
bool b1 = true;
|
bool b1 = true;
|
||||||
json jb = b1;
|
json jb = b1;
|
||||||
auto b2 = jb.get<bool>();
|
auto b2 = jb.template get<bool>();
|
||||||
// NOT RECOMMENDED
|
// NOT RECOMMENDED
|
||||||
bool b3 = jb;
|
bool b3 = jb;
|
||||||
bool b4;
|
bool b4;
|
||||||
@@ -708,7 +710,7 @@ b4 = jb;
|
|||||||
// numbers
|
// numbers
|
||||||
int i = 42;
|
int i = 42;
|
||||||
json jn = i;
|
json jn = i;
|
||||||
auto f = jn.get<double>();
|
auto f = jn.template get<double>();
|
||||||
// NOT RECOMMENDED
|
// NOT RECOMMENDED
|
||||||
double f2 = jb;
|
double f2 = jb;
|
||||||
double f3;
|
double f3;
|
||||||
@@ -751,9 +753,9 @@ j["age"] = p.age;
|
|||||||
|
|
||||||
// convert from JSON: copy each value from the JSON object
|
// convert from JSON: copy each value from the JSON object
|
||||||
ns::person p {
|
ns::person p {
|
||||||
j["name"].get<std::string>(),
|
j["name"].template get<std::string>(),
|
||||||
j["address"].get<std::string>(),
|
j["address"].template get<std::string>(),
|
||||||
j["age"].get<int>()
|
j["age"].template get<int>()
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -770,7 +772,7 @@ std::cout << j << std::endl;
|
|||||||
// {"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"}
|
// {"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"}
|
||||||
|
|
||||||
// conversion: json -> person
|
// conversion: json -> person
|
||||||
auto p2 = j.get<ns::person>();
|
auto p2 = j.template get<ns::person>();
|
||||||
|
|
||||||
// that's it
|
// that's it
|
||||||
assert(p == p2);
|
assert(p == p2);
|
||||||
@@ -797,13 +799,13 @@ namespace ns {
|
|||||||
```
|
```
|
||||||
|
|
||||||
That's all! When calling the `json` constructor with your type, your custom `to_json` method will be automatically called.
|
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:
|
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 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.
|
* 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.
|
* 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.
|
* You do not need to add serializers or deserializers for STL types like `std::vector`: the library already implements these.
|
||||||
|
|
||||||
@@ -888,8 +890,8 @@ namespace nlohmann {
|
|||||||
if (j.is_null()) {
|
if (j.is_null()) {
|
||||||
opt = boost::none;
|
opt = boost::none;
|
||||||
} else {
|
} else {
|
||||||
opt = j.get<T>(); // same as above, but with
|
opt = j.template get<T>(); // same as above, but with
|
||||||
// adl_serializer<T>::from_json
|
// adl_serializer<T>::from_json
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -916,7 +918,7 @@ namespace nlohmann {
|
|||||||
// note: the return type is no longer 'void', and the method only takes
|
// note: the return type is no longer 'void', and the method only takes
|
||||||
// one argument
|
// one argument
|
||||||
static move_only_type from_json(const json& j) {
|
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
|
// Here's the catch! You must provide a to_json method! Otherwise, you
|
||||||
@@ -1020,11 +1022,11 @@ assert(j == "stopped");
|
|||||||
|
|
||||||
// json string to enum
|
// json string to enum
|
||||||
json j3 = "running";
|
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)
|
// undefined json value to enum (where the first map entry above is the default)
|
||||||
json jPi = 3.14;
|
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,
|
Just as in [Arbitrary Type Conversions](#arbitrary-types-conversions) above,
|
||||||
@@ -1032,7 +1034,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.
|
- It MUST be available (e.g., proper headers must be included) everywhere you use the conversions.
|
||||||
|
|
||||||
Other Important points:
|
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.
|
- 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)
|
### Binary formats (BSON, CBOR, MessagePack, UBJSON, and BJData)
|
||||||
@@ -1109,7 +1111,7 @@ auto cbor = json::to_msgpack(j); // 0xD5 (fixext2), 0x10, 0xCA, 0xFE
|
|||||||
|
|
||||||
## Supported compilers
|
## 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 2023 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)
|
- GCC 4.8 - 12.0 (and possibly later)
|
||||||
- Clang 3.4 - 15.0 (and possibly later)
|
- Clang 3.4 - 15.0 (and possibly later)
|
||||||
@@ -1140,51 +1142,60 @@ 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.
|
- 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 |
|
| 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 11.0.3 (clang-1103.0.32.62); Xcode 11.7 | macOS 11.7.1 | 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.0 (clang-1200.0.32.29); Xcode 12.4 | macOS 11.7.1 | GitHub Actions |
|
||||||
| Apple Clang 12.0.5 (clang-1205.0.22.11); Xcode 12.5.1 | macOS 11.6.8 | GitHub Actions |
|
| Apple Clang 12.0.5 (clang-1205.0.22.11); Xcode 12.5.1 | macOS 11.7.1 | 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.0 | macOS 11.7.1 | 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.3); Xcode 13.1 | macOS 12.6.1 | GitHub Actions |
|
||||||
| Apple Clang 13.0.0 (clang-1300.0.29.30); Xcode 13.2.1 | macOS 12.4 | GitHub Actions |
|
| Apple Clang 13.0.0 (clang-1300.0.29.30); Xcode 13.2.1 | macOS 12.6.1 | 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.3); Xcode 13.3.1 | macOS 12.6.1 | GitHub Actions |
|
||||||
| Apple Clang 13.1.6 (clang-1316.0.21.2.5); Xcode 13.4.1 | macOS 12.4 | GitHub Actions |
|
| Apple Clang 13.1.6 (clang-1316.0.21.2.5); Xcode 13.4.1 | macOS 12.6.1 | GitHub Actions |
|
||||||
| Clang 3.5.2 (3.5.2-3ubuntu1) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
| Apple Clang 14.0.0 (clang-1400.0.29.102); Xcode 14.0 | macOS 12.6.1 | GitHub Actions |
|
||||||
| Clang 3.6.2 (3.6.2-3ubuntu2) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
| Apple Clang 14.0.0 (clang-1400.0.29.102); Xcode 14.0.1 | macOS 12.6.1 | GitHub Actions |
|
||||||
| Clang 3.7.1 (3.7.1-2ubuntu2) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
| Apple Clang 14.0.0 (clang-1400.0.29.202); Xcode 14.1 | macOS 12.6.1 | GitHub Actions |
|
||||||
| Clang 3.8.0 (3.8.0-2ubuntu4) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
| Clang 3.5.2 | 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 3.6.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 3.7.1 | 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 3.8.1 | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||||
| Clang 6.0.1 (6.0.1-14) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
| Clang 3.9.1 | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||||
| Clang 7.0.1 (7.0.1-12) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
| Clang 4.0.1 | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||||
| Clang 8.0.1 (8.0.1-9) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
| Clang 5.0.2 | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||||
| Clang 9.0.1 (9.0.1-12) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
| Clang 6.0.1 | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||||
| Clang 10.0.0 (10.0.0-4ubuntu1) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
| Clang 7.0.1 | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||||
|
| Clang 8.0.0 | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||||
|
| Clang 9.0.0 | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||||
|
| Clang 10.0.0 | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||||
| Clang 10.0.0 with GNU-like command-line | Windows-10.0.17763 | 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 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 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 11.0.0 | 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 12.0.0 | 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 12.0.0 with GNU-like command-line | Windows-10.0.17763 | GitHub Actions |
|
||||||
| Clang 14.0.5-++20220603124341+2f0a69c32a4c-1~exp1~20220603124352.149 | Ubuntu 20.04.3 LTS | GitHub Actions |
|
| Clang 13.0.0 | 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 |
|
| 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 |
|
||||||
| GCC 4.8.5 (Ubuntu 4.8.5-4ubuntu2) | 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 4.9.4 | 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 5.5.0 | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||||
| GCC 6.4.0 (Ubuntu 6.4.0-17ubuntu1) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
| GCC 6.5.0 | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||||
| GCC 7.5.0 (Ubuntu 7.5.0-6ubuntu2) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
| GCC 7.5.0 | Ubuntu 20.04.3 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 (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.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 8.5.0 | 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 9.5.0 | 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 10.4.0 | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||||
| GCC 11.1.0 | Ubuntu (aarch64) | Drone CI |
|
| GCC 11.1.0 | Ubuntu (aarch64) | Cirrus CI |
|
||||||
| GCC 11.1.0 (Ubuntu 11.1.0-1ubuntu1~20.04) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
| GCC 11.3.0 | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||||
| GCC 13.0.0 13.0.0 20220605 (experimental) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
| GCC 12.2.0 | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||||
|
| GCC 13.0.0 20220605 (experimental) | Ubuntu 20.04.3 LTS | GitHub Actions |
|
||||||
| Intel C++ Compiler 2021.5.0.20211109 | Ubuntu 20.04.3 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 |
|
| 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 |
|
| Visual Studio 14 2015 MSVC 19.0.24241.7 (Build Engine version 14.0.25420.1) | Windows-6.3.9600 | AppVeyor |
|
||||||
@@ -1262,7 +1273,7 @@ Example:
|
|||||||
```cmake
|
```cmake
|
||||||
include(FetchContent)
|
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)
|
FetchContent_MakeAvailable(json)
|
||||||
|
|
||||||
target_link_libraries(foo PRIVATE nlohmann_json::nlohmann_json)
|
target_link_libraries(foo PRIVATE nlohmann_json::nlohmann_json)
|
||||||
@@ -1309,7 +1320,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.
|
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.
|
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 +1338,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 [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 [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).
|
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).
|
||||||
@@ -1718,6 +1733,36 @@ I deeply appreciate the help of the following people.
|
|||||||
314. [Berkus Decker](https://github.com/berkus) fixed a typo in the README.
|
314. [Berkus Decker](https://github.com/berkus) fixed a typo in the README.
|
||||||
315. [Illia Polishchuk](https://github.com/effolkronium) improved the CMake testing.
|
315. [Illia Polishchuk](https://github.com/effolkronium) improved the CMake testing.
|
||||||
316. [Ikko Ashimine](https://github.com/eltociear) fixed a typo.
|
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.
|
Thanks a lot for helping out! Please [let me know](mailto:mail@nlohmann.me) if I forgot someone.
|
||||||
|
|
||||||
|
|||||||
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}")
|
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" ASTYLE_TOOL_VERSION "${ASTYLE_TOOL_VERSION}")
|
||||||
message(STATUS "🔖 Artistic Style ${ASTYLE_TOOL_VERSION} (${ASTYLE_TOOL})")
|
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++-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)
|
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}")
|
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TOOL_VERSION "${CLANG_TOOL_VERSION}")
|
||||||
message(STATUS "🔖 Clang ${CLANG_TOOL_VERSION} (${CLANG_TOOL})")
|
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)
|
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}")
|
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})")
|
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}")
|
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CPPCHECK_TOOL_VERSION "${CPPCHECK_TOOL_VERSION}")
|
||||||
message(STATUS "🔖 Cppcheck ${CPPCHECK_TOOL_VERSION} (${CPPCHECK_TOOL})")
|
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)
|
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}")
|
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" GCC_TOOL_VERSION "${GCC_TOOL_VERSION}")
|
||||||
message(STATUS "🔖 GCC ${GCC_TOOL_VERSION} (${GCC_TOOL})")
|
message(STATUS "🔖 GCC ${GCC_TOOL_VERSION} (${GCC_TOOL})")
|
||||||
@@ -95,6 +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-extra-semi-stmt The library uses std::assert which triggers this warning.
|
||||||
# -Wno-padded We do not care about padding warnings.
|
# -Wno-padded We do not care about padding warnings.
|
||||||
# -Wno-covered-switch-default All switches list all cases and a default case.
|
# -Wno-covered-switch-default All switches list all cases and a default case.
|
||||||
|
# -Wno-unsafe-buffer-usage Otherwise Doctest would not compile.
|
||||||
# -Wno-weak-vtables The library is header-only.
|
# -Wno-weak-vtables The library is header-only.
|
||||||
# -Wreserved-identifier See https://github.com/onqtam/doctest/issues/536.
|
# -Wreserved-identifier See https://github.com/onqtam/doctest/issues/536.
|
||||||
|
|
||||||
@@ -107,6 +108,7 @@ set(CLANG_CXXFLAGS
|
|||||||
-Wno-extra-semi-stmt
|
-Wno-extra-semi-stmt
|
||||||
-Wno-padded
|
-Wno-padded
|
||||||
-Wno-covered-switch-default
|
-Wno-covered-switch-default
|
||||||
|
-Wno-unsafe-buffer-usage
|
||||||
-Wno-weak-vtables
|
-Wno-weak-vtables
|
||||||
-Wno-reserved-identifier
|
-Wno-reserved-identifier
|
||||||
)
|
)
|
||||||
@@ -437,7 +439,7 @@ add_custom_target(ci_test_clang
|
|||||||
# Different C++ Standards.
|
# 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}
|
add_custom_target(ci_test_gcc_cxx${CXX_STANDARD}
|
||||||
COMMAND CXX=${GCC_TOOL} CXXFLAGS="${GCC_CXXFLAGS}" ${CMAKE_COMMAND}
|
COMMAND CXX=${GCC_TOOL} CXXFLAGS="${GCC_CXXFLAGS}" ${CMAKE_COMMAND}
|
||||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||||
@@ -466,7 +468,7 @@ endforeach()
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
add_custom_target(ci_test_noexceptions
|
add_custom_target(ci_test_noexceptions
|
||||||
COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND}
|
COMMAND ${CMAKE_COMMAND}
|
||||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||||
-DJSON_BuildTests=ON -DCMAKE_CXX_FLAGS=-DJSON_NOEXCEPTION -DDOCTEST_TEST_FILTER=--no-throw
|
-DJSON_BuildTests=ON -DCMAKE_CXX_FLAGS=-DJSON_NOEXCEPTION -DDOCTEST_TEST_FILTER=--no-throw
|
||||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_noexceptions
|
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_noexceptions
|
||||||
@@ -480,7 +482,7 @@ add_custom_target(ci_test_noexceptions
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
add_custom_target(ci_test_noimplicitconversions
|
add_custom_target(ci_test_noimplicitconversions
|
||||||
COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND}
|
COMMAND ${CMAKE_COMMAND}
|
||||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||||
-DJSON_BuildTests=ON -DJSON_ImplicitConversions=OFF
|
-DJSON_BuildTests=ON -DJSON_ImplicitConversions=OFF
|
||||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_noimplicitconversions
|
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_noimplicitconversions
|
||||||
@@ -494,7 +496,7 @@ add_custom_target(ci_test_noimplicitconversions
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
add_custom_target(ci_test_diagnostics
|
add_custom_target(ci_test_diagnostics
|
||||||
COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND}
|
COMMAND ${CMAKE_COMMAND}
|
||||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||||
-DJSON_BuildTests=ON -DJSON_Diagnostics=ON
|
-DJSON_BuildTests=ON -DJSON_Diagnostics=ON
|
||||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_diagnostics
|
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_diagnostics
|
||||||
@@ -508,7 +510,7 @@ add_custom_target(ci_test_diagnostics
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
add_custom_target(ci_test_legacycomparison
|
add_custom_target(ci_test_legacycomparison
|
||||||
COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND}
|
COMMAND ${CMAKE_COMMAND}
|
||||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||||
-DJSON_BuildTests=ON -DJSON_LegacyDiscardedValueComparison=ON
|
-DJSON_BuildTests=ON -DJSON_LegacyDiscardedValueComparison=ON
|
||||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_legacycomparison
|
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_legacycomparison
|
||||||
@@ -522,7 +524,7 @@ add_custom_target(ci_test_legacycomparison
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
add_custom_target(ci_test_noglobaludls
|
add_custom_target(ci_test_noglobaludls
|
||||||
COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND}
|
COMMAND ${CMAKE_COMMAND}
|
||||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||||
-DJSON_BuildTests=ON -DJSON_FastTests=ON -DJSON_GlobalUDLs=OFF
|
-DJSON_BuildTests=ON -DJSON_FastTests=ON -DJSON_GlobalUDLs=OFF
|
||||||
-DCMAKE_CXX_FLAGS=-DJSON_TEST_NO_GLOBAL_UDLS
|
-DCMAKE_CXX_FLAGS=-DJSON_TEST_NO_GLOBAL_UDLS
|
||||||
@@ -667,8 +669,11 @@ add_custom_target(ci_cppcheck
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
add_custom_target(ci_cpplint
|
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"
|
COMMENT "Check code with cpplint"
|
||||||
|
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@@ -833,27 +838,17 @@ add_custom_target(ci_benchmarks
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
function(ci_get_cmake version var)
|
function(ci_get_cmake version var)
|
||||||
if (APPLE)
|
set(${var} ${PROJECT_BINARY_DIR}/cmake-${version}/bin/cmake)
|
||||||
set(${var} ${PROJECT_BINARY_DIR}/cmake-${version}-Darwin64/CMake.app/Contents/bin/cmake)
|
add_custom_command(
|
||||||
add_custom_command(
|
OUTPUT ${${var}}
|
||||||
OUTPUT ${${var}}
|
COMMAND wget -nc https://github.com/Kitware/CMake/releases/download/v${version}/cmake-${version}.tar.gz
|
||||||
COMMAND wget -nc https://github.com/Kitware/CMake/releases/download/v${version}/cmake-${version}-Darwin64.tar.gz
|
COMMAND tar xfz cmake-${version}.tar.gz
|
||||||
COMMAND tar xfz cmake-${version}-Darwin64.tar.gz
|
COMMAND rm cmake-${version}.tar.gz
|
||||||
COMMAND rm cmake-${version}-Darwin64.tar.gz
|
COMMAND ${CMAKE_COMMAND} -S cmake-${version} -B cmake-${version}
|
||||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
COMMAND ${CMAKE_COMMAND} --build cmake-${version} --parallel 10
|
||||||
COMMENT "Download CMake ${version}"
|
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} ${${var}} PARENT_SCOPE)
|
set(${var} ${${var}} PARENT_SCOPE)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
@@ -905,15 +900,10 @@ add_custom_target(ci_cmake_flags
|
|||||||
# Use more installed compilers.
|
# 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)
|
||||||
find_program(COMPILER_TOOL NAMES ${COMPILER})
|
find_program(COMPILER_TOOL NAMES ${COMPILER})
|
||||||
if (COMPILER_TOOL)
|
if (COMPILER_TOOL)
|
||||||
if ("${COMPILER}" STREQUAL "clang++-9")
|
unset(ADDITIONAL_FLAGS)
|
||||||
# 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()
|
|
||||||
|
|
||||||
add_custom_target(ci_test_compiler_${COMPILER}
|
add_custom_target(ci_test_compiler_${COMPILER}
|
||||||
COMMAND CXX=${COMPILER} ${CMAKE_COMMAND}
|
COMMAND CXX=${COMPILER} ${CMAKE_COMMAND}
|
||||||
@@ -929,6 +919,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)
|
unset(COMPILER_TOOL CACHE)
|
||||||
endforeach()
|
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
|
# CUDA example
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|||||||
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
|
# check if compiler is targeting 32bit by default
|
||||||
include(CheckTypeSize)
|
include(CheckTypeSize)
|
||||||
check_type_size("size_t" sizeof_size_t LANGUAGE CXX)
|
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.")
|
message(STATUS "Auto-enabling 32bit unit test.")
|
||||||
set(${build_32bit_var} ON)
|
set(${build_32bit_var} ON)
|
||||||
else()
|
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: 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: 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 ('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: 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: Header only', 'Guide', 'integration/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('Integration: Package Managers', 'Guide', 'integration/package_managers/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++",
|
"name": "JSON for Modern C++",
|
||||||
"version": "3.11.2",
|
"version": "3.11.3",
|
||||||
"archive": "JSON_for_Modern_C++.tgz",
|
"archive": "JSON_for_Modern_C++.tgz",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Niels Lohmann",
|
"name": "Niels Lohmann",
|
||||||
|
|||||||
@@ -35,14 +35,13 @@ int main()
|
|||||||
// output the changed array
|
// output the changed array
|
||||||
std::cout << j["array"] << '\n';
|
std::cout << j["array"] << '\n';
|
||||||
|
|
||||||
|
|
||||||
// out_of_range.106
|
// out_of_range.106
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// try to use an array index with leading '0'
|
// try to use an array index with leading '0'
|
||||||
json::reference ref = j.at("/array/01"_json_pointer);
|
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';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
@@ -53,7 +52,7 @@ int main()
|
|||||||
// try to use an array index that is not a number
|
// try to use an array index that is not a number
|
||||||
json::reference ref = j.at("/array/one"_json_pointer);
|
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';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
@@ -64,7 +63,7 @@ int main()
|
|||||||
// try to use an invalid array index
|
// try to use an invalid array index
|
||||||
json::reference ref = j.at("/array/4"_json_pointer);
|
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';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
@@ -75,7 +74,7 @@ int main()
|
|||||||
// try to use the array index '-'
|
// try to use the array index '-'
|
||||||
json::reference ref = j.at("/array/-"_json_pointer);
|
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';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
@@ -86,7 +85,7 @@ int main()
|
|||||||
// try to use a JSON pointer to a nonexistent object key
|
// try to use a JSON pointer to a nonexistent object key
|
||||||
json::const_reference ref = j.at("/foo"_json_pointer);
|
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';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
@@ -97,7 +96,7 @@ int main()
|
|||||||
// try to use a JSON pointer that cannot be resolved
|
// try to use a JSON pointer that cannot be resolved
|
||||||
json::reference ref = j.at("/number/foo"_json_pointer);
|
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';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ int main()
|
|||||||
// try to use an array index that is not a number
|
// try to use an array index that is not a number
|
||||||
json::const_reference ref = j.at("/array/one"_json_pointer);
|
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';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ int main()
|
|||||||
// try to use an invalid array index
|
// try to use an invalid array index
|
||||||
json::const_reference ref = j.at("/array/4"_json_pointer);
|
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';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ int main()
|
|||||||
// try to use the array index '-'
|
// try to use the array index '-'
|
||||||
json::const_reference ref = j.at("/array/-"_json_pointer);
|
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';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
@@ -62,7 +62,7 @@ int main()
|
|||||||
// try to use a JSON pointer to a nonexistent object key
|
// try to use a JSON pointer to a nonexistent object key
|
||||||
json::const_reference ref = j.at("/foo"_json_pointer);
|
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';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ int main()
|
|||||||
// try to use a JSON pointer that cannot be resolved
|
// try to use a JSON pointer that cannot be resolved
|
||||||
json::const_reference ref = j.at("/number/foo"_json_pointer);
|
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';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ int main()
|
|||||||
// output changed array
|
// output changed array
|
||||||
std::cout << object << '\n';
|
std::cout << object << '\n';
|
||||||
|
|
||||||
|
|
||||||
// exception type_error.304
|
// exception type_error.304
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -32,7 +31,7 @@ int main()
|
|||||||
json str = "I am a string";
|
json str = "I am a string";
|
||||||
str.at("the good"sv) = "Another string";
|
str.at("the good"sv) = "Another string";
|
||||||
}
|
}
|
||||||
catch (json::type_error& e)
|
catch (const json::type_error& e)
|
||||||
{
|
{
|
||||||
std::cout << e.what() << '\n';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
@@ -43,7 +42,7 @@ int main()
|
|||||||
// try to write at a nonexisting key using string_view
|
// try to write at a nonexisting key using string_view
|
||||||
object.at("the fast"sv) = "il rapido";
|
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';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ int main()
|
|||||||
// output element with key "the ugly" using string_view
|
// output element with key "the ugly" using string_view
|
||||||
std::cout << object.at("the ugly"sv) << '\n';
|
std::cout << object.at("the ugly"sv) << '\n';
|
||||||
|
|
||||||
|
|
||||||
// exception type_error.304
|
// exception type_error.304
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -26,7 +25,7 @@ int main()
|
|||||||
const json str = "I am a string";
|
const json str = "I am a string";
|
||||||
std::cout << str.at("the good"sv) << '\n';
|
std::cout << str.at("the good"sv) << '\n';
|
||||||
}
|
}
|
||||||
catch (json::type_error& e)
|
catch (const json::type_error& e)
|
||||||
{
|
{
|
||||||
std::cout << e.what() << '\n';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
@@ -37,7 +36,7 @@ int main()
|
|||||||
// try to read from a nonexisting key using string_view
|
// try to read from a nonexisting key using string_view
|
||||||
std::cout << object.at("the fast"sv) << '\n';
|
std::cout << object.at("the fast"sv) << '\n';
|
||||||
}
|
}
|
||||||
catch (json::out_of_range)
|
catch (const json::out_of_range)
|
||||||
{
|
{
|
||||||
std::cout << "out of range" << '\n';
|
std::cout << "out of range" << '\n';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ int main()
|
|||||||
// output changed array
|
// output changed array
|
||||||
std::cout << object << '\n';
|
std::cout << object << '\n';
|
||||||
|
|
||||||
|
|
||||||
// exception type_error.304
|
// exception type_error.304
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -30,7 +29,7 @@ int main()
|
|||||||
json str = "I am a string";
|
json str = "I am a string";
|
||||||
str.at("the good") = "Another string";
|
str.at("the good") = "Another string";
|
||||||
}
|
}
|
||||||
catch (json::type_error& e)
|
catch (const json::type_error& e)
|
||||||
{
|
{
|
||||||
std::cout << e.what() << '\n';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
@@ -41,7 +40,7 @@ int main()
|
|||||||
// try to write at a nonexisting key
|
// try to write at a nonexisting key
|
||||||
object.at("the fast") = "il rapido";
|
object.at("the fast") = "il rapido";
|
||||||
}
|
}
|
||||||
catch (json::out_of_range& e)
|
catch (const json::out_of_range& e)
|
||||||
{
|
{
|
||||||
std::cout << e.what() << '\n';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ int main()
|
|||||||
// output element with key "the ugly"
|
// output element with key "the ugly"
|
||||||
std::cout << object.at("the ugly") << '\n';
|
std::cout << object.at("the ugly") << '\n';
|
||||||
|
|
||||||
|
|
||||||
// exception type_error.304
|
// exception type_error.304
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -24,7 +23,7 @@ int main()
|
|||||||
const json str = "I am a string";
|
const json str = "I am a string";
|
||||||
std::cout << str.at("the good") << '\n';
|
std::cout << str.at("the good") << '\n';
|
||||||
}
|
}
|
||||||
catch (json::type_error& e)
|
catch (const json::type_error& e)
|
||||||
{
|
{
|
||||||
std::cout << e.what() << '\n';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
@@ -35,7 +34,7 @@ int main()
|
|||||||
// try to read from a nonexisting key
|
// try to read from a nonexisting key
|
||||||
std::cout << object.at("the fast") << '\n';
|
std::cout << object.at("the fast") << '\n';
|
||||||
}
|
}
|
||||||
catch (json::out_of_range)
|
catch (const json::out_of_range)
|
||||||
{
|
{
|
||||||
std::cout << "out of range" << '\n';
|
std::cout << "out of range" << '\n';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ int main()
|
|||||||
// output changed array
|
// output changed array
|
||||||
std::cout << array << '\n';
|
std::cout << array << '\n';
|
||||||
|
|
||||||
|
|
||||||
// exception type_error.304
|
// exception type_error.304
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -25,7 +24,7 @@ int main()
|
|||||||
json str = "I am a string";
|
json str = "I am a string";
|
||||||
str.at(0) = "Another string";
|
str.at(0) = "Another string";
|
||||||
}
|
}
|
||||||
catch (json::type_error& e)
|
catch (const json::type_error& e)
|
||||||
{
|
{
|
||||||
std::cout << e.what() << '\n';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
@@ -36,7 +35,7 @@ int main()
|
|||||||
// try to write beyond the array limit
|
// try to write beyond the array limit
|
||||||
array.at(5) = "sixth";
|
array.at(5) = "sixth";
|
||||||
}
|
}
|
||||||
catch (json::out_of_range& e)
|
catch (const json::out_of_range& e)
|
||||||
{
|
{
|
||||||
std::cout << e.what() << '\n';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ int main()
|
|||||||
// output element at index 2 (third element)
|
// output element at index 2 (third element)
|
||||||
std::cout << array.at(2) << '\n';
|
std::cout << array.at(2) << '\n';
|
||||||
|
|
||||||
|
|
||||||
// exception type_error.304
|
// exception type_error.304
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -19,7 +18,7 @@ int main()
|
|||||||
const json str = "I am a string";
|
const json str = "I am a string";
|
||||||
std::cout << str.at(0) << '\n';
|
std::cout << str.at(0) << '\n';
|
||||||
}
|
}
|
||||||
catch (json::type_error& e)
|
catch (const json::type_error& e)
|
||||||
{
|
{
|
||||||
std::cout << e.what() << '\n';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
@@ -30,7 +29,7 @@ int main()
|
|||||||
// try to read beyond the array limit
|
// try to read beyond the array limit
|
||||||
std::cout << array.at(5) << '\n';
|
std::cout << array.at(5) << '\n';
|
||||||
}
|
}
|
||||||
catch (json::out_of_range& e)
|
catch (const json::out_of_range& e)
|
||||||
{
|
{
|
||||||
std::cout << e.what() << '\n';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ int main()
|
|||||||
json j_null;
|
json j_null;
|
||||||
j_null.back();
|
j_null.back();
|
||||||
}
|
}
|
||||||
catch (json::invalid_iterator& e)
|
catch (const json::invalid_iterator& e)
|
||||||
{
|
{
|
||||||
std::cout << e.what() << '\n';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ int main()
|
|||||||
std::cout << j_mmap << '\n';
|
std::cout << j_mmap << '\n';
|
||||||
std::cout << j_ummap << "\n\n";
|
std::cout << j_ummap << "\n\n";
|
||||||
|
|
||||||
|
|
||||||
// ===========
|
// ===========
|
||||||
// array types
|
// array types
|
||||||
// ===========
|
// ===========
|
||||||
@@ -117,7 +116,6 @@ int main()
|
|||||||
std::cout << j_mset << '\n';
|
std::cout << j_mset << '\n';
|
||||||
std::cout << j_umset << "\n\n";
|
std::cout << j_umset << "\n\n";
|
||||||
|
|
||||||
|
|
||||||
// ============
|
// ============
|
||||||
// string types
|
// string types
|
||||||
// ============
|
// ============
|
||||||
@@ -138,7 +136,6 @@ int main()
|
|||||||
std::cout << j_string_literal << '\n';
|
std::cout << j_string_literal << '\n';
|
||||||
std::cout << j_stdstring << "\n\n";
|
std::cout << j_stdstring << "\n\n";
|
||||||
|
|
||||||
|
|
||||||
// ============
|
// ============
|
||||||
// number types
|
// number types
|
||||||
// ============
|
// ============
|
||||||
@@ -203,7 +200,6 @@ int main()
|
|||||||
std::cout << j_float_nan << '\n';
|
std::cout << j_float_nan << '\n';
|
||||||
std::cout << j_double << "\n\n";
|
std::cout << j_double << "\n\n";
|
||||||
|
|
||||||
|
|
||||||
// =============
|
// =============
|
||||||
// boolean types
|
// boolean types
|
||||||
// =============
|
// =============
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ int main()
|
|||||||
{
|
{
|
||||||
json j_invalid(j_number.begin() + 1, j_number.end());
|
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';
|
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);
|
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;
|
std::cout << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ int main()
|
|||||||
// try to use an array index with leading '0'
|
// try to use an array index with leading '0'
|
||||||
j.contains("/array/01"_json_pointer);
|
j.contains("/array/01"_json_pointer);
|
||||||
}
|
}
|
||||||
catch (json::parse_error& e)
|
catch (const json::parse_error& e)
|
||||||
{
|
{
|
||||||
std::cout << e.what() << '\n';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
@@ -36,7 +36,7 @@ int main()
|
|||||||
// try to use an array index that is not a number
|
// try to use an array index that is not a number
|
||||||
j.contains("/array/one"_json_pointer);
|
j.contains("/array/one"_json_pointer);
|
||||||
}
|
}
|
||||||
catch (json::parse_error& e)
|
catch (const json::parse_error& e)
|
||||||
{
|
{
|
||||||
std::cout << e.what() << '\n';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ int main()
|
|||||||
{
|
{
|
||||||
int housenumber = j["address"]["housenumber"];
|
int housenumber = j["address"]["housenumber"];
|
||||||
}
|
}
|
||||||
catch (json::exception& e)
|
catch (const json::exception& e)
|
||||||
{
|
{
|
||||||
std::cout << e.what() << '\n';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ int main()
|
|||||||
{
|
{
|
||||||
int housenumber = j["address"]["housenumber"];
|
int housenumber = j["address"]["housenumber"];
|
||||||
}
|
}
|
||||||
catch (json::exception& e)
|
catch (const json::exception& e)
|
||||||
{
|
{
|
||||||
std::cout << e.what() << '\n';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ int main()
|
|||||||
{
|
{
|
||||||
std::cout << j_invalid.dump() << std::endl;
|
std::cout << j_invalid.dump() << std::endl;
|
||||||
}
|
}
|
||||||
catch (json::type_error& e)
|
catch (const json::type_error& e)
|
||||||
{
|
{
|
||||||
std::cout << e.what() << std::endl;
|
std::cout << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ int main()
|
|||||||
{
|
{
|
||||||
std::cout << j_invalid.dump() << std::endl;
|
std::cout << j_invalid.dump() << std::endl;
|
||||||
}
|
}
|
||||||
catch (json::type_error& e)
|
catch (const json::type_error& e)
|
||||||
{
|
{
|
||||||
std::cout << e.what() << std::endl;
|
std::cout << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ int main()
|
|||||||
json j = {{"foo", "bar"}};
|
json j = {{"foo", "bar"}};
|
||||||
json k = j.at("non-existing");
|
json k = j.at("non-existing");
|
||||||
}
|
}
|
||||||
catch (json::exception& e)
|
catch (const json::exception& e)
|
||||||
{
|
{
|
||||||
// output exception information
|
// output exception information
|
||||||
std::cout << "message: " << e.what() << '\n'
|
std::cout << "message: " << e.what() << '\n'
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ int main()
|
|||||||
j["address"] = "744 Evergreen Terrace";
|
j["address"] = "744 Evergreen Terrace";
|
||||||
j["age"] = 60;
|
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;
|
std::cout << p.name << " (" << p.age << ") lives in " << p.address << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ int main()
|
|||||||
j["address"] = "744 Evergreen Terrace";
|
j["address"] = "744 Evergreen Terrace";
|
||||||
j["age"] = 60;
|
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;
|
std::cout << p.name << " (" << p.age << ") lives in " << p.address << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ int main()
|
|||||||
json value = 17;
|
json value = 17;
|
||||||
|
|
||||||
// explicitly getting pointers
|
// explicitly getting pointers
|
||||||
auto p1 = value.get<const json::number_integer_t*>();
|
auto p1 = value.template get<const json::number_integer_t*>();
|
||||||
auto p2 = value.get<json::number_integer_t*>();
|
auto p2 = value.template get<json::number_integer_t*>();
|
||||||
auto p3 = value.get<json::number_integer_t* const>();
|
auto p3 = value.template get<json::number_integer_t* const>();
|
||||||
auto p4 = value.get<const json::number_integer_t* const>();
|
auto p4 = value.template get<const json::number_integer_t* const>();
|
||||||
auto p5 = value.get<json::number_float_t*>();
|
auto p5 = value.template get<json::number_float_t*>();
|
||||||
|
|
||||||
// print the pointees
|
// print the pointees
|
||||||
std::cout << *p1 << ' ' << *p2 << ' ' << *p3 << ' ' << *p4 << '\n';
|
std::cout << *p1 << ' ' << *p2 << ' ' << *p3 << ' ' << *p4 << '\n';
|
||||||
|
|||||||
@@ -22,14 +22,14 @@ int main()
|
|||||||
};
|
};
|
||||||
|
|
||||||
// use explicit conversions
|
// use explicit conversions
|
||||||
auto v1 = json_types["boolean"].get<bool>();
|
auto v1 = json_types["boolean"].template get<bool>();
|
||||||
auto v2 = json_types["number"]["integer"].get<int>();
|
auto v2 = json_types["number"]["integer"].template get<int>();
|
||||||
auto v3 = json_types["number"]["integer"].get<short>();
|
auto v3 = json_types["number"]["integer"].template get<short>();
|
||||||
auto v4 = json_types["number"]["floating-point"].get<float>();
|
auto v4 = json_types["number"]["floating-point"].template get<float>();
|
||||||
auto v5 = json_types["number"]["floating-point"].get<int>();
|
auto v5 = json_types["number"]["floating-point"].template get<int>();
|
||||||
auto v6 = json_types["string"].get<std::string>();
|
auto v6 = json_types["string"].template get<std::string>();
|
||||||
auto v7 = json_types["array"].get<std::vector<short>>();
|
auto v7 = json_types["array"].template get<std::vector<short>>();
|
||||||
auto v8 = json_types.get<std::unordered_map<std::string, json>>();
|
auto v8 = json_types.template get<std::unordered_map<std::string, json>>();
|
||||||
|
|
||||||
// print the conversion results
|
// print the conversion results
|
||||||
std::cout << v1 << '\n';
|
std::cout << v1 << '\n';
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ int main()
|
|||||||
{
|
{
|
||||||
auto r3 = value.get_ref<json::number_float_t&>();
|
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';
|
std::cout << ex.what() << '\n';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ int main()
|
|||||||
std::vector<short> v7;
|
std::vector<short> v7;
|
||||||
std::unordered_map<std::string, json> v8;
|
std::unordered_map<std::string, json> v8;
|
||||||
|
|
||||||
|
|
||||||
// use explicit conversions
|
// use explicit conversions
|
||||||
json_types["boolean"].get_to(v1);
|
json_types["boolean"].get_to(v1);
|
||||||
json_types["number"]["integer"].get_to(v2);
|
json_types["number"]["integer"].get_to(v2);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ int main()
|
|||||||
json::iterator it = j.begin();
|
json::iterator it = j.begin();
|
||||||
auto k = it.key();
|
auto k = it.key();
|
||||||
}
|
}
|
||||||
catch (json::invalid_iterator& e)
|
catch (const json::invalid_iterator& e)
|
||||||
{
|
{
|
||||||
// output exception information
|
// output exception information
|
||||||
std::cout << "message: " << e.what() << '\n'
|
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");
|
json::json_pointer p9("foo");
|
||||||
}
|
}
|
||||||
catch (json::parse_error& e)
|
catch (const json::parse_error& e)
|
||||||
{
|
{
|
||||||
std::cout << e.what() << '\n';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,7 @@ int main()
|
|||||||
{
|
{
|
||||||
json::json_pointer p10("/foo/~");
|
json::json_pointer p10("/foo/~");
|
||||||
}
|
}
|
||||||
catch (json::parse_error& e)
|
catch (const json::parse_error& e)
|
||||||
{
|
{
|
||||||
std::cout << e.what() << '\n';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ int main()
|
|||||||
{
|
{
|
||||||
json::json_pointer p11("/foo/~3");
|
json::json_pointer p11("/foo/~3");
|
||||||
}
|
}
|
||||||
catch (json::parse_error& e)
|
catch (const json::parse_error& e)
|
||||||
{
|
{
|
||||||
std::cout << e.what() << '\n';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"compiler": {
|
"compiler": {
|
||||||
"c++": "201103",
|
"c++": "201103",
|
||||||
"family": "gcc",
|
"family": "gcc",
|
||||||
"version": "12.1.0"
|
"version": "12.3.0"
|
||||||
},
|
},
|
||||||
"copyright": "(C) 2013-2022 Niels Lohmann",
|
"copyright": "(C) 2013-2022 Niels Lohmann",
|
||||||
"name": "JSON for Modern C++",
|
"name": "JSON for Modern C++",
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
"version": {
|
"version": {
|
||||||
"major": 3,
|
"major": 3,
|
||||||
"minor": 11,
|
"minor": 11,
|
||||||
"patch": 2,
|
"patch": 3,
|
||||||
"string": "3.11.2"
|
"string": "3.11.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,15 +45,15 @@ int main()
|
|||||||
|
|
||||||
// deserialization: json -> person
|
// deserialization: json -> person
|
||||||
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
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:
|
// incomplete deserialization:
|
||||||
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
||||||
try
|
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;
|
std::cout << "deserialization failed: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,15 +33,15 @@ int main()
|
|||||||
|
|
||||||
// deserialization: json -> person
|
// deserialization: json -> person
|
||||||
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
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:
|
// incomplete deserialization:
|
||||||
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
||||||
try
|
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;
|
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
|
// deserialization: json -> person
|
||||||
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
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:
|
// incomplete deserialization:
|
||||||
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
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;
|
std::cout << "roundtrip: " << json(p3) << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,10 +33,10 @@ int main()
|
|||||||
|
|
||||||
// deserialization: json -> person
|
// deserialization: json -> person
|
||||||
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
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:
|
// incomplete deserialization:
|
||||||
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
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;
|
std::cout << "roundtrip: " << json(p3) << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,15 +38,15 @@ int main()
|
|||||||
|
|
||||||
// deserialization: json -> person
|
// deserialization: json -> person
|
||||||
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
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:
|
// incomplete deserialization:
|
||||||
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
||||||
try
|
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;
|
std::cout << "deserialization failed: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,15 +26,15 @@ int main()
|
|||||||
|
|
||||||
// deserialization: json -> person
|
// deserialization: json -> person
|
||||||
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
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:
|
// incomplete deserialization:
|
||||||
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
||||||
try
|
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;
|
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
|
// deserialization: json -> person
|
||||||
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
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:
|
// incomplete deserialization:
|
||||||
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
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;
|
std::cout << "roundtrip: " << json(p3) << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ int main()
|
|||||||
|
|
||||||
// deserialization: json -> person
|
// deserialization: json -> person
|
||||||
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
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:
|
// incomplete deserialization:
|
||||||
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
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;
|
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
|
// deserialization
|
||||||
json j_running = "running";
|
json j_running = "running";
|
||||||
json j_blue = "blue";
|
json j_blue = "blue";
|
||||||
auto running = j_running.get<ns::TaskState>();
|
auto running = j_running.template get<ns::TaskState>();
|
||||||
auto blue = j_blue.get<ns::Color>();
|
auto blue = j_blue.template get<ns::Color>();
|
||||||
std::cout << j_running << " -> " << running
|
std::cout << j_running << " -> " << running
|
||||||
<< ", " << j_blue << " -> " << static_cast<int>(blue) << std::endl;
|
<< ", " << j_blue << " -> " << static_cast<int>(blue) << std::endl;
|
||||||
|
|
||||||
// deserializing undefined JSON value to enum
|
// deserializing undefined JSON value to enum
|
||||||
// (where the first map entry above is the default)
|
// (where the first map entry above is the default)
|
||||||
json j_pi = 3.14;
|
json j_pi = 3.14;
|
||||||
auto invalid = j_pi.get<ns::TaskState>();
|
auto invalid = j_pi.template get<ns::TaskState>();
|
||||||
auto unknown = j_pi.get<ns::Color>();
|
auto unknown = j_pi.template get<ns::Color>();
|
||||||
std::cout << j_pi << " -> " << invalid << ", "
|
std::cout << j_pi << " -> " << invalid << ", "
|
||||||
<< j_pi << " -> " << static_cast<int>(unknown) << std::endl;
|
<< j_pi << " -> " << static_cast<int>(unknown) << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ int main()
|
|||||||
|
|
||||||
// deserialization
|
// deserialization
|
||||||
json j_rot = "rot";
|
json j_rot = "rot";
|
||||||
auto rot = j_rot.get<ns::Color>();
|
auto rot = j_rot.template get<ns::Color>();
|
||||||
auto red = j_red.get<ns::Color>();
|
auto red = j_red.template get<ns::Color>();
|
||||||
std::cout << j_rot << " -> " << static_cast<int>(rot) << std::endl;
|
std::cout << j_rot << " -> " << static_cast<int>(rot) << std::endl;
|
||||||
std::cout << j_red << " -> " << static_cast<int>(red) << 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
|
// can only create an object from a list of pairs
|
||||||
json j_invalid_object = json::object({{ "one", 1, 2 }});
|
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';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ int main()
|
|||||||
{
|
{
|
||||||
bool v1 = json_types["string"];
|
bool v1 = json_types["string"];
|
||||||
}
|
}
|
||||||
catch (json::type_error& e)
|
catch (const json::type_error& e)
|
||||||
{
|
{
|
||||||
std::cout << e.what() << '\n';
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ int main()
|
|||||||
json string = "foo";
|
json string = "foo";
|
||||||
json discarded = json(json::value_t::discarded);
|
json discarded = json(json::value_t::discarded);
|
||||||
|
|
||||||
|
|
||||||
// output values and comparisons
|
// output values and comparisons
|
||||||
std::cout << array_1 << " <=> " << array_2 << " := " << to_string(array_1 <=> array_2) << '\n'; // *NOPAD*
|
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*
|
std::cout << object_1 << " <=> " << object_2 << " := " << to_string(object_1 <=> object_2) << '\n'; // *NOPAD*
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ int main()
|
|||||||
json number = 17;
|
json number = 17;
|
||||||
json string = "17";
|
json string = "17";
|
||||||
|
|
||||||
|
|
||||||
// output values and comparisons
|
// output values and comparisons
|
||||||
std::cout << std::boolalpha << std::fixed;
|
std::cout << std::boolalpha << std::fixed;
|
||||||
std::cout << boolean << " <=> " << true << " := " << to_string(boolean <=> true) << '\n'; // *NOPAD*
|
std::cout << boolean << " <=> " << true << " := " << to_string(boolean <=> true) << '\n'; // *NOPAD*
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ int main()
|
|||||||
}])"_json;
|
}])"_json;
|
||||||
value.patch(patch);
|
value.patch(patch);
|
||||||
}
|
}
|
||||||
catch (json::other_error& e)
|
catch (const json::other_error& e)
|
||||||
{
|
{
|
||||||
// output exception information
|
// output exception information
|
||||||
std::cout << "message: " << e.what() << '\n'
|
std::cout << "message: " << e.what() << '\n'
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ int main()
|
|||||||
json j = {1, 2, 3, 4};
|
json j = {1, 2, 3, 4};
|
||||||
j.at(4) = 10;
|
j.at(4) = 10;
|
||||||
}
|
}
|
||||||
catch (json::out_of_range& e)
|
catch (const json::out_of_range& e)
|
||||||
{
|
{
|
||||||
// output exception information
|
// output exception information
|
||||||
std::cout << "message: " << e.what() << '\n'
|
std::cout << "message: " << e.what() << '\n'
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ int main()
|
|||||||
{
|
{
|
||||||
json j = json::parse(text);
|
json j = json::parse(text);
|
||||||
}
|
}
|
||||||
catch (json::parse_error& e)
|
catch (const json::parse_error& e)
|
||||||
{
|
{
|
||||||
std::cout << e.what() << std::endl;
|
std::cout << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ int main()
|
|||||||
json j_complete = json::parse(ss);
|
json j_complete = json::parse(ss);
|
||||||
std::cout << std::setw(4) << j_complete << "\n\n";
|
std::cout << std::setw(4) << j_complete << "\n\n";
|
||||||
|
|
||||||
|
|
||||||
// define parser callback
|
// define parser callback
|
||||||
json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed)
|
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);
|
json j_complete = json::parse(text);
|
||||||
std::cout << std::setw(4) << j_complete << "\n\n";
|
std::cout << std::setw(4) << j_complete << "\n\n";
|
||||||
|
|
||||||
|
|
||||||
// define parser callback
|
// define parser callback
|
||||||
json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed)
|
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
|
// parsing input with a syntax error
|
||||||
json::parse("[1,2,3,]");
|
json::parse("[1,2,3,]");
|
||||||
}
|
}
|
||||||
catch (json::parse_error& e)
|
catch (const json::parse_error& e)
|
||||||
{
|
{
|
||||||
// output exception information
|
// output exception information
|
||||||
std::cout << "message: " << e.what() << '\n'
|
std::cout << "message: " << e.what() << '\n'
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ int main()
|
|||||||
json j = "string";
|
json j = "string";
|
||||||
j.push_back("another string");
|
j.push_back("another string");
|
||||||
}
|
}
|
||||||
catch (json::type_error& e)
|
catch (const json::type_error& e)
|
||||||
{
|
{
|
||||||
// output exception information
|
// output exception information
|
||||||
std::cout << "message: " << e.what() << '\n'
|
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:
|
clean:
|
||||||
rm -fr docs/images/json.gif docs/examples
|
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
|
publish: prepare_files
|
||||||
venv/bin/mkdocs gh-deploy --clean --force
|
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> {}))
|
-> 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).
|
class (either explicitly or via the conversion operators).
|
||||||
|
|
||||||
1. This function is chosen for default-constructible value types.
|
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"
|
??? 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
|
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
|
```cpp
|
||||||
--8<-- "examples/from_json__default_constructible.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())
|
-> 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
|
## Parameters
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ constructor.
|
|||||||
|
|
||||||
## See also
|
## See also
|
||||||
|
|
||||||
[List of exceptions](127.0.0.1:8000/home/exceptions/)
|
[List of exceptions](../../home/exceptions.md)
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ template<
|
|||||||
class NumberFloatType = double,
|
class NumberFloatType = double,
|
||||||
template<typename U> class AllocatorType = std::allocator,
|
template<typename U> class AllocatorType = std::allocator,
|
||||||
template<typename T, typename SFINAE = void> class JSONSerializer = adl_serializer,
|
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;
|
class basic_json;
|
||||||
```
|
```
|
||||||
@@ -32,6 +33,7 @@ class basic_json;
|
|||||||
| `AllocatorType` | type of the allocator to use | |
|
| `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) |
|
| `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) |
|
| `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
|
## 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
|
- [EqualityComparable](https://en.cppreference.com/w/cpp/named_req/EqualityComparable): JSON values can be compared with
|
||||||
`==`, see [`operator==`](operator_eq.md).
|
`==`, see [`operator==`](operator_eq.md).
|
||||||
- [LessThanComparable](https://en.cppreference.com/w/cpp/named_req/LessThanComparable): JSON values can be compared with
|
- [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
|
- [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`.
|
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
|
- [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
|
## 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
|
- [**value_t**](value_t.md) - the JSON type enumeration
|
||||||
- [**json_pointer**](../json_pointer/index.md) - JSON Pointer implementation
|
- [**json_pointer**](../json_pointer/index.md) - JSON Pointer implementation
|
||||||
- [**json_serializer**](json_serializer.md) - type of the serializer to for conversions from/to JSON
|
- [**json_serializer**](json_serializer.md) - type of the serializer to for conversions from/to JSON
|
||||||
|
|||||||
45
docs/mkdocs/docs/api/basic_json/json_base_class_t.md
Normal file
45
docs/mkdocs/docs/api/basic_json/json_base_class_t.md
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
# <small>nlohmann::basic_json::</small>json_base_class_t
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
using json_base_class_t = detail::json_base_class<CustomBaseClass>;
|
||||||
|
```
|
||||||
|
|
||||||
|
The base class used to inject custom functionality into each instance of `basic_json`.
|
||||||
|
Examples of such functionality might be metadata, additional member functions (e.g., visitors), or other application-specific code.
|
||||||
|
|
||||||
|
## Template parameters
|
||||||
|
|
||||||
|
`CustomBaseClass`
|
||||||
|
: the base class to be added to `basic_json`
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
#### Default type
|
||||||
|
|
||||||
|
The default value for `CustomBaseClass` is `void`. In this case an
|
||||||
|
[empty base class](https://en.cppreference.com/w/cpp/language/ebo) is used and no additional functionality is injected.
|
||||||
|
|
||||||
|
#### Limitations
|
||||||
|
|
||||||
|
The type `CustomBaseClass` has to be a default-constructible class.
|
||||||
|
`basic_json` only supports copy/move construction/assignment if `CustomBaseClass` does so as well.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The following code shows how to inject custom data and methods for each node.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/json_base_class_t.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```json
|
||||||
|
--8<-- "examples/json_base_class_t.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.12.0.
|
||||||
@@ -17,7 +17,7 @@ using json_serializer = JSONSerializer<T, SFINAE>;
|
|||||||
|
|
||||||
#### Default type
|
#### Default type
|
||||||
|
|
||||||
The default values for `json_serializer` is [`adl_serializer`](../adl_serializer).
|
The default values for `json_serializer` is [`adl_serializer`](../adl_serializer/index.md).
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user