mirror of
https://github.com/nlohmann/json.git
synced 2026-10-10 00:17:13 +00:00
Compare commits
129
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
55ff4c9eff | ||
|
|
633eef8494 | ||
|
|
e5f84e1ebf | ||
|
|
7fc3a7d87e | ||
|
|
43b689b9b6 | ||
|
|
b5378e8deb | ||
|
|
ce87157d4e | ||
|
|
cdf52ae9be | ||
|
|
146ba55453 | ||
|
|
e6978ba50c | ||
|
|
6285225fd0 | ||
|
|
21af527e75 | ||
|
|
23518f54fe | ||
|
|
1c136a66c4 | ||
|
|
c1c19a7bcd | ||
|
|
bacdabd176 | ||
|
|
d5647e6a3b | ||
|
|
9a091d2b82 | ||
|
|
b890b4cba3 | ||
|
|
dca9d49a33 | ||
|
|
acd87e2336 | ||
|
|
a13902a33f | ||
|
|
c021a09b08 | ||
|
|
e4aaf46d38 | ||
|
|
ad94fb01cc | ||
|
|
c2e1cc50e0 | ||
|
|
173f2a7407 | ||
|
|
1c63a120b6 | ||
|
|
85889e8843 | ||
|
|
3c0a9a99fd | ||
|
|
e82724d87f | ||
|
|
5bc24e876b | ||
|
|
78821cd9c2 | ||
|
|
68f0722a19 | ||
|
|
5f121d8c50 | ||
|
|
585929bff9 | ||
|
|
31ba5208c8 | ||
|
|
da7b9bdb3d | ||
|
|
634f49bc5b | ||
|
|
2222d386c9 | ||
|
|
eaedec859a | ||
|
|
d94cbd99dc | ||
|
|
bc48951128 | ||
|
|
fd72ecfc8c | ||
|
|
de8a099ba5 | ||
|
|
dd24e2dffd | ||
|
|
868506dcc0 | ||
|
|
58ce09dcfd | ||
|
|
8dacb98041 | ||
|
|
2e23687092 | ||
|
|
227c5cdfb1 | ||
|
|
0832fd1cb4 | ||
|
|
8ec98e2c9e | ||
|
|
88b28ac43c | ||
|
|
e0c3c819e1 | ||
|
|
06ac77f4fd | ||
|
|
dfa51af692 | ||
|
|
d0d29039da | ||
|
|
9a3ebb9456 | ||
|
|
3296a3ad8c | ||
|
|
3565f40229 | ||
|
|
1c5a953de5 | ||
|
|
a03e65420c | ||
|
|
d6ede37088 | ||
|
|
722c03495f | ||
|
|
c197feff81 | ||
|
|
b2b47c69b1 | ||
|
|
6a406ee141 | ||
|
|
ca76c37650 | ||
|
|
fe2bcc080f | ||
|
|
c60217e801 | ||
|
|
6ba332c7df | ||
|
|
e9c3985f0a | ||
|
|
b630f5e9c7 | ||
|
|
4d8e7a7210 | ||
|
|
75e8fbac32 | ||
|
|
631e667fe5 | ||
|
|
d0a43141ea | ||
|
|
ecff144b3a | ||
|
|
855f511db4 | ||
|
|
d0de6a9111 | ||
|
|
f8e99e856c | ||
|
|
521a084827 | ||
|
|
ca91678af1 | ||
|
|
ff34a3fd2f | ||
|
|
fe0299545a | ||
|
|
366f3d26e5 | ||
|
|
7c9208bfb3 | ||
|
|
bb60941f0e | ||
|
|
3b0dd69928 | ||
|
|
c05c5e229b | ||
|
|
acf076a677 | ||
|
|
33edc9751c | ||
|
|
83c87cb9e0 | ||
|
|
eed1587000 | ||
|
|
c034480c22 | ||
|
|
899cf31255 | ||
|
|
c363dc3e4d | ||
|
|
972f5cc10b | ||
|
|
518c5c887a | ||
|
|
c944317002 | ||
|
|
31dd15b258 | ||
|
|
8d7e0046f4 | ||
|
|
ca49ab6123 | ||
|
|
730b57775d | ||
|
|
272411c5e6 | ||
|
|
adf78d3a76 | ||
|
|
b7566c6293 | ||
|
|
c5b2b26fdc | ||
|
|
c37f82e563 | ||
|
|
25c58ac6bd | ||
|
|
87f1eb436e | ||
|
|
969333b1cc | ||
|
|
fc1df0b7db | ||
|
|
02dfbea39d | ||
|
|
a5f8e230ac | ||
|
|
d8ebaf61d7 | ||
|
|
a39f33b951 | ||
|
|
e4bdf1be72 | ||
|
|
d10879bca8 | ||
|
|
484483acad | ||
|
|
584e6b1cfb | ||
|
|
a69a42a930 | ||
|
|
77388b95fc | ||
|
|
e054d4df94 | ||
|
|
d96329f8d6 | ||
|
|
1d7688aef2 | ||
|
|
58cfecf7f7 | ||
|
|
47202c804a |
No files matched your search
+8
-8
@@ -3,15 +3,15 @@ arm_container:
|
|||||||
|
|
||||||
check_task:
|
check_task:
|
||||||
check_script:
|
check_script:
|
||||||
- wget https://github.com/Kitware/CMake/releases/download/v3.20.2/cmake-3.20.2.tar.gz
|
# the gcc image ships an outdated CMake, so fetch a recent prebuilt binary
|
||||||
- tar xfz cmake-3.20.2.tar.gz
|
# instead of compiling CMake from source
|
||||||
- cd cmake-3.20.2
|
- wget -q https://github.com/Kitware/CMake/releases/download/v4.3.4/cmake-4.3.4-linux-aarch64.tar.gz
|
||||||
- ./configure
|
- tar xfz cmake-4.3.4-linux-aarch64.tar.gz
|
||||||
- make cmake ctest -j4
|
- export PATH="$(pwd)/cmake-4.3.4-linux-aarch64/bin:$PATH"
|
||||||
- cd ..
|
- cmake --version
|
||||||
- mkdir build
|
- mkdir build
|
||||||
- cd build
|
- cd build
|
||||||
- ../cmake-3.20.2/bin/cmake .. -DJSON_FastTests=ON
|
- cmake .. -DJSON_FastTests=ON
|
||||||
- make -j4
|
- make -j4
|
||||||
- cd tests
|
- cd tests
|
||||||
- ../../cmake-3.20.2/bin/ctest -j4
|
- ctest -j4
|
||||||
@@ -15,6 +15,14 @@ guidance.
|
|||||||
|
|
||||||
For vulnerabilities in third-party dependencies or modules, please report them directly to the respective maintainers.
|
For vulnerabilities in third-party dependencies or modules, please report them directly to the respective maintainers.
|
||||||
|
|
||||||
|
## Unofficial packages
|
||||||
|
|
||||||
|
This project does not publish an official npm package. The npm package
|
||||||
|
[`nlohmann-json`](https://www.npmjs.com/package/nlohmann-json) (or similarly named packages) is not maintained or
|
||||||
|
endorsed by this project. See the
|
||||||
|
[package managers documentation](https://json.nlohmann.me/integration/package_managers/#npm) for supported
|
||||||
|
integration options.
|
||||||
|
|
||||||
## Additional Resources
|
## Additional Resources
|
||||||
|
|
||||||
- Explore security-related topics and contribute to tools and projects through
|
- Explore security-related topics and contribute to tools and projects through
|
||||||
|
|||||||
+1
-1
@@ -13,7 +13,7 @@ sentimentBotReplyComment: >
|
|||||||
|
|
||||||
# *Required* Comment to reply with
|
# *Required* Comment to reply with
|
||||||
requestInfoReplyComment: >
|
requestInfoReplyComment: >
|
||||||
We would appreciate it if you could provide us with more info about this issue or pull request! Please check the [issue template](https://github.com/nlohmann/json/blob/develop/.github/ISSUE_TEMPLATE.md) and the [pull request template](https://github.com/nlohmann/json/blob/develop/.github/PULL_REQUEST_TEMPLATE.md).
|
We would appreciate it if you could provide us with more info about this issue or pull request! Please check the [issue template](https://github.com/nlohmann/json/issues/new/choose) and the [pull request template](https://github.com/nlohmann/json/blob/develop/.github/PULL_REQUEST_TEMPLATE.md).
|
||||||
|
|
||||||
# *OPTIONAL* Label to be added to Issues and Pull Requests with insufficient information given
|
# *OPTIONAL* Label to be added to Issues and Pull Requests with insufficient information given
|
||||||
requestInfoLabelToAdd: "state: needs more info"
|
requestInfoLabelToAdd: "state: needs more info"
|
||||||
|
|||||||
@@ -4,28 +4,44 @@ updates:
|
|||||||
directory: /
|
directory: /
|
||||||
schedule:
|
schedule:
|
||||||
interval: daily
|
interval: daily
|
||||||
|
cooldown:
|
||||||
|
default-days: 7
|
||||||
|
groups:
|
||||||
|
codeql-action:
|
||||||
|
patterns:
|
||||||
|
- "github/codeql-action/*"
|
||||||
|
|
||||||
- package-ecosystem: pip
|
- package-ecosystem: pip
|
||||||
directory: /docs/mkdocs
|
directory: /docs/mkdocs
|
||||||
schedule:
|
schedule:
|
||||||
interval: daily
|
interval: daily
|
||||||
|
cooldown:
|
||||||
|
default-days: 7
|
||||||
|
|
||||||
- package-ecosystem: pip
|
- package-ecosystem: pip
|
||||||
directory: /tools/astyle
|
directory: /tools/astyle
|
||||||
schedule:
|
schedule:
|
||||||
interval: daily
|
interval: daily
|
||||||
|
cooldown:
|
||||||
|
default-days: 7
|
||||||
|
|
||||||
- package-ecosystem: pip
|
- package-ecosystem: pip
|
||||||
directory: /tools/generate_natvis
|
directory: /tools/generate_natvis
|
||||||
schedule:
|
schedule:
|
||||||
interval: daily
|
interval: daily
|
||||||
|
cooldown:
|
||||||
|
default-days: 7
|
||||||
|
|
||||||
- package-ecosystem: pip
|
- package-ecosystem: pip
|
||||||
directory: /tools/serve_header
|
directory: /tools/serve_header
|
||||||
schedule:
|
schedule:
|
||||||
interval: daily
|
interval: daily
|
||||||
|
cooldown:
|
||||||
|
default-days: 7
|
||||||
|
|
||||||
- package-ecosystem: pip
|
- package-ecosystem: pip
|
||||||
directory: /cmake/requirements
|
directory: /cmake/requirements
|
||||||
schedule:
|
schedule:
|
||||||
interval: daily
|
interval: daily
|
||||||
|
cooldown:
|
||||||
|
default-days: 7
|
||||||
+2
-2
@@ -23,11 +23,11 @@ labels:
|
|||||||
|
|
||||||
- label: "CI"
|
- label: "CI"
|
||||||
files:
|
files:
|
||||||
- "github/workflows/.*"
|
- ".github/workflows/.*"
|
||||||
|
|
||||||
- label: "CI"
|
- label: "CI"
|
||||||
files:
|
files:
|
||||||
- "github/external_ci/.*"
|
- ".github/external_ci/.*"
|
||||||
|
|
||||||
- label: "S"
|
- label: "S"
|
||||||
size-below: 10
|
size-below: 10
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@ab7a9404c0f3da075243ca237b5fac12c98deaa5 # v2.19.3
|
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
@@ -34,43 +34,65 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@ab7a9404c0f3da075243ca237b5fac12c98deaa5 # v2.19.3
|
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: Checkout pull request
|
- name: Checkout pull request
|
||||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
path: main
|
path: main
|
||||||
ref: ${{ github.event.pull_request.head.sha }}
|
ref: ${{ github.event.pull_request.head.sha }}
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
- name: Checkout tools
|
- name: Checkout tools
|
||||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
path: tools
|
path: tools
|
||||||
ref: develop
|
ref: develop
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
- name: Install astyle
|
- name: Install astyle
|
||||||
run: |
|
run: |
|
||||||
python3 -mvenv venv
|
python3 -mvenv venv
|
||||||
venv/bin/pip3 install -r $MAIN_DIR/tools/astyle/requirements.txt
|
venv/bin/pip3 install -r $MAIN_DIR/tools/astyle/requirements.txt
|
||||||
|
|
||||||
- name: Check amalgamation
|
- name: Regenerate amalgamation and formatting
|
||||||
run: |
|
run: |
|
||||||
cd $MAIN_DIR
|
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.json -s .
|
||||||
python3 $TOOL_DIR/amalgamate.py -c $TOOL_DIR/config_json_fwd.json -s .
|
python3 $TOOL_DIR/amalgamate.py -c $TOOL_DIR/config_json_fwd.json -s .
|
||||||
echo "Format (1)"
|
|
||||||
${{ github.workspace }}/venv/bin/astyle --project=tools/astyle/.astylerc --suffix=none --quiet $INCLUDE_DIR/json.hpp $INCLUDE_DIR/json_fwd.hpp
|
|
||||||
|
|
||||||
diff $INCLUDE_DIR/json.hpp~ $INCLUDE_DIR/json.hpp
|
${{ github.workspace }}/venv/bin/astyle --project=tools/astyle/.astylerc --suffix=none --quiet \
|
||||||
diff $INCLUDE_DIR/json_fwd.hpp~ $INCLUDE_DIR/json_fwd.hpp
|
$INCLUDE_DIR/json.hpp $INCLUDE_DIR/json_fwd.hpp
|
||||||
|
|
||||||
${{ github.workspace }}/venv/bin/astyle --project=tools/astyle/.astylerc --suffix=orig $(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)
|
${{ github.workspace }}/venv/bin/astyle --project=tools/astyle/.astylerc --suffix=none --quiet \
|
||||||
echo Check
|
$(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)
|
||||||
find $MAIN_DIR -name '*.orig' -exec false {} \+
|
|
||||||
|
- name: Build patch and check for differences
|
||||||
|
id: diff
|
||||||
|
run: |
|
||||||
|
cd $MAIN_DIR
|
||||||
|
mkdir -p ${{ github.workspace }}/patch
|
||||||
|
git diff --patch --no-color > ${{ github.workspace }}/patch/amalgamation.patch
|
||||||
|
if [ -s ${{ github.workspace }}/patch/amalgamation.patch ]; then
|
||||||
|
echo "The source code has not been amalgamated/formatted correctly. Diff:"
|
||||||
|
cat ${{ github.workspace }}/patch/amalgamation.patch
|
||||||
|
echo "has_diff=true" >> "$GITHUB_OUTPUT"
|
||||||
|
else
|
||||||
|
echo "has_diff=false" >> "$GITHUB_OUTPUT"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Uploaded so contributors can fix their PR with `git apply amalgamation.patch`
|
||||||
|
# instead of installing the pinned astyle version locally.
|
||||||
|
- name: Upload patch
|
||||||
|
if: steps.diff.outputs.has_diff == 'true'
|
||||||
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||||
|
with:
|
||||||
|
name: amalgamation-patch
|
||||||
|
path: patch/amalgamation.patch
|
||||||
|
|
||||||
|
- name: Fail if not amalgamated/formatted
|
||||||
|
if: steps.diff.outputs.has_diff == 'true'
|
||||||
|
run: exit 1
|
||||||
@@ -9,10 +9,13 @@ jobs:
|
|||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@ab7a9404c0f3da075243ca237b5fac12c98deaa5 # v2.19.3
|
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
# The OSS-Fuzz CIFuzz actions are referenced via @master as recommended by
|
||||||
|
# the OSS-Fuzz documentation; the project does not publish tags or releases
|
||||||
|
# to pin to. See https://google.github.io/oss-fuzz/getting-started/continuous-integration/
|
||||||
- name: Build Fuzzers
|
- name: Build Fuzzers
|
||||||
id: build
|
id: build
|
||||||
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
|
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
|
||||||
|
|||||||
@@ -27,23 +27,25 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@ab7a9404c0f3da075243ca237b5fac12c98deaa5 # v2.19.3
|
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@9e0d7b8d25671d64c341c19c0152d693099fb5ba # v4.35.5
|
uses: github/codeql-action/init@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
|
||||||
with:
|
with:
|
||||||
languages: c-cpp
|
languages: c-cpp
|
||||||
|
|
||||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
# If this step fails, then you should remove it and run the build manually (see below)
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
- name: Autobuild
|
- name: Autobuild
|
||||||
uses: github/codeql-action/autobuild@9e0d7b8d25671d64c341c19c0152d693099fb5ba # v4.35.5
|
uses: github/codeql-action/autobuild@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@9e0d7b8d25671d64c341c19c0152d693099fb5ba # v4.35.5
|
uses: github/codeql-action/analyze@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
|
||||||
@@ -19,11 +19,12 @@ jobs:
|
|||||||
pull-requests: write
|
pull-requests: write
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@ab7a9404c0f3da075243ca237b5fac12c98deaa5 # v2.19.3
|
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: 'Download artifact'
|
- name: 'Download artifact'
|
||||||
|
id: download
|
||||||
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
|
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
@@ -43,7 +44,13 @@ jobs:
|
|||||||
});
|
});
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
|
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
|
||||||
- run: unzip pr.zip
|
|
||||||
|
var hasPatch = artifacts.data.artifacts.some((artifact) => artifact.name == "amalgamation-patch");
|
||||||
|
core.setOutput('has_patch', String(hasPatch));
|
||||||
|
# Extract the untrusted PR artifact into a dedicated empty directory and
|
||||||
|
# read only the two expected files by fixed path afterwards. This avoids a
|
||||||
|
# malicious archive overwriting workspace files or escaping via ../ paths.
|
||||||
|
- run: unzip -o pr.zip -d ./pr_artifact
|
||||||
|
|
||||||
- name: 'Comment on PR'
|
- name: 'Comment on PR'
|
||||||
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
|
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
|
||||||
@@ -51,8 +58,19 @@ jobs:
|
|||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
script: |
|
script: |
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
const author = fs.readFileSync('./author')
|
// Both values come from a fork-triggered workflow and are therefore
|
||||||
const issue_number = Number(fs.readFileSync('./number'));
|
// attacker-controlled. Validate them strictly before use to prevent
|
||||||
|
// Markdown/mention injection and bogus REST API filters.
|
||||||
|
const author = fs.readFileSync('./pr_artifact/author', 'utf8').trim();
|
||||||
|
if (!/^[A-Za-z0-9-]{1,39}$/.test(author)) {
|
||||||
|
core.setFailed(`Refusing to proceed: untrusted author value '${author}' is not a valid GitHub username.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const issue_number = Number(fs.readFileSync('./pr_artifact/number', 'utf8').trim());
|
||||||
|
if (!Number.isInteger(issue_number) || issue_number <= 0) {
|
||||||
|
core.setFailed('Refusing to proceed: untrusted PR number is not a positive integer.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
const opts = github.rest.issues.listForRepo.endpoint.merge({
|
const opts = github.rest.issues.listForRepo.endpoint.merge({
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
repo: context.repo.repo,
|
repo: context.repo.repo,
|
||||||
@@ -70,12 +88,20 @@ jobs:
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const hasPatch = '${{ steps.download.outputs.has_patch }}' === 'true';
|
||||||
|
const runUrl = '${{ github.event.workflow_run.html_url }}';
|
||||||
|
|
||||||
await github.rest.issues.createComment({
|
await github.rest.issues.createComment({
|
||||||
issue_number: issue_number,
|
issue_number: issue_number,
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
repo: context.repo.repo,
|
repo: context.repo.repo,
|
||||||
body: '## 🔴 Amalgamation check failed! 🔴\nThe source code has not been amalgamated.'
|
body: '## 🔴 Amalgamation check failed! 🔴\nThe source code has not been amalgamated and/or formatted correctly.'
|
||||||
+ (first ? ' @' + author + ' Please read and follow the [Contribution Guidelines]'
|
+ (hasPatch ? '\n\n📎 A ready-to-apply patch is attached to the [failed workflow run](' + runUrl + ') as the `amalgamation-patch` artifact.'
|
||||||
|
+ ' Download it, then apply it locally from the repository root with:'
|
||||||
|
+ '\n\n```shell\ngit apply amalgamation.patch\n```\n\n'
|
||||||
|
+ 'This does not require installing astyle yourself.'
|
||||||
|
: '')
|
||||||
|
+ (first ? '\n\n@' + author + ' Please read and follow the [Contribution Guidelines]'
|
||||||
+ '(https://github.com/nlohmann/json/blob/develop/.github/CONTRIBUTING.md#files-to-change).'
|
+ '(https://github.com/nlohmann/json/blob/develop/.github/CONTRIBUTING.md#files-to-change).'
|
||||||
: '')
|
: '')
|
||||||
})
|
})
|
||||||
@@ -17,11 +17,13 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@ab7a9404c0f3da075243ca237b5fac12c98deaa5 # v2.19.3
|
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: 'Checkout Repository'
|
- name: 'Checkout Repository'
|
||||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
- name: 'Dependency Review'
|
- name: 'Dependency Review'
|
||||||
uses: actions/dependency-review-action@a1d282b36b6f3519aa1f3fc636f609c47dddb294 # v5.0.0
|
uses: actions/dependency-review-action@a1d282b36b6f3519aa1f3fc636f609c47dddb294 # v5.0.0
|
||||||
@@ -27,20 +27,22 @@ jobs:
|
|||||||
security-events: write
|
security-events: write
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@ab7a9404c0f3da075243ca237b5fac12c98deaa5 # v2.19.3
|
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
- name: flawfinder_scan
|
- name: flawfinder_scan
|
||||||
uses: david-a-wheeler/flawfinder@c57197cd6061453f10a496f30a732bc1905918d1 # v2.0.19
|
uses: david-a-wheeler/flawfinder@c4216b74cf2639ffa98503768bd6e4299b5440c9 # v2.0.20
|
||||||
with:
|
with:
|
||||||
arguments: '--sarif ./'
|
arguments: '--sarif ./'
|
||||||
output: 'flawfinder_results.sarif'
|
output: 'flawfinder_results.sarif'
|
||||||
|
|
||||||
- name: Upload analysis results to GitHub Security tab
|
- name: Upload analysis results to GitHub Security tab
|
||||||
uses: github/codeql-action/upload-sarif@9e0d7b8d25671d64c341c19c0152d693099fb5ba # v4
|
uses: github/codeql-action/upload-sarif@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
|
||||||
with:
|
with:
|
||||||
sarif_file: ${{github.workspace}}/flawfinder_results.sarif
|
sarif_file: ${{github.workspace}}/flawfinder_results.sarif
|
||||||
@@ -17,10 +17,10 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@ab7a9404c0f3da075243ca237b5fac12c98deaa5 # v2.19.3
|
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- uses: srvaroa/labeler@e8fbb2561481ef6e711a770f0234e9379dc76892 # master
|
- uses: srvaroa/labeler@bf262763a8a8e191f5847873aecc0f29df84f957 # v1.14.0
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
|
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
@@ -17,60 +17,6 @@ permissions:
|
|||||||
contents: read
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# macos-11 is deprecated
|
|
||||||
# macos-11:
|
|
||||||
# runs-on: macos-11
|
|
||||||
# strategy:
|
|
||||||
# matrix:
|
|
||||||
# xcode: ['11.7', '12.4', '12.5.1', '13.0']
|
|
||||||
# env:
|
|
||||||
# DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
|
||||||
#
|
|
||||||
# steps:
|
|
||||||
# - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
||||||
# - name: Run CMake
|
|
||||||
# run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON
|
|
||||||
# - name: Build
|
|
||||||
# run: cmake --build build --parallel 10
|
|
||||||
# - name: Test
|
|
||||||
# run: cd build ; ctest -j 10 --output-on-failure
|
|
||||||
|
|
||||||
# macos-12 is deprecated (https://github.com/actions/runner-images/issues/10721)
|
|
||||||
# macos-12:
|
|
||||||
# runs-on: macos-12 # https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md
|
|
||||||
# strategy:
|
|
||||||
# matrix:
|
|
||||||
# xcode: ['13.1', '13.2.1', '13.3.1', '13.4.1', '14.0', '14.0.1', '14.1']
|
|
||||||
# env:
|
|
||||||
# DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
|
||||||
#
|
|
||||||
# steps:
|
|
||||||
# - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
||||||
# - name: Run CMake
|
|
||||||
# run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON
|
|
||||||
# - name: Build
|
|
||||||
# run: cmake --build build --parallel 10
|
|
||||||
# - name: Test
|
|
||||||
# run: cd build ; ctest -j 10 --output-on-failure
|
|
||||||
|
|
||||||
# macos-13 is deprecated (https://github.com/actions/runner-images/issues/13046)
|
|
||||||
# macos-13:
|
|
||||||
# runs-on: macos-13 # https://github.com/actions/runner-images/blob/main/images/macos/macos-13-Readme.md
|
|
||||||
# strategy:
|
|
||||||
# matrix:
|
|
||||||
# xcode: ['14.1', '14.2', '14.3', '14.3.1', '15.0.1', '15.1', '15.2']
|
|
||||||
# env:
|
|
||||||
# DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
|
||||||
#
|
|
||||||
# steps:
|
|
||||||
# - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
||||||
# - name: Run CMake
|
|
||||||
# run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON
|
|
||||||
# - name: Build
|
|
||||||
# run: cmake --build build --parallel 10
|
|
||||||
# - name: Test
|
|
||||||
# run: cd build ; ctest -j 10 --output-on-failure
|
|
||||||
|
|
||||||
macos-14:
|
macos-14:
|
||||||
runs-on: macos-14 # https://github.com/actions/runner-images/blob/main/images/macos/macos-14-Readme.md
|
runs-on: macos-14 # https://github.com/actions/runner-images/blob/main/images/macos/macos-14-Readme.md
|
||||||
strategy:
|
strategy:
|
||||||
@@ -80,7 +26,9 @@ jobs:
|
|||||||
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON
|
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -97,7 +45,9 @@ jobs:
|
|||||||
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON
|
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -112,7 +62,9 @@ jobs:
|
|||||||
standard: [11, 14, 17, 20, 23, 26]
|
standard: [11, 14, 17, 20, 23, 26]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_TestStandards=${{ matrix.standard }}
|
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_TestStandards=${{ matrix.standard }}
|
||||||
- name: Build
|
- name: Build
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ jobs:
|
|||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@ab7a9404c0f3da075243ca237b5fac12c98deaa5 # v2.19.3
|
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
|
||||||
- name: Install virtual environment
|
- name: Install virtual environment
|
||||||
run: make install_venv -C docs/mkdocs
|
run: make install_venv -C docs/mkdocs
|
||||||
|
|||||||
@@ -36,17 +36,17 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@ab7a9404c0f3da075243ca237b5fac12c98deaa5 # v2.19.3
|
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: "Checkout code"
|
- name: "Checkout code"
|
||||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
- name: "Run analysis"
|
- name: "Run analysis"
|
||||||
uses: ossf/scorecard-action@4eaacf0543bb3f2c246792bd56e8cdeffafb205a # v2.4.3
|
uses: ossf/scorecard-action@2d1146689b8cda280b9bc96326124645441f03bc # v2.4.4
|
||||||
with:
|
with:
|
||||||
results_file: results.sarif
|
results_file: results.sarif
|
||||||
results_format: sarif
|
results_format: sarif
|
||||||
@@ -76,6 +76,6 @@ jobs:
|
|||||||
|
|
||||||
# Upload the results to GitHub's code scanning dashboard.
|
# Upload the results to GitHub's code scanning dashboard.
|
||||||
- name: "Upload to code-scanning"
|
- name: "Upload to code-scanning"
|
||||||
uses: github/codeql-action/upload-sarif@9e0d7b8d25671d64c341c19c0152d693099fb5ba # v4.35.5
|
uses: github/codeql-action/upload-sarif@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
|
||||||
with:
|
with:
|
||||||
sarif_file: results.sarif
|
sarif_file: results.sarif
|
||||||
@@ -32,23 +32,36 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@ab7a9404c0f3da075243ca237b5fac12c98deaa5 # v2.19.3
|
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
# Checkout project source
|
# Checkout project source
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
|
||||||
# Scan code using project's configuration on https://semgrep.dev/manage
|
|
||||||
- uses: returntocorp/semgrep-action@713efdd345f3035192eaa63f56867b88e63e4e5d
|
|
||||||
with:
|
with:
|
||||||
publishToken: ${{ secrets.SEMGREP_APP_TOKEN }}
|
persist-credentials: false
|
||||||
publishDeployment: ${{ secrets.SEMGREP_DEPLOYMENT_ID }}
|
|
||||||
generateSarif: "1"
|
# The former returntocorp/semgrep-action is deprecated (the org was renamed
|
||||||
|
# to semgrep/*); the maintained approach is to install the CLI and invoke
|
||||||
|
# it directly. We use `semgrep scan` (not `semgrep ci`, which requires a
|
||||||
|
# login token): with no SEMGREP_APP_TOKEN configured this is exactly what
|
||||||
|
# the old action fell back to, running community rules with no token.
|
||||||
|
# SEMGREP_APP_TOKEN is still passed through so registry auth works if a
|
||||||
|
# token is ever added.
|
||||||
|
- name: Install Semgrep
|
||||||
|
run: python3 -m pip install --user semgrep==1.168.0
|
||||||
|
|
||||||
|
# `semgrep scan --sarif` always exits 0 even with findings; continue-on-error
|
||||||
|
# is a safety net so the SARIF upload still runs if the scan itself errors.
|
||||||
|
- name: Run Semgrep
|
||||||
|
run: semgrep scan --config auto --sarif --output=semgrep.sarif
|
||||||
|
continue-on-error: true
|
||||||
|
env:
|
||||||
|
SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }}
|
||||||
|
|
||||||
# Upload SARIF file generated in previous step
|
# Upload SARIF file generated in previous step
|
||||||
- name: Upload SARIF file
|
- name: Upload SARIF file
|
||||||
uses: github/codeql-action/upload-sarif@9e0d7b8d25671d64c341c19c0152d693099fb5ba # v4
|
uses: github/codeql-action/upload-sarif@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
|
||||||
with:
|
with:
|
||||||
sarif_file: semgrep.sarif
|
sarif_file: semgrep.sarif
|
||||||
if: always()
|
if: always()
|
||||||
@@ -16,11 +16,11 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@ab7a9404c0f3da075243ca237b5fac12c98deaa5 # v2.19.3
|
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- uses: actions/stale@b5d41d4e1d5dceea10e7104786b73624c18a190f # v10.2.0
|
- uses: actions/stale@4391f3da665fdf50b6810c1a66712fb9ba21aa93 # v11.0.0
|
||||||
with:
|
with:
|
||||||
stale-issue-label: 'state: stale'
|
stale-issue-label: 'state: stale'
|
||||||
stale-pr-label: 'state: stale'
|
stale-pr-label: 'state: stale'
|
||||||
|
|||||||
+162
-40
@@ -21,9 +21,11 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: gcc:latest
|
container: gcc:latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@7bfc9baacbbdcb5e37957ad05c3546b3e222be3c # v4.3.2
|
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||||
- 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
|
||||||
@@ -31,9 +33,21 @@ jobs:
|
|||||||
|
|
||||||
ci_infer:
|
ci_infer:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- name: Harden Runner
|
||||||
|
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
||||||
|
with:
|
||||||
|
egress-policy: audit
|
||||||
|
|
||||||
|
- name: Install Infer
|
||||||
|
run: |
|
||||||
|
wget -q -O - "https://github.com/facebook/infer/releases/download/v1.3.0/infer-linux-x86_64-v1.3.0.tar.xz" | sudo tar -C /opt -xJ
|
||||||
|
sudo ln -s /opt/infer-linux-x86_64-v1.3.0/bin/infer /usr/local/bin/infer
|
||||||
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Get latest CMake and ninja
|
||||||
|
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -46,15 +60,17 @@ jobs:
|
|||||||
target: [ci_test_amalgamation, ci_test_single_header, ci_cppcheck, ci_cpplint, ci_reproducible_tests, ci_non_git_tests, ci_offline_testdata, ci_reuse_compliance, ci_test_valgrind]
|
target: [ci_test_amalgamation, ci_test_single_header, ci_cppcheck, ci_cpplint, ci_reproducible_tests, ci_non_git_tests, ci_offline_testdata, ci_reuse_compliance, ci_test_valgrind]
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@ab7a9404c0f3da075243ca237b5fac12c98deaa5 # v2.19.3
|
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: Install Valgrind
|
- name: Install Valgrind
|
||||||
run: sudo apt-get update ; sudo apt-get install -y valgrind
|
run: sudo apt-get update ; sudo apt-get install -y valgrind
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@7bfc9baacbbdcb5e37957ad05c3546b3e222be3c # v4.3.2
|
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||||
- 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
|
||||||
@@ -69,9 +85,11 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Install git, clang-tools, iwyu (ci_single_binaries), and unzip
|
- name: Install git, clang-tools, iwyu (ci_single_binaries), and unzip
|
||||||
run: apt-get update ; apt-get install -y git clang-tools iwyu unzip
|
run: apt-get update ; apt-get install -y git clang-tools iwyu unzip
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@7bfc9baacbbdcb5e37957ad05c3546b3e222be3c # v4.3.2
|
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||||
- 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
|
||||||
@@ -86,9 +104,11 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Install build-essential
|
- name: Install build-essential
|
||||||
run: apt-get update ; apt-get install -y build-essential unzip wget git libssl-dev
|
run: apt-get update ; apt-get install -y build-essential unzip wget git libssl-dev
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@7bfc9baacbbdcb5e37957ad05c3546b3e222be3c # v4.3.2
|
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -98,11 +118,13 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@ab7a9404c0f3da075243ca237b5fac12c98deaa5 # v2.19.3
|
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
- name: Install dependencies and de_DE locale
|
- name: Install dependencies and de_DE locale
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get clean
|
sudo apt-get clean
|
||||||
@@ -120,7 +142,7 @@ jobs:
|
|||||||
name: code-coverage-report
|
name: code-coverage-report
|
||||||
path: ${{ github.workspace }}/build/html
|
path: ${{ github.workspace }}/build/html
|
||||||
- name: Publish report to Coveralls
|
- name: Publish report to Coveralls
|
||||||
uses: coverallsapp/github-action@5cbfd81b66ca5d10c19b062c04de0199c215fb6e # v2.3.7
|
uses: coverallsapp/github-action@8d6379e14d29928660c4ba802d8e85393440b329 # v2.3.8
|
||||||
with:
|
with:
|
||||||
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
|
||||||
@@ -131,9 +153,38 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
compiler: ['4.8', '4.9', '5', '6']
|
compiler: ['4.8', '4.9', '5', '6']
|
||||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
# official gcc:4.8/4.9/5/6 images fail to check out code (too old for
|
||||||
|
# actions/checkout); install the old compilers on top of official ubuntu:20.04
|
||||||
|
# instead, mirroring what the (now retired) custom json-ci image did.
|
||||||
|
container: ubuntu:20.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- name: Install g++-${{ matrix.compiler }}
|
||||||
|
run: |
|
||||||
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y --no-install-recommends software-properties-common ca-certificates gnupg make git
|
||||||
|
# add-apt-repository resolves the PPA through the Launchpad API,
|
||||||
|
# which intermittently times out or fails the team lookup (the plain
|
||||||
|
# "deb ..." sources below never hit Launchpad and never flake).
|
||||||
|
# Retry with backoff so a transient Launchpad blip does not fail CI.
|
||||||
|
for attempt in 1 2 3 4 5; do
|
||||||
|
add-apt-repository -y ppa:ubuntu-toolchain-r/test && break
|
||||||
|
echo "::warning::add-apt-repository ppa:ubuntu-toolchain-r/test failed (attempt ${attempt}/5); retrying"
|
||||||
|
sleep $((attempt * 10))
|
||||||
|
done
|
||||||
|
apt-add-repository -y "deb http://archive.ubuntu.com/ubuntu/ bionic main"
|
||||||
|
apt-add-repository -y "deb http://archive.ubuntu.com/ubuntu/ bionic universe"
|
||||||
|
apt-add-repository -y "deb http://archive.ubuntu.com/ubuntu/ xenial main"
|
||||||
|
apt-add-repository -y "deb http://archive.ubuntu.com/ubuntu/ xenial universe"
|
||||||
|
apt-add-repository -y "deb http://archive.ubuntu.com/ubuntu/ xenial-updates main"
|
||||||
|
apt-add-repository -y "deb http://archive.ubuntu.com/ubuntu/ xenial-updates universe"
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y --no-install-recommends g++-${{ matrix.compiler }}
|
||||||
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Get latest CMake and ninja
|
||||||
|
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: CXX=g++-${{ matrix.compiler }} cmake -S . -B build -DJSON_CI=On
|
run: CXX=g++-${{ matrix.compiler }} cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -147,9 +198,11 @@ jobs:
|
|||||||
compiler: ['7', '8', '9', '10', '11', '12', '13', '14', '15', 'latest']
|
compiler: ['7', '8', '9', '10', '11', '12', '13', '14', '15', 'latest']
|
||||||
container: gcc:${{ matrix.compiler }}
|
container: gcc:${{ matrix.compiler }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@7bfc9baacbbdcb5e37957ad05c3546b3e222be3c # v4.3.2
|
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||||
- 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
|
||||||
@@ -159,12 +212,14 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
compiler: ['3.4', '3.5', '3.6', '3.7', '3.8', '3.9', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15-bullseye', '16', '17', '18', '19', '20', 'latest']
|
compiler: ['3.4', '3.5', '3.6', '3.7', '3.8', '3.9', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15-bullseye', '16', '17', '18', '19', '20', '21', '22', 'latest']
|
||||||
container: silkeh/clang:${{ matrix.compiler }}
|
container: silkeh/clang:${{ matrix.compiler }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@7bfc9baacbbdcb5e37957ad05c3546b3e222be3c # v4.3.2
|
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||||
- name: Set env FORCE_STDCPPFS_FLAG for clang 7 / 8 / 9 / 10
|
- name: Set env FORCE_STDCPPFS_FLAG for clang 7 / 8 / 9 / 10
|
||||||
run: echo "JSON_FORCED_GLOBAL_COMPILE_OPTIONS=-DJSON_HAS_FILESYSTEM=0;-DJSON_HAS_EXPERIMENTAL_FILESYSTEM=0" >> "$GITHUB_ENV"
|
run: echo "JSON_FORCED_GLOBAL_COMPILE_OPTIONS=-DJSON_HAS_FILESYSTEM=0;-DJSON_HAS_EXPERIMENTAL_FILESYSTEM=0" >> "$GITHUB_ENV"
|
||||||
if: ${{ matrix.compiler == '7' || matrix.compiler == '8' || matrix.compiler == '9' || matrix.compiler == '10' }}
|
if: ${{ matrix.compiler == '7' || matrix.compiler == '8' || matrix.compiler == '9' || matrix.compiler == '10' }}
|
||||||
@@ -180,9 +235,11 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
standard: [11, 14, 17, 20, 23, 26]
|
standard: [11, 14, 17, 20, 23, 26]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@7bfc9baacbbdcb5e37957ad05c3546b3e222be3c # v4.3.2
|
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||||
- 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
|
||||||
@@ -198,9 +255,11 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Install git and unzip
|
- name: Install git and unzip
|
||||||
run: apt-get update ; apt-get install -y git unzip
|
run: apt-get update ; apt-get install -y git unzip
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@7bfc9baacbbdcb5e37957ad05c3546b3e222be3c # v4.3.2
|
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build with libc++
|
- name: Build with libc++
|
||||||
@@ -212,9 +271,22 @@ jobs:
|
|||||||
|
|
||||||
ci_cuda_example:
|
ci_cuda_example:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
# 11.8.0: newest pre-C++20 CUDA release, exercises the C++17 fallback
|
||||||
|
# path (tests/cuda_example/CMakeLists.txt picks the standard per nvcc
|
||||||
|
# version); 12.1.1: permanent regression guard for #3907 (nvcc 12.0/12.1
|
||||||
|
# choke on enable_borrowed_range at C++20, fixed in 12.2); 12.6.3: recent
|
||||||
|
# CUDA/C++20 coverage.
|
||||||
|
cuda: ['11.8.0', '12.1.1', '12.6.3']
|
||||||
|
container: nvidia/cuda:${{ matrix.cuda }}-devel-ubuntu22.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Get latest CMake and ninja
|
||||||
|
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||||
- 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
|
||||||
@@ -227,9 +299,24 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: ${{ matrix.container }}
|
container: ${{ matrix.container }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
- name: Get latest CMake and ninja
|
with:
|
||||||
uses: lukka/get-cmake@7bfc9baacbbdcb5e37957ad05c3546b3e222be3c # v4.3.2
|
persist-credentials: false
|
||||||
|
# The module test uses `import std;`, which needs CMake's experimental
|
||||||
|
# import-std support. Its opt-in token is CMake-version-specific, so pin
|
||||||
|
# CMake to the version whose token is set in tests/module_cpp20/CMakeLists.txt.
|
||||||
|
- name: Get pinned CMake and ninja
|
||||||
|
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||||
|
with:
|
||||||
|
cmakeVersion: 4.3.4
|
||||||
|
# Clang: the std library module is provided by libc++ (the image's libstdc++
|
||||||
|
# ships none), and the image's libc++ module manifest has a broken relative
|
||||||
|
# path — repoint it at the real module sources.
|
||||||
|
- name: Use libc++ and fix its module manifest path (Clang)
|
||||||
|
if: matrix.container == 'silkeh/clang:latest'
|
||||||
|
run: |
|
||||||
|
echo "CXXFLAGS=-stdlib=libc++" >> "$GITHUB_ENV"
|
||||||
|
mkdir -p /usr/lib/share && ln -sf /usr/lib/llvm-*/share/libc++ /usr/lib/share/libc++
|
||||||
- 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
|
||||||
@@ -237,29 +324,62 @@ jobs:
|
|||||||
|
|
||||||
ci_icpc:
|
ci_icpc:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: ghcr.io/nlohmann/json-ci:v2.2.0
|
# Intel discontinued the classic icc/icpc compiler in oneAPI 2024.0; this is
|
||||||
|
# Intel's own last officially published image that still includes it.
|
||||||
|
container: intel/oneapi-hpckit:2023.2.1-devel-ubuntu22.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Get latest CMake and ninja
|
||||||
|
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||||
- 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: |
|
# No need to source setvars.sh here: unlike the old custom image, this
|
||||||
. /opt/intel/oneapi/setvars.sh
|
# official image already has the oneAPI environment (icc/icpc on PATH)
|
||||||
cmake --build build --target ci_icpc
|
# baked in, and re-sourcing it fails with "already been run" (exit 3).
|
||||||
|
run: cmake --build build --target ci_icpc
|
||||||
|
|
||||||
|
ci_icpx:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: intel/oneapi-hpckit:latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
- name: Get latest CMake and ninja
|
||||||
|
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||||
|
- name: Run CMake
|
||||||
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
|
- name: Build
|
||||||
|
run: cmake --build build --target ci_icpx
|
||||||
|
|
||||||
|
ci_nvhpc:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: nvcr.io/nvidia/nvhpc:25.5-devel-cuda12.9-ubuntu22.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
- name: Get latest CMake and ninja
|
||||||
|
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||||
|
- name: Run CMake
|
||||||
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
|
- name: Build
|
||||||
|
run: cmake --build build --target ci_nvhpc
|
||||||
|
|
||||||
ci_emscripten:
|
ci_emscripten:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@ab7a9404c0f3da075243ca237b5fac12c98deaa5 # v2.19.3
|
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: Install emscripten
|
- name: Install emscripten
|
||||||
uses: mymindstorm/setup-emsdk@4528d102f7230f0e7b276855c01ea1159be0e984 # v16
|
uses: mymindstorm/setup-emsdk@4528d102f7230f0e7b276855c01ea1159be0e984 # v16
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@7bfc9baacbbdcb5e37957ad05c3546b3e222be3c # v4.3.2
|
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=$EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -GNinja
|
run: cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=$EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -GNinja
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -272,11 +392,13 @@ jobs:
|
|||||||
target: [ci_test_examples, ci_test_build_documentation]
|
target: [ci_test_examples, ci_test_build_documentation]
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@ab7a9404c0f3da075243ca237b5fac12c98deaa5 # v2.19.3
|
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
- 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
|
||||||
|
|||||||
@@ -24,7 +24,9 @@ jobs:
|
|||||||
architecture: [x64, x86]
|
architecture: [x64, x86]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
- name: Set up MinGW
|
- name: Set up MinGW
|
||||||
uses: egor-tensin/setup-mingw@41b837e47d7f85214629d255b9c4bc3fcbe9fd63 # v3.0
|
uses: egor-tensin/setup-mingw@41b837e47d7f85214629d255b9c4bc3fcbe9fd63 # v3.0
|
||||||
with:
|
with:
|
||||||
@@ -47,7 +49,9 @@ jobs:
|
|||||||
runs-on: windows-2022
|
runs-on: windows-2022
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
- name: Set extra CXX_FLAGS for latest std_version
|
- name: Set extra CXX_FLAGS for latest std_version
|
||||||
id: cxxflags
|
id: cxxflags
|
||||||
run: |
|
run: |
|
||||||
@@ -70,6 +74,68 @@ jobs:
|
|||||||
- name: Test
|
- name: Test
|
||||||
run: cd build ; ctest -j 10 -C ${{ matrix.build_type }} --output-on-failure
|
run: cd build ; ctest -j 10 -C ${{ matrix.build_type }} --output-on-failure
|
||||||
|
|
||||||
|
# Visual Studio 2026 (v145 toolset) on the windows-2025 image. The "Visual Studio
|
||||||
|
# 18 2026" generator requires CMake 4.2+, so a recent CMake is fetched explicitly.
|
||||||
|
msvc-vs2026:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
build_type: [Debug, Release]
|
||||||
|
architecture: [Win32, x64]
|
||||||
|
std_version: [default, latest]
|
||||||
|
|
||||||
|
runs-on: windows-2025
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
- name: Get latest CMake and ninja
|
||||||
|
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||||
|
- name: Set extra CXX_FLAGS for latest std_version
|
||||||
|
# /wd5285 silences C5285 emitted by the bundled third-party doctest.h, which
|
||||||
|
# specializes std::tuple (newly diagnosed by the VS2026 v145 toolset)
|
||||||
|
run: |
|
||||||
|
if [ "${{ matrix.std_version }}" = "latest" ]; then
|
||||||
|
echo "flags=/permissive- /std:c++latest /utf-8 /W4 /WX /wd5285" >> $GITHUB_ENV
|
||||||
|
else
|
||||||
|
echo "flags=/W4 /WX /wd5285" >> $GITHUB_ENV
|
||||||
|
fi
|
||||||
|
shell: bash
|
||||||
|
- name: Run CMake (Release)
|
||||||
|
run: cmake -S . -B build -G "Visual Studio 18 2026" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="$env:flags"
|
||||||
|
if: matrix.build_type == 'Release'
|
||||||
|
shell: pwsh
|
||||||
|
- name: Run CMake (Debug)
|
||||||
|
run: cmake -S . -B build -G "Visual Studio 18 2026" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DJSON_FastTests=ON -DCMAKE_CXX_FLAGS="$env:flags"
|
||||||
|
if: matrix.build_type == 'Debug'
|
||||||
|
shell: pwsh
|
||||||
|
- name: Build
|
||||||
|
run: cmake --build build --config ${{ matrix.build_type }} --parallel 10
|
||||||
|
- name: Test
|
||||||
|
run: cd build ; ctest -j 10 -C ${{ matrix.build_type }} --output-on-failure
|
||||||
|
|
||||||
|
# Native ARM64 Windows runner with the MSVC ARM64 toolset. The windows-11-arm
|
||||||
|
# label is only available for public repositories.
|
||||||
|
msvc-arm64:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
build_type: [Debug, Release]
|
||||||
|
|
||||||
|
runs-on: windows-11-arm
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
- name: Run CMake (Release)
|
||||||
|
run: cmake -S . -B build -G "Visual Studio 17 2022" -A ARM64 -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/W4 /WX"
|
||||||
|
if: matrix.build_type == 'Release'
|
||||||
|
shell: pwsh
|
||||||
|
- name: Run CMake (Debug)
|
||||||
|
run: cmake -S . -B build -G "Visual Studio 17 2022" -A ARM64 -DJSON_BuildTests=On -DJSON_FastTests=ON -DCMAKE_CXX_FLAGS="/W4 /WX"
|
||||||
|
if: matrix.build_type == 'Debug'
|
||||||
|
shell: pwsh
|
||||||
|
- name: Build
|
||||||
|
run: cmake --build build --config ${{ matrix.build_type }} --parallel 10
|
||||||
|
- name: Test
|
||||||
|
run: cd build ; ctest -j 10 -C ${{ matrix.build_type }} --output-on-failure
|
||||||
|
|
||||||
clang:
|
clang:
|
||||||
runs-on: windows-2022
|
runs-on: windows-2022
|
||||||
strategy:
|
strategy:
|
||||||
@@ -77,7 +143,9 @@ jobs:
|
|||||||
version: [11.0.1, 12.0.1, 13.0.1, 14.0.6, 15.0.7, 16.0.6, 18.1.8, 19.1.7, 20.1.8]
|
version: [11.0.1, 12.0.1, 13.0.1, 14.0.6, 15.0.7, 16.0.6, 18.1.8, 19.1.7, 20.1.8]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
- name: Install Clang
|
- name: Install Clang
|
||||||
run: curl -fsSL -o LLVM${{ matrix.version }}.exe https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ matrix.version }}/LLVM-${{ matrix.version }}-win64.exe ; 7z x LLVM${{ matrix.version }}.exe -y -o"C:/Program Files/LLVM"
|
run: curl -fsSL -o LLVM${{ matrix.version }}.exe https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ matrix.version }}/LLVM-${{ matrix.version }}-win64.exe ; 7z x LLVM${{ matrix.version }}.exe -y -o"C:/Program Files/LLVM"
|
||||||
- name: Set up MinGW
|
- name: Set up MinGW
|
||||||
@@ -85,10 +153,16 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
platform: x64
|
platform: x64
|
||||||
version: 12.2.0 # https://github.com/egor-tensin/setup-mingw/issues/14
|
version: 12.2.0 # https://github.com/egor-tensin/setup-mingw/issues/14
|
||||||
|
# CMAKE_CXX_FLAGS_DEBUG is overridden to drop the default -g: linking
|
||||||
|
# test-regression2_cpp20 intermittently fails with "relocation truncated
|
||||||
|
# to fit: IMAGE_REL_AMD64_SECREL against `.debug_line'" because the
|
||||||
|
# MinGW linker cannot relocate the debug sections this test produces.
|
||||||
|
# The tests are only built and run here, so the debug info is not used.
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build ^
|
run: cmake -S . -B build ^
|
||||||
-DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang++.exe" ^
|
-DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang++.exe" ^
|
||||||
-DCMAKE_CXX_FLAGS="--target=x86_64-w64-mingw32 -stdlib=libstdc++ -pthread" ^
|
-DCMAKE_CXX_FLAGS="--target=x86_64-w64-mingw32 -stdlib=libstdc++ -pthread" ^
|
||||||
|
-DCMAKE_CXX_FLAGS_DEBUG="-g0" ^
|
||||||
-DCMAKE_EXE_LINKER_FLAGS="-lwinpthread" ^
|
-DCMAKE_EXE_LINKER_FLAGS="-lwinpthread" ^
|
||||||
-G"MinGW Makefiles" ^
|
-G"MinGW Makefiles" ^
|
||||||
-DCMAKE_BUILD_TYPE=Debug ^
|
-DCMAKE_BUILD_TYPE=Debug ^
|
||||||
@@ -105,7 +179,9 @@ jobs:
|
|||||||
architecture: [Win32, x64]
|
architecture: [Win32, x64]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -G "Visual Studio 17 2022" -A ${{ matrix.architecture }} -T ClangCL -DJSON_BuildTests=On
|
run: cmake -S . -B build -G "Visual Studio 17 2022" -A ${{ matrix.architecture }} -T ClangCL -DJSON_BuildTests=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -114,9 +190,18 @@ jobs:
|
|||||||
run: cd build ; ctest -j 10 -C Debug --exclude-regex "test-unicode" --output-on-failure
|
run: cd build ; ctest -j 10 -C Debug --exclude-regex "test-unicode" --output-on-failure
|
||||||
|
|
||||||
ci_module_cpp20:
|
ci_module_cpp20:
|
||||||
runs-on: windows-latest
|
runs-on: windows-2022
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
# The module test uses `import std;`, which needs CMake's experimental
|
||||||
|
# import-std support. Its opt-in token is CMake-version-specific, so pin
|
||||||
|
# CMake to the version whose token is set in tests/module_cpp20/CMakeLists.txt.
|
||||||
|
- name: Get pinned CMake and ninja
|
||||||
|
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||||
|
with:
|
||||||
|
cmakeVersion: 4.3.4
|
||||||
- name: Run CMake (Debug)
|
- name: Run CMake (Debug)
|
||||||
run: cmake -S . -B build -G "Visual Studio 17 2022" -DJSON_CI=ON -DCMAKE_CXX_FLAGS="/permissive- /std:c++latest /utf-8 /W4 /WX"
|
run: cmake -S . -B build -G "Visual Studio 17 2022" -DJSON_CI=ON -DCMAKE_CXX_FLAGS="/permissive- /std:c++latest /utf-8 /W4 /WX"
|
||||||
- name: Build
|
- name: Build
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ Files: include/nlohmann/thirdparty/hedley.hpp
|
|||||||
Copyright: 2016-2021 Evan Nemerson <evan@nemerson.com>
|
Copyright: 2016-2021 Evan Nemerson <evan@nemerson.com>
|
||||||
License: CC0
|
License: CC0
|
||||||
|
|
||||||
|
Files: include/nlohmann/detail/meta/cpp_future.hpp
|
||||||
|
Copyright: 2013-2026 Niels Lohmann <https://nlohmann.me> and 2018 The Abseil Authors
|
||||||
|
License: MIT AND Apache-2.0
|
||||||
|
|
||||||
Files: tests/thirdparty/doctest/*
|
Files: tests/thirdparty/doctest/*
|
||||||
Copyright: 2016-2023 Viktor Kirilov
|
Copyright: 2016-2023 Viktor Kirilov
|
||||||
License: MIT
|
License: MIT
|
||||||
|
|||||||
+13
-12
@@ -20,7 +20,11 @@ endif()
|
|||||||
##
|
##
|
||||||
##
|
##
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
|
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
|
||||||
include(ExternalProject)
|
|
||||||
|
if (POLICY CMP0077)
|
||||||
|
# Allow CMake 3.13+ to override options when using FetchContent / add_subdirectory.
|
||||||
|
cmake_policy(SET CMP0077 NEW)
|
||||||
|
endif ()
|
||||||
|
|
||||||
# ---- C++ Modules Support (optional) ----
|
# ---- C++ Modules Support (optional) ----
|
||||||
option(NLOHMANN_JSON_BUILD_MODULES "Build C++ modules support" OFF)
|
option(NLOHMANN_JSON_BUILD_MODULES "Build C++ modules support" OFF)
|
||||||
@@ -38,12 +42,7 @@ endif()
|
|||||||
## OPTIONS
|
## OPTIONS
|
||||||
##
|
##
|
||||||
|
|
||||||
if (POLICY CMP0077)
|
# VERSION_GREATER_EQUAL is not available in older CMake (< 3.7)
|
||||||
# Allow CMake 3.13+ to override options when using FetchContent / add_subdirectory.
|
|
||||||
cmake_policy(SET CMP0077 NEW)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
# VERSION_GREATER_EQUAL is not available in CMake 3.1
|
|
||||||
if(${MAIN_PROJECT} AND (${CMAKE_VERSION} VERSION_EQUAL 3.13 OR ${CMAKE_VERSION} VERSION_GREATER 3.13))
|
if(${MAIN_PROJECT} AND (${CMAKE_VERSION} VERSION_EQUAL 3.13 OR ${CMAKE_VERSION} VERSION_GREATER 3.13))
|
||||||
set(JSON_BuildTests_INIT ON)
|
set(JSON_BuildTests_INIT ON)
|
||||||
else()
|
else()
|
||||||
@@ -98,7 +97,7 @@ if (NOT JSON_ImplicitConversions)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (JSON_DisableEnumSerialization)
|
if (JSON_DisableEnumSerialization)
|
||||||
message(STATUS "Enum integer serialization is disabled (JSON_DISABLE_ENUM_SERIALIZATION=0)")
|
message(STATUS "Enum integer serialization is disabled (JSON_DISABLE_ENUM_SERIALIZATION=1)")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (JSON_LegacyDiscardedValueComparison)
|
if (JSON_LegacyDiscardedValueComparison)
|
||||||
@@ -164,7 +163,7 @@ if (MSVC)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Install a pkg-config file, so other tools can find this.
|
# Install a pkg-config file, so other tools can find this.
|
||||||
CONFIGURE_FILE(
|
configure_file(
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/pkg-config.pc.in"
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/pkg-config.pc.in"
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
|
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
|
||||||
@ONLY
|
@ONLY
|
||||||
@@ -174,9 +173,11 @@ CONFIGURE_FILE(
|
|||||||
## TESTS
|
## TESTS
|
||||||
## create and configure the unit test target
|
## create and configure the unit test target
|
||||||
##
|
##
|
||||||
if (JSON_BuildTests)
|
# Only build tests when JSON_BuildTests is set and testing has not been
|
||||||
|
# disabled by a parent project via BUILD_TESTING (see the CTest module, which
|
||||||
|
# also calls enable_testing()).
|
||||||
|
if (JSON_BuildTests AND (NOT DEFINED BUILD_TESTING OR BUILD_TESTING))
|
||||||
include(CTest)
|
include(CTest)
|
||||||
enable_testing()
|
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@@ -212,7 +213,7 @@ if(JSON_Install)
|
|||||||
install(
|
install(
|
||||||
FILES ${NLOHMANN_NATVIS_FILE}
|
FILES ${NLOHMANN_NATVIS_FILE}
|
||||||
DESTINATION .
|
DESTINATION .
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
export(
|
export(
|
||||||
TARGETS ${NLOHMANN_JSON_TARGET_NAME}
|
TARGETS ${NLOHMANN_JSON_TARGET_NAME}
|
||||||
|
|||||||
@@ -9,6 +9,30 @@ This file describes the source for supporting files; that is, files that are not
|
|||||||
|
|
||||||
## Continuous Integration
|
## Continuous Integration
|
||||||
|
|
||||||
|
### `.github/workflows`
|
||||||
|
|
||||||
|
The [GitHub Actions](https://docs.github.com/en/actions) workflows that build, test, and analyze the library. Each file in this folder defines one workflow:
|
||||||
|
|
||||||
|
- `ubuntu.yml`, `macos.yml`, `windows.yml` — build and run the test suite on Linux, macOS, and Windows.
|
||||||
|
- `check_amalgamation.yml` — verify that the single-header amalgamation in `single_include` is up to date on pull requests.
|
||||||
|
- `comment_check_amalgamation.yml` — comment on a pull request when the amalgamation check failed.
|
||||||
|
- `cifuzz.yml` — run short fuzzing sessions via [OSS-Fuzz CIFuzz](https://google.github.io/oss-fuzz/getting-started/continuous-integration/) on pull requests.
|
||||||
|
- `codeql-analysis.yml` — run [CodeQL](https://codeql.github.com) code scanning.
|
||||||
|
- `flawfinder.yml` — run the [Flawfinder](https://dwheeler.com/flawfinder/) static analysis.
|
||||||
|
- `semgrep.yml` — run [Semgrep](https://semgrep.dev) static analysis.
|
||||||
|
- `scorecards.yml` — run the [OpenSSF Scorecard](https://securityscorecards.dev) supply-chain security checks.
|
||||||
|
- `dependency-review.yml` — scan dependency changes in pull requests for known vulnerabilities.
|
||||||
|
- `labeler.yml` — the "Pull Request Labeler" workflow (see `.github/labeler.yml`).
|
||||||
|
- `stale.yml` — comment on and close stale issues and pull requests.
|
||||||
|
- `publish_documentation.yml` — build and publish the documentation on every merge to the `develop` branch.
|
||||||
|
|
||||||
|
Further documentation:
|
||||||
|
|
||||||
|
- [Workflow syntax for GitHub Actions](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions)
|
||||||
|
|
||||||
|
> [!IMPORTANT]
|
||||||
|
> The folder `.github/workflows` is predetermined by GitHub.
|
||||||
|
|
||||||
### `.cirrus.yml`
|
### `.cirrus.yml`
|
||||||
|
|
||||||
Configuration file for the pipeline at [Cirrus CI](https://cirrus-ci.com/github/nlohmann/json).
|
Configuration file for the pipeline at [Cirrus CI](https://cirrus-ci.com/github/nlohmann/json).
|
||||||
@@ -123,7 +147,7 @@ Further documentation:
|
|||||||
> [!IMPORTANT]
|
> [!IMPORTANT]
|
||||||
> The folder `.github/ISSUE_TEMPLATE` is predetermined by GitHub.
|
> The folder `.github/ISSUE_TEMPLATE` is predetermined by GitHub.
|
||||||
|
|
||||||
### `.github/ISSUE_TEMPLATE/config.yaml`
|
### `.github/ISSUE_TEMPLATE/config.yml`
|
||||||
|
|
||||||
Issue template chooser configuration. The file is used to configure the dialog when a new issue is created.
|
Issue template chooser configuration. The file is used to configure the dialog when a new issue is created.
|
||||||
|
|
||||||
@@ -132,7 +156,7 @@ Further documentation:
|
|||||||
- [Configuring issue templates for your repository](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/configuring-issue-templates-for-your-repository)
|
- [Configuring issue templates for your repository](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/configuring-issue-templates-for-your-repository)
|
||||||
|
|
||||||
> [!IMPORTANT]
|
> [!IMPORTANT]
|
||||||
> The filename `.github/ISSUE_TEMPLATE/config.yaml` is predetermined by GitHub.
|
> The filename `.github/ISSUE_TEMPLATE/config.yml` is predetermined by GitHub.
|
||||||
|
|
||||||
### `.github/labeler.yml`
|
### `.github/labeler.yml`
|
||||||
|
|
||||||
@@ -165,7 +189,7 @@ Further documentation:
|
|||||||
- [Adding a security policy to your repository](https://docs.github.com/en/code-security/getting-started/adding-a-security-policy-to-your-repository)
|
- [Adding a security policy to your repository](https://docs.github.com/en/code-security/getting-started/adding-a-security-policy-to-your-repository)
|
||||||
|
|
||||||
> [!IMPORTANT]
|
> [!IMPORTANT]
|
||||||
> The filename `.github/SECURITY.yml` is predetermined by GitHub.
|
> The filename `.github/SECURITY.md` is predetermined by GitHub.
|
||||||
|
|
||||||
> [!NOTE]
|
> [!NOTE]
|
||||||
> The file is part of the documentation and is included in `docs/mkdocs/docs/community/security_policy.md`.
|
> The file is part of the documentation and is included in `docs/mkdocs/docs/community/security_policy.md`.
|
||||||
@@ -234,6 +258,16 @@ make BUILD.bazel
|
|||||||
|
|
||||||
### `meson.build`
|
### `meson.build`
|
||||||
|
|
||||||
|
The build definition for the [Meson](https://mesonbuild.com) build system.
|
||||||
|
|
||||||
### `Package.swift`
|
### `Package.swift`
|
||||||
|
|
||||||
### `WORKSPACE.bazel`
|
The package manifest for the [Swift Package Manager](https://www.swift.org/package-manager/).
|
||||||
|
|
||||||
|
### `MODULE.bazel`
|
||||||
|
|
||||||
|
The module definition for [Bazel](https://bazel.build)'s [Bzlmod](https://bazel.build/external/module) dependency system. It complements `BUILD.bazel` and replaces the previously used `WORKSPACE.bazel`.
|
||||||
|
|
||||||
|
Further documentation:
|
||||||
|
|
||||||
|
- [Bazel modules](https://bazel.build/external/module)
|
||||||
@@ -205,7 +205,7 @@ 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: BUILD.bazel
|
include.zip: BUILD.bazel
|
||||||
zip -9 --recurse-paths -X include.zip $(SRCS) $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) BUILD.bazel WORKSPACE.bazel meson.build LICENSE.MIT
|
zip -9 --recurse-paths -X include.zip $(SRCS) $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) BUILD.bazel MODULE.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
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
[](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/develop/LICENSE.MIT)
|
||||||
[](https://github.com/nlohmann/json/releases)
|
[](https://github.com/nlohmann/json/releases)
|
||||||
[](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)
|
||||||
@@ -42,6 +42,7 @@
|
|||||||
- [Specializing enum conversion](#specializing-enum-conversion)
|
- [Specializing enum conversion](#specializing-enum-conversion)
|
||||||
- [Binary formats (BSON, CBOR, MessagePack, UBJSON, and BJData)](#binary-formats-bson-cbor-messagepack-ubjson-and-bjdata)
|
- [Binary formats (BSON, CBOR, MessagePack, UBJSON, and BJData)](#binary-formats-bson-cbor-messagepack-ubjson-and-bjdata)
|
||||||
- [Customers](#customers)
|
- [Customers](#customers)
|
||||||
|
- [Ecosystem](#ecosystem)
|
||||||
- [Supported compilers](#supported-compilers)
|
- [Supported compilers](#supported-compilers)
|
||||||
- [Integration](#integration)
|
- [Integration](#integration)
|
||||||
- [CMake](#cmake)
|
- [CMake](#cmake)
|
||||||
@@ -70,7 +71,7 @@ Other aspects were not so important to us:
|
|||||||
|
|
||||||
- **Speed**. There are certainly [faster JSON libraries](https://github.com/miloyip/nativejson-benchmark#parsing-time) out there. However, if your goal is to speed up your development by adding JSON support with a single header, then this library is the way to go. If you know how to use a `std::vector` or `std::map`, you are already set.
|
- **Speed**. There are certainly [faster JSON libraries](https://github.com/miloyip/nativejson-benchmark#parsing-time) out there. However, if your goal is to speed up your development by adding JSON support with a single header, then this library is the way to go. If you know how to use a `std::vector` or `std::map`, you are already set.
|
||||||
|
|
||||||
See the [contribution guidelines](https://github.com/nlohmann/json/blob/master/.github/CONTRIBUTING.md#please-dont) for more information.
|
See the [contribution guidelines](https://github.com/nlohmann/json/blob/develop/.github/CONTRIBUTING.md#please-dont) for more information.
|
||||||
|
|
||||||
## Sponsors
|
## Sponsors
|
||||||
|
|
||||||
@@ -90,7 +91,6 @@ 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)
|
|
||||||
|
|
||||||
### Further support
|
### Further support
|
||||||
|
|
||||||
@@ -429,6 +429,8 @@ struct MyIterator {
|
|||||||
using reference = const char&;
|
using reference = const char&;
|
||||||
using iterator_category = std::input_iterator_tag;
|
using iterator_category = std::input_iterator_tag;
|
||||||
|
|
||||||
|
explicit MyIterator(MyContainer* tgt = nullptr) : target(tgt) {}
|
||||||
|
|
||||||
MyIterator& operator++() {
|
MyIterator& operator++() {
|
||||||
target->advance();
|
target->advance();
|
||||||
return *this;
|
return *this;
|
||||||
@@ -450,12 +452,12 @@ MyIterator begin(MyContainer& tgt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MyIterator end(const MyContainer&) {
|
MyIterator end(const MyContainer&) {
|
||||||
return {};
|
return MyIterator{};
|
||||||
}
|
}
|
||||||
|
|
||||||
void foo() {
|
void foo() {
|
||||||
MyContainer c;
|
MyContainer c;
|
||||||
json j = json::parse(c);
|
json j = json::parse(begin(c), end(c));
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -756,9 +758,9 @@ int i = 42;
|
|||||||
json jn = i;
|
json jn = i;
|
||||||
auto f = jn.get<double>();
|
auto f = jn.get<double>();
|
||||||
// NOT RECOMMENDED
|
// NOT RECOMMENDED
|
||||||
double f2 = jb;
|
double f2 = jn;
|
||||||
double f3;
|
double f3;
|
||||||
f3 = jb;
|
f3 = jn;
|
||||||
|
|
||||||
// etc.
|
// etc.
|
||||||
```
|
```
|
||||||
@@ -1105,7 +1107,7 @@ Just as in [Arbitrary Type Conversions](#arbitrary-types-conversions) above,
|
|||||||
|
|
||||||
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 `get<ENUM_TYPE>()`, undefined JSON values will default to the first pair specified in your map. Select this default pair carefully. If you desire an exception in this circumstance use `NLOHMANN_JSON_SERIALIZE_ENUM_STRICT()` which behaves identically except for throwing an exception on unrecognized values.
|
||||||
- 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)
|
||||||
@@ -1185,6 +1187,11 @@ The library is used in multiple projects, applications, operating systems, etc.
|
|||||||
|
|
||||||
[](https://json.nlohmann.me/home/customers/)
|
[](https://json.nlohmann.me/home/customers/)
|
||||||
|
|
||||||
|
## Ecosystem
|
||||||
|
|
||||||
|
Beyond projects that use the library, there are third-party projects that build on top of it - schema validators,
|
||||||
|
language bindings, format converters, and the like. See the curated [Ecosystem](https://json.nlohmann.me/community/ecosystem/) page.
|
||||||
|
|
||||||
## Supported compilers
|
## Supported compilers
|
||||||
|
|
||||||
Though it's 2026 already, the support for C++11 is still a bit sparse. Currently, the following compilers are known to work:
|
Though it's 2026 already, the support for C++11 is still a bit sparse. Currently, the following compilers are known to work:
|
||||||
@@ -1465,7 +1472,7 @@ I deeply appreciate the help of the following people.
|
|||||||
57. [Jared Grubb](https://github.com/jaredgrubb) supported the implementation of user-defined types.
|
57. [Jared Grubb](https://github.com/jaredgrubb) supported the implementation of user-defined types.
|
||||||
58. [EnricoBilla](https://github.com/EnricoBilla) noted a typo in an example.
|
58. [EnricoBilla](https://github.com/EnricoBilla) noted a typo in an example.
|
||||||
59. [Martin Hořeňovský](https://github.com/horenmar) found a way for a 2x speedup for the compilation time of the test suite.
|
59. [Martin Hořeňovský](https://github.com/horenmar) found a way for a 2x speedup for the compilation time of the test suite.
|
||||||
60. [ukhegg](https://github.com/ukhegg) found proposed an improvement for the examples section.
|
60. [ukhegg](https://github.com/ukhegg) proposed an improvement for the examples section.
|
||||||
61. [rswanson-ihi](https://github.com/rswanson-ihi) noted a typo in the README.
|
61. [rswanson-ihi](https://github.com/rswanson-ihi) noted a typo in the README.
|
||||||
62. [Mihai Stan](https://github.com/stanmihai4) fixed a bug in the comparison with `nullptr`s.
|
62. [Mihai Stan](https://github.com/stanmihai4) fixed a bug in the comparison with `nullptr`s.
|
||||||
63. [Tushar Maheshwari](https://github.com/tusharpm) added [cotire](https://github.com/sakra/cotire) support to speed up the compilation.
|
63. [Tushar Maheshwari](https://github.com/tusharpm) added [cotire](https://github.com/sakra/cotire) support to speed up the compilation.
|
||||||
@@ -1800,13 +1807,13 @@ The library itself consists of a single header file licensed under the MIT licen
|
|||||||
- [**amalgamate.py - Amalgamate C source and header files**](https://github.com/edlund/amalgamate) to create a single header file
|
- [**amalgamate.py - Amalgamate C source and header files**](https://github.com/edlund/amalgamate) to create a single header file
|
||||||
- [**American fuzzy lop**](https://lcamtuf.coredump.cx/afl/) for fuzz testing
|
- [**American fuzzy lop**](https://lcamtuf.coredump.cx/afl/) for fuzz testing
|
||||||
- [**AppVeyor**](https://www.appveyor.com) for [continuous integration](https://ci.appveyor.com/project/nlohmann/json) on Windows
|
- [**AppVeyor**](https://www.appveyor.com) for [continuous integration](https://ci.appveyor.com/project/nlohmann/json) on Windows
|
||||||
- [**Artistic Style**](http://astyle.sourceforge.net) for automatic source code indentation
|
- [**Artistic Style**](https://astyle.sourceforge.net) for automatic source code indentation
|
||||||
- [**Clang**](https://clang.llvm.org) for compilation with code sanitizers
|
- [**Clang**](https://clang.llvm.org) for compilation with code sanitizers
|
||||||
- [**CMake**](https://cmake.org) for build automation
|
- [**CMake**](https://cmake.org) for build automation
|
||||||
- [**Codacy**](https://www.codacy.com) for further [code analysis](https://app.codacy.com/gh/nlohmann/json/dashboard)
|
- [**Codacy**](https://www.codacy.com) for further [code analysis](https://app.codacy.com/gh/nlohmann/json/dashboard)
|
||||||
- [**Coveralls**](https://coveralls.io) to measure [code coverage](https://coveralls.io/github/nlohmann/json)
|
- [**Coveralls**](https://coveralls.io) to measure [code coverage](https://coveralls.io/github/nlohmann/json)
|
||||||
- [**Coverity Scan**](https://scan.coverity.com) for [static analysis](https://scan.coverity.com/projects/nlohmann-json)
|
- [**Coverity Scan**](https://scan.coverity.com) for [static analysis](https://scan.coverity.com/projects/nlohmann-json)
|
||||||
- [**cppcheck**](http://cppcheck.sourceforge.net) for static analysis
|
- [**cppcheck**](https://cppcheck.sourceforge.io) for static analysis
|
||||||
- [**doctest**](https://github.com/onqtam/doctest) for the unit tests
|
- [**doctest**](https://github.com/onqtam/doctest) for the unit tests
|
||||||
- [**GitHub Changelog Generator**](https://github.com/skywinder/github-changelog-generator) to generate the [ChangeLog](https://github.com/nlohmann/json/blob/develop/ChangeLog.md)
|
- [**GitHub Changelog Generator**](https://github.com/skywinder/github-changelog-generator) to generate the [ChangeLog](https://github.com/nlohmann/json/blob/develop/ChangeLog.md)
|
||||||
- [**Google Benchmark**](https://github.com/google/benchmark) to implement the benchmarks
|
- [**Google Benchmark**](https://github.com/google/benchmark) to implement the benchmarks
|
||||||
@@ -1821,6 +1828,15 @@ The library itself consists of a single header file licensed under the MIT licen
|
|||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
|
### Standards compliance
|
||||||
|
|
||||||
|
The library targets strict conformance with [RFC 8259](https://tools.ietf.org/html/rfc8259.html). Both the original [JSONTestSuite](https://github.com/nst/JSONTestSuite) and its updated revision are exercised in CI; their test data is downloaded from [`nlohmann/json_test_data`](https://github.com/nlohmann/json_test_data) at configure time rather than committed to this repository (see [`tests/src/unit-testsuites.cpp`](https://github.com/nlohmann/json/blob/develop/tests/src/unit-testsuites.cpp)):
|
||||||
|
|
||||||
|
- The updated revision runs all mandatory `y_` (must-accept) and `n_` (must-reject) cases through the strict [`parse()`](https://json.nlohmann.me/api/basic_json/parse/) entry point; the original suite runs its `n_` cases through `parse()` and its `y_` cases through [`operator>>`](https://json.nlohmann.me/api/operator_gtgt/).
|
||||||
|
- The `i_` (implementation-defined) cases are, by RFC 8259, free to be accepted *or* rejected, so "passing all `i_` cases" is not a meaningful conformance metric. The library makes deliberate, documented choices there: nesting depth is not artificially limited, a leading UTF-8 byte order mark is silently ignored, [Unicode noncharacters](https://www.unicode.org/faq/private_use.html#nonchar1) are forwarded unchanged, invalid UTF-8 and lone/unpaired UTF-16 surrogates are rejected (stricter than required), and a number that cannot be stored without becoming `NaN`/`INF` raises [`out_of_range.406`](https://json.nlohmann.me/home/exceptions/#jsonexceptionout_of_range406).
|
||||||
|
|
||||||
|
One behavioral nuance is worth calling out, because a superficial test often misreads it as non-compliance: [`parse()`](https://json.nlohmann.me/api/basic_json/parse/) is strict and rejects trailing data after a value, whereas [`operator>>`](https://json.nlohmann.me/api/operator_gtgt/) follows relaxed iostream semantics — it parses a single value and leaves the stream positioned right after it. Feeding "a valid document followed by trailing bytes" through `operator>>` reports success; the same input through `parse()` is rejected. This is a documented two-API design, not a conformance gap. See [**parsing**](https://json.nlohmann.me/features/parsing/) for details.
|
||||||
|
|
||||||
### Character encoding
|
### Character encoding
|
||||||
|
|
||||||
The library supports **Unicode input** as follows:
|
The library supports **Unicode input** as follows:
|
||||||
@@ -1839,7 +1855,7 @@ The library supports **Unicode input** as follows:
|
|||||||
This library does not support comments by default. It does so for three reasons:
|
This library does not support comments by default. It does so for three reasons:
|
||||||
|
|
||||||
1. Comments are not part of the [JSON specification](https://tools.ietf.org/html/rfc8259). You may argue that `//` or `/* */` are allowed in JavaScript, but JSON is not JavaScript.
|
1. Comments are not part of the [JSON specification](https://tools.ietf.org/html/rfc8259). You may argue that `//` or `/* */` are allowed in JavaScript, but JSON is not JavaScript.
|
||||||
2. This was not an oversight: Douglas Crockford [wrote on this](https://plus.google.com/118095276221607585885/posts/RK8qyGVaGSr) in May 2012:
|
2. This was not an oversight: Douglas Crockford [wrote on this](https://news.ycombinator.com/item?id=3912149) in May 2012:
|
||||||
|
|
||||||
> I removed comments from JSON because I saw people were using them to hold parsing directives, a practice which would have destroyed interoperability. I know that the lack of comments makes some people sad, but it shouldn't.
|
> I removed comments from JSON because I saw people were using them to hold parsing directives, a practice which would have destroyed interoperability. I know that the lack of comments makes some people sad, but it shouldn't.
|
||||||
>
|
>
|
||||||
@@ -1847,7 +1863,7 @@ This library does not support comments by default. It does so for three reasons:
|
|||||||
|
|
||||||
3. It is dangerous for interoperability if some libraries would add comment support while others don't. Please check [The Harmful Consequences of the Robustness Principle](https://tools.ietf.org/html/draft-iab-protocol-maintenance-01) on this.
|
3. It is dangerous for interoperability if some libraries would add comment support while others don't. Please check [The Harmful Consequences of the Robustness Principle](https://tools.ietf.org/html/draft-iab-protocol-maintenance-01) on this.
|
||||||
|
|
||||||
However, you can set set parameter `ignore_comments` to true in the `parse` function to ignore `//` or `/* */` comments. Comments will then be treated as whitespace.
|
However, you can set parameter `ignore_comments` to true in the `parse` function to ignore `//` or `/* */` comments. Comments will then be treated as whitespace.
|
||||||
|
|
||||||
### Trailing commas
|
### Trailing commas
|
||||||
|
|
||||||
|
|||||||
+47
-1
@@ -669,7 +669,6 @@ add_custom_target(ci_test_compiler_default
|
|||||||
add_custom_target(ci_cuda_example
|
add_custom_target(ci_cuda_example
|
||||||
COMMAND ${CMAKE_COMMAND}
|
COMMAND ${CMAKE_COMMAND}
|
||||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||||
-DCMAKE_CUDA_HOST_COMPILER=g++-8
|
|
||||||
-S${PROJECT_SOURCE_DIR}/tests/cuda_example -B${PROJECT_BINARY_DIR}/build_cuda_example
|
-S${PROJECT_SOURCE_DIR}/tests/cuda_example -B${PROJECT_BINARY_DIR}/build_cuda_example
|
||||||
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_cuda_example
|
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_cuda_example
|
||||||
)
|
)
|
||||||
@@ -701,6 +700,53 @@ add_custom_target(ci_icpc
|
|||||||
COMMENT "Compile and test with ICPC"
|
COMMENT "Compile and test with ICPC"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_custom_target(ci_icpx
|
||||||
|
COMMAND ${CMAKE_COMMAND}
|
||||||
|
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||||
|
-DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx
|
||||||
|
-DJSON_BuildTests=ON -DJSON_FastTests=ON
|
||||||
|
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_icpx
|
||||||
|
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_icpx
|
||||||
|
COMMAND cd ${PROJECT_BINARY_DIR}/build_icpx && ${CMAKE_CTEST_COMMAND} --parallel ${N} --exclude-regex "test-unicode" --output-on-failure
|
||||||
|
COMMENT "Compile and test with ICPX (Intel oneAPI DPC++/C++)"
|
||||||
|
)
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# NVIDIA HPC SDK C++ Compiler
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
# nvc++ defaults to a relaxed, non-IEEE floating-point model that flushes denormals
|
||||||
|
# to zero and does not honor NaN ordering; -Kieee restores strict IEEE 754 behavior
|
||||||
|
# (needed for the dtoa/grisu and NaN-comparison code paths).
|
||||||
|
#
|
||||||
|
# -tp=px pins the target processor to the generic x86-64 baseline (SSE2-only) to avoid
|
||||||
|
# a nvc++ 25.5 / LLVM issue: when nvc++ auto-detects -tp from the runner's CPU (e.g. -tp znver4),
|
||||||
|
# certain attribute combinations trigger an llc instruction-selection crash on std::ldexp<unsigned>.
|
||||||
|
# Pinning to px removes this variability and is robust to future llc/nvc++ updates.
|
||||||
|
#
|
||||||
|
# The following tests are excluded as they trigger known nvc++ 25.5 defects (not
|
||||||
|
# library bugs); see https://github.com/nlohmann/json for tracking. Only the
|
||||||
|
# affected language-standard variants are excluded so coverage is otherwise kept:
|
||||||
|
# - test-comparison_cpp20, test-comparison_legacy_cpp20
|
||||||
|
# miscompiles cross-type/<=> comparison (e.g. `-17 <= null`)
|
||||||
|
# - test-constructor1_cpp11
|
||||||
|
# std::initializer_list lifetime bug -> SIGSEGV
|
||||||
|
# - test-deserialization_cpp20
|
||||||
|
# mangles the UTF-8 u8"" string literal in the char8_t (C++20) section
|
||||||
|
add_custom_target(ci_nvhpc
|
||||||
|
COMMAND ${CMAKE_COMMAND}
|
||||||
|
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||||
|
-DCMAKE_C_COMPILER=nvc -DCMAKE_CXX_COMPILER=nvc++
|
||||||
|
-DCMAKE_CXX_FLAGS="-Kieee;-tp=px"
|
||||||
|
-DJSON_BuildTests=ON -DJSON_FastTests=ON
|
||||||
|
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_nvhpc
|
||||||
|
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_nvhpc
|
||||||
|
# the pipes are escaped so the surrounding shell passes them to ctest verbatim
|
||||||
|
# instead of treating them as shell pipe operators
|
||||||
|
COMMAND cd ${PROJECT_BINARY_DIR}/build_nvhpc && ${CMAKE_CTEST_COMMAND} --parallel ${N} --exclude-regex "test-unicode\\|test-comparison_cpp20\\|test-comparison_legacy_cpp20\\|test-constructor1_cpp11\\|test-deserialization_cpp20" --output-on-failure
|
||||||
|
COMMENT "Compile and test with NVIDIA HPC SDK (nvc++)"
|
||||||
|
)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# REUSE
|
# REUSE
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|||||||
@@ -5,8 +5,14 @@
|
|||||||
# -Wno-extra-semi-stmt The library uses assert which triggers this warning.
|
# -Wno-extra-semi-stmt The library uses 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-c2y-extensions Clang 22.1 diagnoses __COUNTER__ as a C2y extension, also in
|
||||||
# -Wno-missing-noreturn We found no way to silence this warning otherwise, see PR #4871
|
# C++ mode. The library does not use __COUNTER__; the warnings
|
||||||
|
# all come from vendored Doctest (SECTION/TEST_CASE macros).
|
||||||
|
# -Wno-unsafe-buffer-usage Pervasive: the library's own low-level numeric/buffer code
|
||||||
|
# (to_chars, serializer, lexer, binary reader/writer, input
|
||||||
|
# adapters, json_pointer) plus vendored Doctest itself (~208
|
||||||
|
# distinct sites measured 2026-07-08 on clang trunk) all use
|
||||||
|
# raw pointer arithmetic / libc string calls by necessity.
|
||||||
|
|
||||||
set(CLANG_CXXFLAGS
|
set(CLANG_CXXFLAGS
|
||||||
-Werror
|
-Werror
|
||||||
@@ -17,6 +23,6 @@ set(CLANG_CXXFLAGS
|
|||||||
-Wno-extra-semi-stmt
|
-Wno-extra-semi-stmt
|
||||||
-Wno-padded
|
-Wno-padded
|
||||||
-Wno-covered-switch-default
|
-Wno-covered-switch-default
|
||||||
|
-Wno-c2y-extensions
|
||||||
-Wno-unsafe-buffer-usage
|
-Wno-unsafe-buffer-usage
|
||||||
-Wno-missing-noreturn
|
|
||||||
)
|
)
|
||||||
@@ -12,7 +12,7 @@ else()
|
|||||||
# create a header with the path to the downloaded test data
|
# create a header with the path to the downloaded test data
|
||||||
file(WRITE ${CMAKE_BINARY_DIR}/include/test_data.hpp "#define TEST_DATA_DIRECTORY \"${CMAKE_BINARY_DIR}/test_files\"\n")
|
file(WRITE ${CMAKE_BINARY_DIR}/include/test_data.hpp "#define TEST_DATA_DIRECTORY \"${CMAKE_BINARY_DIR}/test_files\"\n")
|
||||||
|
|
||||||
# download test data from GitHub release
|
# download test data from the GitHub tag source archive
|
||||||
ExternalProject_Add(download_test_data_project
|
ExternalProject_Add(download_test_data_project
|
||||||
URL "${JSON_TEST_DATA_URL}/archive/refs/tags/v${JSON_TEST_DATA_VERSION}.zip"
|
URL "${JSON_TEST_DATA_URL}/archive/refs/tags/v${JSON_TEST_DATA_VERSION}.zip"
|
||||||
SOURCE_DIR "${CMAKE_BINARY_DIR}/test_files"
|
SOURCE_DIR "${CMAKE_BINARY_DIR}/test_files"
|
||||||
@@ -32,13 +32,17 @@ endif()
|
|||||||
|
|
||||||
# determine the operating system (for debug and support purposes)
|
# determine the operating system (for debug and support purposes)
|
||||||
find_program(UNAME_COMMAND uname)
|
find_program(UNAME_COMMAND uname)
|
||||||
find_program(VER_COMMAND ver)
|
|
||||||
find_program(LSB_RELEASE_COMMAND lsb_release)
|
find_program(LSB_RELEASE_COMMAND lsb_release)
|
||||||
find_program(SW_VERS_COMMAND sw_vers)
|
find_program(SW_VERS_COMMAND sw_vers)
|
||||||
set(OS_VERSION_STRINGS "${CMAKE_SYSTEM}")
|
set(OS_VERSION_STRINGS "${CMAKE_SYSTEM}")
|
||||||
if (VER_COMMAND)
|
if (CMAKE_HOST_WIN32)
|
||||||
execute_process(COMMAND ${VER_COMMAND} OUTPUT_VARIABLE VER_COMMAND_RESULT OUTPUT_STRIP_TRAILING_WHITESPACE)
|
# "ver" is a cmd.exe builtin rather than a standalone executable, so it
|
||||||
set(OS_VERSION_STRINGS "${OS_VERSION_STRINGS}; ${VER_COMMAND_RESULT}")
|
# cannot be located with find_program and must be invoked through cmd
|
||||||
|
execute_process(COMMAND cmd /c ver OUTPUT_VARIABLE VER_COMMAND_RESULT ERROR_QUIET)
|
||||||
|
string(STRIP "${VER_COMMAND_RESULT}" VER_COMMAND_RESULT)
|
||||||
|
if (VER_COMMAND_RESULT)
|
||||||
|
set(OS_VERSION_STRINGS "${OS_VERSION_STRINGS}; ${VER_COMMAND_RESULT}")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
if (SW_VERS_COMMAND)
|
if (SW_VERS_COMMAND)
|
||||||
execute_process(COMMAND ${SW_VERS_COMMAND} OUTPUT_VARIABLE SW_VERS_COMMAND_RESULT OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
|
execute_process(COMMAND ${SW_VERS_COMMAND} OUTPUT_VARIABLE SW_VERS_COMMAND_RESULT OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
|
||||||
|
|||||||
+4
-4
@@ -35,6 +35,8 @@ foreach(feature ${CMAKE_CXX_COMPILE_FEATURES})
|
|||||||
set(compiler_supports_cpp_20 TRUE)
|
set(compiler_supports_cpp_20 TRUE)
|
||||||
elseif (${feature} STREQUAL cxx_std_23)
|
elseif (${feature} STREQUAL cxx_std_23)
|
||||||
set(compiler_supports_cpp_23 TRUE)
|
set(compiler_supports_cpp_23 TRUE)
|
||||||
|
elseif (${feature} STREQUAL cxx_std_26)
|
||||||
|
set(compiler_supports_cpp_26 TRUE)
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
@@ -92,7 +94,6 @@ function(json_test_set_test_options tests)
|
|||||||
target_compile_options(${test_interface} INTERFACE ${args_COMPILE_OPTIONS})
|
target_compile_options(${test_interface} INTERFACE ${args_COMPILE_OPTIONS})
|
||||||
target_link_libraries (${test_interface} INTERFACE ${args_LINK_LIBRARIES})
|
target_link_libraries (${test_interface} INTERFACE ${args_LINK_LIBRARIES})
|
||||||
target_link_options(${test_interface} INTERFACE ${args_LINK_OPTIONS})
|
target_link_options(${test_interface} INTERFACE ${args_LINK_OPTIONS})
|
||||||
#set_target_properties(${test_interface} PROPERTIES JSON_TEST_PROPERTIES "${args_TEST_PROPERTIES}")
|
|
||||||
set_property(DIRECTORY PROPERTY
|
set_property(DIRECTORY PROPERTY
|
||||||
${test_interface}_TEST_PROPERTIES "${args_TEST_PROPERTIES}"
|
${test_interface}_TEST_PROPERTIES "${args_TEST_PROPERTIES}"
|
||||||
)
|
)
|
||||||
@@ -102,7 +103,6 @@ endfunction()
|
|||||||
|
|
||||||
# for internal use by _json_test_add_test()
|
# for internal use by _json_test_add_test()
|
||||||
function(_json_test_apply_test_properties test_target properties_target)
|
function(_json_test_apply_test_properties test_target properties_target)
|
||||||
#get_target_property(test_properties ${properties_target} JSON_TEST_PROPERTIES)
|
|
||||||
get_property(test_properties DIRECTORY PROPERTY ${properties_target}_TEST_PROPERTIES)
|
get_property(test_properties DIRECTORY PROPERTY ${properties_target}_TEST_PROPERTIES)
|
||||||
if(test_properties)
|
if(test_properties)
|
||||||
set_tests_properties(${test_target} PROPERTIES ${test_properties})
|
set_tests_properties(${test_target} PROPERTIES ${test_properties})
|
||||||
@@ -213,10 +213,10 @@ function(json_test_add_test_for file)
|
|||||||
|
|
||||||
if("${args_NAME}" STREQUAL "")
|
if("${args_NAME}" STREQUAL "")
|
||||||
get_filename_component(file_basename ${file} NAME_WE)
|
get_filename_component(file_basename ${file} NAME_WE)
|
||||||
string(REGEX REPLACE "unit-([^$]+)" "test-\\1" test_name ${file_basename})
|
string(REGEX REPLACE "unit-(.+)" "test-\\1" test_name ${file_basename})
|
||||||
else()
|
else()
|
||||||
set(test_name ${args_NAME})
|
set(test_name ${args_NAME})
|
||||||
if(NOT test_name MATCHES "test-[^$]+")
|
if(NOT test_name MATCHES "test-.+")
|
||||||
message(FATAL_ERROR "Test name must start with 'test-'.")
|
message(FATAL_ERROR "Test name must start with 'test-'.")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"archive": "JSON_for_Modern_C++.tgz",
|
"archive": "JSON_for_Modern_C++.tgz",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Niels Lohmann",
|
"name": "Niels Lohmann",
|
||||||
"link": "https://twitter.com/nlohmann"
|
"link": "https://nlohmann.me"
|
||||||
},
|
},
|
||||||
"aliases": ["nlohmann/json"]
|
"aliases": ["nlohmann/json"]
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,8 @@ class (either explicitly or via the conversion operators).
|
|||||||
|
|
||||||
## Return value
|
## Return value
|
||||||
|
|
||||||
Copy of the JSON value, converted to `ValueType`
|
1. (none) -- the converted value is written to the output parameter `val`.
|
||||||
|
2. the JSON value `j` converted to `TargetType`
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ static bool accept(InputType&& i,
|
|||||||
const bool ignore_trailing_commas = false);
|
const bool ignore_trailing_commas = false);
|
||||||
|
|
||||||
// (2)
|
// (2)
|
||||||
template<typename IteratorType>
|
template<typename IteratorType, typename SentinelType = IteratorType>
|
||||||
static bool accept(IteratorType first, IteratorType last,
|
static bool accept(IteratorType first, SentinelType last,
|
||||||
const bool ignore_comments = false,
|
const bool ignore_comments = false,
|
||||||
const bool ignore_trailing_commas = false);
|
const bool ignore_trailing_commas = false);
|
||||||
```
|
```
|
||||||
@@ -17,10 +17,11 @@ static bool accept(IteratorType first, IteratorType last,
|
|||||||
Checks whether the input is valid JSON.
|
Checks whether the input is valid JSON.
|
||||||
|
|
||||||
1. Reads from a compatible input.
|
1. Reads from a compatible input.
|
||||||
2. Reads from a pair of character iterators
|
2. Reads from a pair of character iterators, or an iterator and a sentinel of a different type (C++20 ranges support)
|
||||||
|
|
||||||
The value_type of the iterator must be an integral type with a size of 1, 2, or 4 bytes, which will be interpreted
|
The value_type of the iterator must be an integral type with a size of 1, 2, or 4 bytes, which will be interpreted
|
||||||
respectively as UTF-8, UTF-16, and UTF-32.
|
respectively as UTF-8, UTF-16, and UTF-32. If `SentinelType` differs from `IteratorType`, it must be comparable to
|
||||||
|
the iterator type with `operator!=`.
|
||||||
|
|
||||||
Unlike the [`parse()`](parse.md) function, this function neither throws an exception in case of invalid JSON input
|
Unlike the [`parse()`](parse.md) function, this function neither throws an exception in case of invalid JSON input
|
||||||
(i.e., a parse error) nor creates diagnostic information.
|
(i.e., a parse error) nor creates diagnostic information.
|
||||||
@@ -35,7 +36,8 @@ Unlike the [`parse()`](parse.md) function, this function neither throws an excep
|
|||||||
- a C-style array of characters
|
- a C-style array of characters
|
||||||
- a pointer to a null-terminated string of single byte characters (throws if null)
|
- a pointer to a null-terminated string of single byte characters (throws if null)
|
||||||
- a `std::string`
|
- a `std::string`
|
||||||
- an object `obj` for which `begin(obj)` and `end(obj)` produces a valid pair of iterators.
|
- a container `obj` for which `begin(obj)` and `end(obj)` produce a valid pair of iterators
|
||||||
|
(as found via ADL or member functions, with semantics compatible to `std::begin` and `std::end`)
|
||||||
|
|
||||||
`IteratorType`
|
`IteratorType`
|
||||||
: a compatible iterator type, for instance.
|
: a compatible iterator type, for instance.
|
||||||
@@ -43,6 +45,12 @@ Unlike the [`parse()`](parse.md) function, this function neither throws an excep
|
|||||||
- a pair of `std::string::iterator` or `std::vector<std::uint8_t>::iterator`
|
- a pair of `std::string::iterator` or `std::vector<std::uint8_t>::iterator`
|
||||||
- a pair of pointers such as `ptr` and `ptr + len`
|
- a pair of pointers such as `ptr` and `ptr + len`
|
||||||
|
|
||||||
|
`SentinelType`
|
||||||
|
: defaults to `IteratorType`; may be a different type comparable to `IteratorType` via `operator!=`, for instance.
|
||||||
|
|
||||||
|
- a custom sentinel type for C++20 ranges
|
||||||
|
- `std::default_sentinel_t`, when `IteratorType` is `std::counted_iterator`
|
||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
`i` (in)
|
`i` (in)
|
||||||
@@ -60,7 +68,7 @@ Unlike the [`parse()`](parse.md) function, this function neither throws an excep
|
|||||||
: iterator to the start of the character range
|
: iterator to the start of the character range
|
||||||
|
|
||||||
`last` (in)
|
`last` (in)
|
||||||
: iterator to the end of the character range
|
: iterator to the end of the character range, or a sentinel value that compares equal to the end iterator with `operator!=`
|
||||||
|
|
||||||
## Return value
|
## Return value
|
||||||
|
|
||||||
@@ -101,6 +109,7 @@ A UTF-8 byte order mark is silently ignored.
|
|||||||
## See also
|
## See also
|
||||||
|
|
||||||
- [parse](parse.md) - deserialize from a compatible input
|
- [parse](parse.md) - deserialize from a compatible input
|
||||||
|
- [sax_parse](sax_parse.md) - parse input using the SAX interface
|
||||||
- [operator>>](../operator_gtgt.md) - deserialize from stream
|
- [operator>>](../operator_gtgt.md) - deserialize from stream
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
@@ -108,7 +117,9 @@ A UTF-8 byte order mark is silently ignored.
|
|||||||
- Added in version 3.0.0.
|
- Added in version 3.0.0.
|
||||||
- Ignoring comments via `ignore_comments` added in version 3.9.0.
|
- Ignoring comments via `ignore_comments` added in version 3.9.0.
|
||||||
- Changed [runtime assertion](../../features/assertions.md) in case of `FILE*` null pointers to exception in version 3.12.0.
|
- Changed [runtime assertion](../../features/assertions.md) in case of `FILE*` null pointers to exception in version 3.12.0.
|
||||||
- Added `ignore_trailing_commas` in version 3.12.1.
|
- Added `ignore_trailing_commas` in version 3.13.0.
|
||||||
|
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
|
||||||
|
- Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0.
|
||||||
|
|
||||||
!!! warning "Deprecation"
|
!!! warning "Deprecation"
|
||||||
|
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ This function is only needed to express two edge cases that cannot be realized w
|
|||||||
|
|
||||||
- [`basic_json(initializer_list_t)`](basic_json.md) - create a JSON value from an initializer list
|
- [`basic_json(initializer_list_t)`](basic_json.md) - create a JSON value from an initializer list
|
||||||
- [`object`](object.md) - create a JSON object value from an initializer list
|
- [`object`](object.md) - create a JSON object value from an initializer list
|
||||||
|
- [Creating JSON values](../../features/creating_values.md) - the article on creating JSON values
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -82,6 +82,8 @@ Strong exception safety: if an exception occurs, the original value stays intact
|
|||||||
key of an object which cannot be found. See the example below.
|
key of an object which cannot be found. See the example below.
|
||||||
- Throws [`out_of_range.404`](../../home/exceptions.md#jsonexceptionout_of_range404) if the JSON pointer `ptr` can
|
- Throws [`out_of_range.404`](../../home/exceptions.md#jsonexceptionout_of_range404) if the JSON pointer `ptr` can
|
||||||
not be resolved. See the example below.
|
not be resolved. See the example below.
|
||||||
|
- Throws [`out_of_range.410`](../../home/exceptions.md#jsonexceptionout_of_range410) if an array index in the passed
|
||||||
|
JSON pointer `ptr` exceeds the range of `size_type` (e.g., on 32-bit platforms).
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
|
|||||||
@@ -82,7 +82,13 @@ basic_json(basic_json&& other) noexcept;
|
|||||||
4. This is a constructor for existing `basic_json` types. It does not hijack copy/move constructors, since the parameter
|
4. This is a constructor for existing `basic_json` types. It does not hijack copy/move constructors, since the parameter
|
||||||
has different template arguments than the current ones.
|
has different template arguments than the current ones.
|
||||||
|
|
||||||
The constructor tries to convert the internal `m_value` of the parameter.
|
The constructor tries to convert the internal `m_value` of the parameter. Each member value (object, array, string,
|
||||||
|
etc.) is serialized via the corresponding `to_json()` overload. For objects and strings, the conversion requires
|
||||||
|
that the *target* `basic_json` type's `object_t::key_type` (or `string_t`) be directly constructible from the
|
||||||
|
*source* type's corresponding member type via `is_constructible`. If this requirement is not met, the conversion
|
||||||
|
does not fail to compile; instead, it silently falls back to the array-conversion path, which represents objects
|
||||||
|
as arrays of `[key, value]` pairs and strings as arrays of character codes. This is a known limitation tracked in
|
||||||
|
[issue #3425](https://github.com/nlohmann/json/issues/3425).
|
||||||
|
|
||||||
5. Creates a JSON value of type array or object from the passed initializer list `init`. In case `type_deduction` is
|
5. Creates a JSON value of type array or object from the passed initializer list `init`. In case `type_deduction` is
|
||||||
`#!cpp true` (default), the type of the JSON value to be created is deducted from the initializer list `init`
|
`#!cpp true` (default), the type of the JSON value to be created is deducted from the initializer list `init`
|
||||||
@@ -109,7 +115,22 @@ basic_json(basic_json&& other) noexcept;
|
|||||||
|
|
||||||
Function [`array()`](array.md) and [`object()`](object.md) force array and object creation from initializer lists,
|
Function [`array()`](array.md) and [`object()`](object.md) force array and object creation from initializer lists,
|
||||||
respectively.
|
respectively.
|
||||||
|
|
||||||
|
!!! warning "Brace initialization yields arrays"
|
||||||
|
|
||||||
|
Because this constructor takes an `initializer_list_t`, brace-initializing a `json`/`ordered_json` from
|
||||||
|
another `json` value wraps it in a single-element array rather than copying it:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
json j1 = "hello";
|
||||||
|
json j2{j1}; // [!] j2 is ["hello"], NOT a copy of j1
|
||||||
|
json j3(j1); // j3 is "hello" -- parentheses copy as expected
|
||||||
|
```
|
||||||
|
|
||||||
|
See the FAQ entry on [brace initialization](../../home/faq.md#brace-initialization-yields-arrays) for the
|
||||||
|
full explanation, an opt-in macro to change this behavior, and how to explicitly create a single-element
|
||||||
|
array (`json::array({value})`) if that is what you want.
|
||||||
|
|
||||||
6. Constructs a JSON array value by creating `cnt` copies of a passed value. In case `cnt` is `0`, an empty array is
|
6. Constructs a JSON array value by creating `cnt` copies of a passed value. In case `cnt` is `0`, an empty array is
|
||||||
created.
|
created.
|
||||||
|
|
||||||
@@ -146,6 +167,11 @@ basic_json(basic_json&& other) noexcept;
|
|||||||
|
|
||||||
- `BasicJsonType` is a `basic_json` type.
|
- `BasicJsonType` is a `basic_json` type.
|
||||||
- `BasicJsonType` has different template arguments than `basic_json_t`.
|
- `BasicJsonType` has different template arguments than `basic_json_t`.
|
||||||
|
|
||||||
|
**Note:** For cross-`basic_json` conversions to produce correct results, the target `basic_json`'s
|
||||||
|
`object_t::key_type` and `string_t` must be directly constructible from the source `basic_json`'s
|
||||||
|
corresponding types. See the description of overload (4) above for details on what happens when
|
||||||
|
this requirement is not met.
|
||||||
|
|
||||||
`U`:
|
`U`:
|
||||||
: `uncvref_t<CompatibleType>`
|
: `uncvref_t<CompatibleType>`
|
||||||
|
|||||||
@@ -13,9 +13,8 @@ is compatible with both of the binary data formats that use binary subtyping, (t
|
|||||||
incompatible with each other, and it is up to the user to translate between them). The subtype is added to `BinaryType`
|
incompatible with each other, and it is up to the user to translate between them). The subtype is added to `BinaryType`
|
||||||
via the helper type [byte_container_with_subtype](../byte_container_with_subtype/index.md).
|
via the helper type [byte_container_with_subtype](../byte_container_with_subtype/index.md).
|
||||||
|
|
||||||
[CBOR's RFC 7049](https://tools.ietf.org/html/rfc7049) describes this type as:
|
[CBOR's RFC 8949](https://www.rfc-editor.org/rfc/rfc8949.html#section-3.1) describes this type as:
|
||||||
> Major type 2: a byte string. The string's length in bytes is represented following the rules for positive integers
|
> Major type 2: A byte string. The number of bytes in the string is equal to the argument.
|
||||||
> (major type 0).
|
|
||||||
|
|
||||||
[MessagePack's documentation on the bin type
|
[MessagePack's documentation on the bin type
|
||||||
family](https://github.com/msgpack/msgpack/blob/master/spec.md#bin-format-family) describes this type as:
|
family](https://github.com/msgpack/msgpack/blob/master/spec.md#bin-format-family) describes this type as:
|
||||||
@@ -37,12 +36,52 @@ represent a byte array in modern C++.
|
|||||||
`BinaryType`
|
`BinaryType`
|
||||||
: container type to store arrays
|
: container type to store arrays
|
||||||
|
|
||||||
|
Although not formally expressed as a C++ concept, `BinaryType` must be default-constructible,
|
||||||
|
copy/move-constructible, and support `push_back()`, `.data()`, and `.size()`, because
|
||||||
|
[`byte_container_with_subtype`](../byte_container_with_subtype/index.md) derives directly from it. Its
|
||||||
|
`value_type` must additionally be exactly one byte wide (e.g., `std::uint8_t`/`char`/`std::byte`): the binary
|
||||||
|
serializers (CBOR, MessagePack, BSON, UBJSON) read and write the container's raw bytes via
|
||||||
|
`reinterpret_cast`, which is only correct for byte-sized elements -- a container like
|
||||||
|
`#!cpp std::vector<std::intptr_t>` will not work as `BinaryType`.
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
#### Default type
|
#### Default type
|
||||||
|
|
||||||
The default values for `BinaryType` is `#!cpp std::vector<std::uint8_t>`.
|
The default values for `BinaryType` is `#!cpp std::vector<std::uint8_t>`.
|
||||||
|
|
||||||
|
#### Custom BinaryType behavior
|
||||||
|
|
||||||
|
When a custom `BinaryType` is configured (other than the default `#!cpp std::vector<std::uint8_t>`), you can assign
|
||||||
|
values of that type directly to a `basic_json` instance, and they will automatically be recognized as binary values
|
||||||
|
rather than arrays:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
using custom_json = nlohmann::basic_json<
|
||||||
|
nlohmann::ordered_map, // ObjectType
|
||||||
|
std::vector, // ArrayType
|
||||||
|
std::string, // StringType
|
||||||
|
bool, // BooleanType
|
||||||
|
std::int64_t, // NumberIntegerType
|
||||||
|
std::uint64_t, // NumberUnsignedType
|
||||||
|
double, // NumberFloatType
|
||||||
|
std::allocator, // AllocatorType
|
||||||
|
nlohmann::adl_serializer,
|
||||||
|
std::vector<std::byte> // Custom BinaryType
|
||||||
|
>;
|
||||||
|
|
||||||
|
std::vector<std::byte> data{std::byte{1}, std::byte{2}, std::byte{3}};
|
||||||
|
custom_json j = data; // Creates a binary value, not an array
|
||||||
|
assert(j.is_binary());
|
||||||
|
|
||||||
|
// Round-tripping works seamlessly
|
||||||
|
auto extracted = j.get<std::vector<std::byte>>();
|
||||||
|
assert(extracted == data);
|
||||||
|
```
|
||||||
|
|
||||||
|
This automatic type detection is a convenience feature that only applies to custom (non-default) `BinaryType` configurations.
|
||||||
|
The default `nlohmann::json` continues to treat `#!cpp std::vector<std::uint8_t>` as arrays for backward compatibility.
|
||||||
|
|
||||||
#### Storage
|
#### Storage
|
||||||
|
|
||||||
Binary Arrays are stored as pointers in a `basic_json` type. That is, for any access to array values, a pointer of the
|
Binary Arrays are stored as pointers in a `basic_json` type. That is, for any access to array values, a pointer of the
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ The type used to store JSON booleans.
|
|||||||
[RFC 8259](https://tools.ietf.org/html/rfc8259) implicitly describes a boolean as a type which differentiates the two
|
[RFC 8259](https://tools.ietf.org/html/rfc8259) implicitly describes a boolean as a type which differentiates the two
|
||||||
literals `#!json true` and `#!json false`.
|
literals `#!json true` and `#!json false`.
|
||||||
|
|
||||||
To store objects in C++, a type is defined by the template parameter `BooleanType` which chooses the type to use.
|
To store boolean values in C++, a type is defined by the template parameter `BooleanType` which chooses the type to use.
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
|
|||||||
@@ -48,11 +48,7 @@ Strong exception safety: if an exception occurs, the original value stays intact
|
|||||||
|
|
||||||
1. The function does not throw exceptions.
|
1. The function does not throw exceptions.
|
||||||
2. The function does not throw exceptions.
|
2. The function does not throw exceptions.
|
||||||
3. The function can throw the following exceptions:
|
3. The function does not throw exceptions.
|
||||||
- Throws [`parse_error.106`](../../home/exceptions.md#jsonexceptionparse_error106) if an array index begins with
|
|
||||||
`0`.
|
|
||||||
- Throws [`parse_error.109`](../../home/exceptions.md#jsonexceptionparse_error109) if an array index was not a
|
|
||||||
number.
|
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
@@ -111,6 +107,11 @@ Logarithmic in the size of the JSON object.
|
|||||||
--8<-- "examples/contains__json_pointer.output"
|
--8<-- "examples/contains__json_pointer.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [find](find.md) find a value in an object
|
||||||
|
- [count](count.md) returns the number of occurrences of a key
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
1. Added in version 3.11.0.
|
1. Added in version 3.11.0.
|
||||||
|
|||||||
@@ -72,6 +72,11 @@ This method always returns `0` when executed on a JSON type that is not an objec
|
|||||||
--8<-- "examples/count__keytype.c++17.output"
|
--8<-- "examples/count__keytype.c++17.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [find](find.md) find a value in an object
|
||||||
|
- [contains](contains.md) checks whether a key exists
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
1. Added in version 3.11.0.
|
1. Added in version 3.11.0.
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ Returns an iterator to the reverse-beginning; that is, the last element.
|
|||||||
|
|
||||||
## Return value
|
## Return value
|
||||||
|
|
||||||
reverse iterator to the first element
|
reverse iterator to the last element
|
||||||
|
|
||||||
## Exception safety
|
## Exception safety
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ Constant.
|
|||||||
|
|
||||||
??? example
|
??? example
|
||||||
|
|
||||||
The following code shows an example for `eend()`.
|
The following code shows an example for `crend()`.
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
--8<-- "examples/crend.cpp"
|
--8<-- "examples/crend.cpp"
|
||||||
|
|||||||
@@ -56,6 +56,9 @@ Currently, only `remove`, `add`, and `replace` operations are generated.
|
|||||||
## See also
|
## See also
|
||||||
|
|
||||||
- [RFC 6902 (JSON Patch)](https://tools.ietf.org/html/rfc6902)
|
- [RFC 6902 (JSON Patch)](https://tools.ietf.org/html/rfc6902)
|
||||||
|
- [patch](patch.md) applies a JSON Patch
|
||||||
|
- [patch_inplace](patch_inplace.md) applies a JSON Patch in place
|
||||||
|
- [merge_patch](merge_patch.md) applies a JSON Merge Patch
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -26,9 +26,9 @@ and `ensure_ascii` parameters.
|
|||||||
|
|
||||||
`error_handler` (in)
|
`error_handler` (in)
|
||||||
: how to react on decoding errors; there are three possible values (see [`error_handler_t`](error_handler_t.md):
|
: how to react on decoding errors; there are three possible values (see [`error_handler_t`](error_handler_t.md):
|
||||||
`strict` (throws and exception in case a decoding error occurs; default), `replace` (replace invalid UTF-8 sequences
|
`strict` (throws an exception in case a decoding error occurs; default), `replace` (replace invalid UTF-8 sequences
|
||||||
with U+FFFD), and `ignore` (ignore invalid UTF-8 sequences during serialization; all bytes are copied to the output
|
with U+FFFD), and `ignore` (ignore invalid UTF-8 sequences during serialization; all valid bytes are copied to the
|
||||||
unchanged)).
|
output unchanged, and invalid bytes are dropped)).
|
||||||
|
|
||||||
## Return value
|
## Return value
|
||||||
|
|
||||||
@@ -43,6 +43,17 @@ Strong guarantee: if an exception is thrown, there are no changes to any JSON va
|
|||||||
Throws [`type_error.316`](../../home/exceptions.md#jsonexceptiontype_error316) if a string stored inside the JSON value
|
Throws [`type_error.316`](../../home/exceptions.md#jsonexceptiontype_error316) if a string stored inside the JSON value
|
||||||
is not UTF-8 encoded and `error_handler` is set to `strict`
|
is not UTF-8 encoded and `error_handler` is set to `strict`
|
||||||
|
|
||||||
|
!!! warning "Serializing untrusted input"
|
||||||
|
|
||||||
|
When serializing values that may contain invalid or untrusted UTF-8 (e.g., bytes taken directly from network
|
||||||
|
input), `dump()` throws [`type_error.316`](../../home/exceptions.md#jsonexceptiontype_error316) in the default
|
||||||
|
`strict` mode. To serialize such data without throwing, pass
|
||||||
|
[`error_handler_t::replace`](error_handler_t.md) (substitutes U+FFFD) or
|
||||||
|
[`error_handler_t::ignore`](error_handler_t.md). Callers that serialize untrusted input on a crash-sensitive path
|
||||||
|
should either choose a non-strict error handler or wrap `dump()` in a `#!cpp try`/`#!cpp catch`.
|
||||||
|
|
||||||
|
See the [FAQ](../../home/faq.md#serializing-untrusted-or-invalid-utf-8) for details.
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
Linear.
|
Linear.
|
||||||
@@ -71,6 +82,12 @@ Binary values are serialized as an object containing two keys:
|
|||||||
--8<-- "examples/dump.output"
|
--8<-- "examples/dump.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [to_string](to_string.md) returns a string representation of a JSON value
|
||||||
|
- [operator<<](../operator_ltlt.md) serialize to stream
|
||||||
|
- [Serialization](../../features/serialization.md) - the serialization article
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 1.0.0.
|
- Added in version 1.0.0.
|
||||||
|
|||||||
@@ -29,6 +29,10 @@ iterators (including the `end()` iterator) and all references to the elements ar
|
|||||||
a pair consisting of an iterator to the inserted element, or the already-existing element if no insertion happened, and
|
a pair consisting of an iterator to the inserted element, or the already-existing element if no insertion happened, and
|
||||||
a `#!cpp bool` denoting whether the insertion took place.
|
a `#!cpp bool` denoting whether the insertion took place.
|
||||||
|
|
||||||
|
## Exception safety
|
||||||
|
|
||||||
|
Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
|
||||||
|
|
||||||
## Exceptions
|
## Exceptions
|
||||||
|
|
||||||
Throws [`type_error.311`](../../home/exceptions.md#jsonexceptiontype_error311) when called on a type other than JSON
|
Throws [`type_error.311`](../../home/exceptions.md#jsonexceptiontype_error311) when called on a type other than JSON
|
||||||
@@ -56,6 +60,12 @@ Logarithmic in the size of the container, O(log(`size()`)).
|
|||||||
--8<-- "examples/emplace.output"
|
--8<-- "examples/emplace.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [emplace_back](emplace_back.md) add a value to an array
|
||||||
|
- [insert](insert.md) add values to an array/object
|
||||||
|
- [Modifying values](../../features/modifying_values.md) - the article on modifying values
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Since version 2.0.8.
|
- Since version 2.0.8.
|
||||||
@@ -58,6 +58,7 @@ Amortized constant.
|
|||||||
|
|
||||||
- [operator+=](operator+=.md) add a value to an array/object
|
- [operator+=](operator+=.md) add a value to an array/object
|
||||||
- [push_back](push_back.md) add a value to an array/object
|
- [push_back](push_back.md) add a value to an array/object
|
||||||
|
- [Modifying values](../../features/modifying_values.md) - the article on modifying values
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ Strong exception safety: if an exception occurs, the original value stays intact
|
|||||||
4. See 3.
|
4. See 3.
|
||||||
5. The function can throw the following exceptions:
|
5. The function can throw the following exceptions:
|
||||||
- Throws [`type_error.307`](../../home/exceptions.md#jsonexceptiontype_error307) when called on a type other than
|
- Throws [`type_error.307`](../../home/exceptions.md#jsonexceptiontype_error307) when called on a type other than
|
||||||
JSON object; example: `"cannot use erase() with null"`
|
JSON array; example: `"cannot use erase() with null"`
|
||||||
- Throws [`out_of_range.401`](../../home/exceptions.md#jsonexceptionout_of_range401) when `idx >= size()`; example:
|
- Throws [`out_of_range.401`](../../home/exceptions.md#jsonexceptionout_of_range401) when `idx >= size()`; example:
|
||||||
`"array index 17 is out of range"`
|
`"array index 17 is out of range"`
|
||||||
|
|
||||||
@@ -202,6 +202,12 @@ Strong exception safety: if an exception occurs, the original value stays intact
|
|||||||
--8<-- "examples/erase__size_type.output"
|
--8<-- "examples/erase__size_type.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [clear](clear.md) clears the contents
|
||||||
|
- [insert](insert.md) add values to an array/object
|
||||||
|
- [Modifying values](../../features/modifying_values.md) - the article on modifying values
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
1. Added in version 1.0.0. Added support for binary types in version 3.8.0.
|
1. Added in version 1.0.0. Added support for binary types in version 3.8.0.
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ replace
|
|||||||
: replace invalid UTF-8 sequences with U+FFFD (� REPLACEMENT CHARACTER)
|
: replace invalid UTF-8 sequences with U+FFFD (� REPLACEMENT CHARACTER)
|
||||||
|
|
||||||
ignore
|
ignore
|
||||||
: ignore invalid UTF-8 sequences; all bytes are copied to the output unchanged
|
: ignore invalid UTF-8 sequences; all valid bytes are copied to the output unchanged, and invalid bytes are dropped
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ This method always returns `end()` when executed on a JSON type that is not an o
|
|||||||
|
|
||||||
## See also
|
## See also
|
||||||
|
|
||||||
|
- [count](count.md) returns the number of occurrences of a key
|
||||||
- [contains](contains.md) checks whether a key exists
|
- [contains](contains.md) checks whether a key exists
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
# format_as(basic_json)
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
template <typename BasicJsonType>
|
||||||
|
std::string format_as(const BasicJsonType& j);
|
||||||
|
```
|
||||||
|
|
||||||
|
This function implements the [`format_as`](https://fmt.dev/latest/api/#formatting-user-defined-types)
|
||||||
|
customization point used by the [{fmt}](https://github.com/fmtlib/fmt) library (fmtlib). It has no
|
||||||
|
dependency on any `fmt` header and no effect at all unless a caller's translation unit also includes
|
||||||
|
`fmt` and calls `fmt::format`/`fmt::print` on a JSON value.
|
||||||
|
|
||||||
|
## Template parameters
|
||||||
|
|
||||||
|
`BasicJsonType`
|
||||||
|
: a specialization of [`basic_json`](index.md)
|
||||||
|
|
||||||
|
## Return value
|
||||||
|
|
||||||
|
string containing the serialization of the JSON value (same as [`dump()`](dump.md))
|
||||||
|
|
||||||
|
## Exception safety
|
||||||
|
|
||||||
|
Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
|
||||||
|
|
||||||
|
## Exceptions
|
||||||
|
|
||||||
|
Throws [`type_error.316`](../../home/exceptions.md#jsonexceptiontype_error316) if a string stored inside the JSON value
|
||||||
|
is not UTF-8 encoded
|
||||||
|
|
||||||
|
## Complexity
|
||||||
|
|
||||||
|
Linear.
|
||||||
|
|
||||||
|
## Possible implementation
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
template <typename BasicJsonType>
|
||||||
|
std::string format_as(const BasicJsonType& j)
|
||||||
|
{
|
||||||
|
return j.dump();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
!!! warning "Version-dependent effect on fmt"
|
||||||
|
|
||||||
|
`fmt` only picks up a `format_as` overload that returns a `std::string` in fmt **10.0.0 through
|
||||||
|
11.0.2**. Starting with fmt **11.1.0**, `fmt` restricts automatic `format_as` pickup to overloads that
|
||||||
|
return an arithmetic type, so this function has no effect there (it is simply unused, not a compile
|
||||||
|
error).
|
||||||
|
|
||||||
|
If you use fmt \>= 11.1.0, or want the same pretty-print spec support that
|
||||||
|
[`std::formatter<basic_json>`](std_formatter.md) has (`#!cpp "{:#}"`, a width to set the indent such
|
||||||
|
as `#!cpp "{:2}"`/`#!cpp "{:#2}"`, and fill-and-align to pick the indent character such as
|
||||||
|
`#!cpp "{:.>#}"`), define your own `fmt::formatter` specialization mirroring the same logic:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "../../../tests/fmt_formatter/project/main.cpp:formatter_recipe"
|
||||||
|
```
|
||||||
|
|
||||||
|
This recipe isn't shipped by the library itself, since doing so would make `fmt` a build dependency
|
||||||
|
(see the FAQ entry on
|
||||||
|
[using JSON values with `std::format` or `fmt`](../../home/faq.md#using-json-values-with-stdformat-or-fmt)
|
||||||
|
for more background) — but it *is* compiled and exercised against a real, current `fmt` release as
|
||||||
|
part of the library's own test suite (`tests/fmt_formatter`, via CMake `FetchContent`), so it's kept in
|
||||||
|
sync with `std::formatter<basic_json>` and verified to actually work, not just illustrative.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The following code shows how the library's `format_as()` function integrates with `fmt::format`,
|
||||||
|
allowing argument-dependent lookup.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/format_as.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```json
|
||||||
|
--8<-- "examples/format_as.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [dump](dump.md)
|
||||||
|
- [std::formatter<basic_json>](std_formatter.md) - the `std::format` (C++20) equivalent
|
||||||
|
- [Serialization](../../features/serialization.md) - the serialization article
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.13.0.
|
||||||
@@ -7,8 +7,8 @@ static basic_json from_bjdata(InputType&& i,
|
|||||||
const bool strict = true,
|
const bool strict = true,
|
||||||
const bool allow_exceptions = true);
|
const bool allow_exceptions = true);
|
||||||
// (2)
|
// (2)
|
||||||
template<typename IteratorType>
|
template<typename IteratorType, typename SentinelType = IteratorType>
|
||||||
static basic_json from_bjdata(IteratorType first, IteratorType last,
|
static basic_json from_bjdata(IteratorType first, SentinelType last,
|
||||||
const bool strict = true,
|
const bool strict = true,
|
||||||
const bool allow_exceptions = true);
|
const bool allow_exceptions = true);
|
||||||
```
|
```
|
||||||
@@ -16,7 +16,7 @@ static basic_json from_bjdata(IteratorType first, IteratorType last,
|
|||||||
Deserializes a given input to a JSON value using the BJData (Binary JData) serialization format.
|
Deserializes a given input to a JSON value using the BJData (Binary JData) serialization format.
|
||||||
|
|
||||||
1. Reads from a compatible input.
|
1. Reads from a compatible input.
|
||||||
2. Reads from an iterator range.
|
2. Reads from an iterator range, or an iterator and a sentinel of a different type (C++20 ranges support).
|
||||||
|
|
||||||
The exact mapping and its limitations are described on a [dedicated page](../../features/binary_formats/bjdata.md).
|
The exact mapping and its limitations are described on a [dedicated page](../../features/binary_formats/bjdata.md).
|
||||||
|
|
||||||
@@ -29,11 +29,18 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
|||||||
- a `FILE` pointer
|
- a `FILE` pointer
|
||||||
- a C-style array of characters
|
- a C-style array of characters
|
||||||
- a pointer to a null-terminated string of single byte characters
|
- a pointer to a null-terminated string of single byte characters
|
||||||
- an object `obj` for which `begin(obj)` and `end(obj)` produces a valid pair of iterators.
|
- a container `obj` for which `begin(obj)` and `end(obj)` produce a valid pair of iterators
|
||||||
|
(as found via ADL or member functions, with semantics compatible to `std::begin` and `std::end`)
|
||||||
|
|
||||||
`IteratorType`
|
`IteratorType`
|
||||||
: a compatible iterator type
|
: a compatible iterator type
|
||||||
|
|
||||||
|
`SentinelType`
|
||||||
|
: defaults to `IteratorType`; may be a different type comparable to `IteratorType` via `operator!=`, for instance.
|
||||||
|
|
||||||
|
- a custom sentinel type for C++20 ranges
|
||||||
|
- `std::default_sentinel_t`, when `IteratorType` is `std::counted_iterator`
|
||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
`i` (in)
|
`i` (in)
|
||||||
@@ -43,7 +50,7 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
|||||||
: iterator to the start of the input
|
: iterator to the start of the input
|
||||||
|
|
||||||
`last` (in)
|
`last` (in)
|
||||||
: iterator to the end of the input
|
: iterator to the end of the input, or a sentinel value that compares equal to the end iterator with `operator!=`
|
||||||
|
|
||||||
`strict` (in)
|
`strict` (in)
|
||||||
: whether to expect the input to be consumed until EOF (`#!cpp true` by default)
|
: whether to expect the input to be consumed until EOF (`#!cpp true` by default)
|
||||||
@@ -67,6 +74,8 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
|
|||||||
- Throws [parse_error.112](../../home/exceptions.md#jsonexceptionparse_error112) if a parse error occurs
|
- Throws [parse_error.112](../../home/exceptions.md#jsonexceptionparse_error112) if a parse error occurs
|
||||||
- Throws [parse_error.113](../../home/exceptions.md#jsonexceptionparse_error113) if a string could not be parsed
|
- Throws [parse_error.113](../../home/exceptions.md#jsonexceptionparse_error113) if a string could not be parsed
|
||||||
successfully
|
successfully
|
||||||
|
- Throws [out_of_range.408](../../home/exceptions.md#jsonexceptionout_of_range408) if the size of an optimized container
|
||||||
|
or n-dimensional array cannot be represented by `std::size_t`
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
@@ -88,6 +97,16 @@ Linear in the size of the input.
|
|||||||
--8<-- "examples/from_bjdata.output"
|
--8<-- "examples/from_bjdata.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [to_bjdata](to_bjdata.md) create a BJData serialization of a JSON value
|
||||||
|
- [from_cbor](from_cbor.md) create a JSON value from an input in CBOR format
|
||||||
|
- [from_msgpack](from_msgpack.md) create a JSON value from an input in MessagePack format
|
||||||
|
- [from_bson](from_bson.md) create a JSON value from an input in BSON format
|
||||||
|
- [from_ubjson](from_ubjson.md) create a JSON value from an input in UBJSON format
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 3.11.0.
|
- Added in version 3.11.0.
|
||||||
|
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
|
||||||
|
- Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0.
|
||||||
@@ -7,8 +7,8 @@ static basic_json from_bson(InputType&& i,
|
|||||||
const bool strict = true,
|
const bool strict = true,
|
||||||
const bool allow_exceptions = true);
|
const bool allow_exceptions = true);
|
||||||
// (2)
|
// (2)
|
||||||
template<typename IteratorType>
|
template<typename IteratorType, typename SentinelType = IteratorType>
|
||||||
static basic_json from_bson(IteratorType first, IteratorType last,
|
static basic_json from_bson(IteratorType first, SentinelType last,
|
||||||
const bool strict = true,
|
const bool strict = true,
|
||||||
const bool allow_exceptions = true);
|
const bool allow_exceptions = true);
|
||||||
```
|
```
|
||||||
@@ -16,7 +16,7 @@ static basic_json from_bson(IteratorType first, IteratorType last,
|
|||||||
Deserializes a given input to a JSON value using the BSON (Binary JSON) serialization format.
|
Deserializes a given input to a JSON value using the BSON (Binary JSON) serialization format.
|
||||||
|
|
||||||
1. Reads from a compatible input.
|
1. Reads from a compatible input.
|
||||||
2. Reads from an iterator range.
|
2. Reads from an iterator range, or an iterator and a sentinel of a different type (C++20 ranges support).
|
||||||
|
|
||||||
The exact mapping and its limitations are described on a [dedicated page](../../features/binary_formats/bson.md).
|
The exact mapping and its limitations are described on a [dedicated page](../../features/binary_formats/bson.md).
|
||||||
|
|
||||||
@@ -29,11 +29,18 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
|||||||
- a `FILE` pointer
|
- a `FILE` pointer
|
||||||
- a C-style array of characters
|
- a C-style array of characters
|
||||||
- a pointer to a null-terminated string of single byte characters
|
- a pointer to a null-terminated string of single byte characters
|
||||||
- an object `obj` for which `begin(obj)` and `end(obj)` produces a valid pair of iterators.
|
- a container `obj` for which `begin(obj)` and `end(obj)` produce a valid pair of iterators
|
||||||
|
(as found via ADL or member functions, with semantics compatible to `std::begin` and `std::end`)
|
||||||
|
|
||||||
`IteratorType`
|
`IteratorType`
|
||||||
: a compatible iterator type
|
: a compatible iterator type
|
||||||
|
|
||||||
|
`SentinelType`
|
||||||
|
: defaults to `IteratorType`; may be a different type comparable to `IteratorType` via `operator!=`, for instance.
|
||||||
|
|
||||||
|
- a custom sentinel type for C++20 ranges
|
||||||
|
- `std::default_sentinel_t`, when `IteratorType` is `std::counted_iterator`
|
||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
`i` (in)
|
`i` (in)
|
||||||
@@ -43,7 +50,7 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
|||||||
: iterator to the start of the input
|
: iterator to the start of the input
|
||||||
|
|
||||||
`last` (in)
|
`last` (in)
|
||||||
: iterator to the end of the input
|
: iterator to the end of the input, or a sentinel value that compares equal to the end iterator with `operator!=`
|
||||||
|
|
||||||
`strict` (in)
|
`strict` (in)
|
||||||
: whether to expect the input to be consumed until EOF (`#!cpp true` by default)
|
: whether to expect the input to be consumed until EOF (`#!cpp true` by default)
|
||||||
@@ -62,8 +69,12 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
|
|||||||
|
|
||||||
## Exceptions
|
## Exceptions
|
||||||
|
|
||||||
Throws [`parse_error.114`](../../home/exceptions.md#jsonexceptionparse_error114) if an unsupported BSON record type is
|
- Throws [`parse_error.110`](../../home/exceptions.md#jsonexceptionparse_error110) if the given input ends prematurely or
|
||||||
encountered.
|
the end of the input was not reached when `strict` was set to true
|
||||||
|
- Throws [`parse_error.112`](../../home/exceptions.md#jsonexceptionparse_error112) if a parse error occurs (e.g., an
|
||||||
|
invalid string or byte array length)
|
||||||
|
- Throws [`parse_error.114`](../../home/exceptions.md#jsonexceptionparse_error114) if an unsupported BSON record type is
|
||||||
|
encountered
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
@@ -92,10 +103,13 @@ Linear in the size of the input.
|
|||||||
- [from_cbor](from_cbor.md) for the related CBOR format
|
- [from_cbor](from_cbor.md) for the related CBOR format
|
||||||
- [from_msgpack](from_msgpack.md) for the related MessagePack format
|
- [from_msgpack](from_msgpack.md) for the related MessagePack format
|
||||||
- [from_ubjson](from_ubjson.md) for the related UBJSON format
|
- [from_ubjson](from_ubjson.md) for the related UBJSON format
|
||||||
|
- [from_bjdata](from_bjdata.md) for the related BJData format
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 3.4.0.
|
- Added in version 3.4.0.
|
||||||
|
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
|
||||||
|
- Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0.
|
||||||
|
|
||||||
!!! warning "Deprecation"
|
!!! warning "Deprecation"
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ static basic_json from_cbor(InputType&& i,
|
|||||||
const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error);
|
const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error);
|
||||||
|
|
||||||
// (2)
|
// (2)
|
||||||
template<typename IteratorType>
|
template<typename IteratorType, typename SentinelType = IteratorType>
|
||||||
static basic_json from_cbor(IteratorType first, IteratorType last,
|
static basic_json from_cbor(IteratorType first, SentinelType last,
|
||||||
const bool strict = true,
|
const bool strict = true,
|
||||||
const bool allow_exceptions = true,
|
const bool allow_exceptions = true,
|
||||||
const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error);
|
const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error);
|
||||||
@@ -19,7 +19,7 @@ static basic_json from_cbor(IteratorType first, IteratorType last,
|
|||||||
Deserializes a given input to a JSON value using the CBOR (Concise Binary Object Representation) serialization format.
|
Deserializes a given input to a JSON value using the CBOR (Concise Binary Object Representation) serialization format.
|
||||||
|
|
||||||
1. Reads from a compatible input.
|
1. Reads from a compatible input.
|
||||||
2. Reads from an iterator range.
|
2. Reads from an iterator range, or an iterator and a sentinel of a different type (C++20 ranges support).
|
||||||
|
|
||||||
The exact mapping and its limitations are described on a [dedicated page](../../features/binary_formats/cbor.md).
|
The exact mapping and its limitations are described on a [dedicated page](../../features/binary_formats/cbor.md).
|
||||||
|
|
||||||
@@ -32,11 +32,18 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
|||||||
- a `FILE` pointer
|
- a `FILE` pointer
|
||||||
- a C-style array of characters
|
- a C-style array of characters
|
||||||
- a pointer to a null-terminated string of single byte characters
|
- a pointer to a null-terminated string of single byte characters
|
||||||
- an object `obj` for which `begin(obj)` and `end(obj)` produces a valid pair of iterators.
|
- a container `obj` for which `begin(obj)` and `end(obj)` produce a valid pair of iterators
|
||||||
|
(as found via ADL or member functions, with semantics compatible to `std::begin` and `std::end`)
|
||||||
|
|
||||||
`IteratorType`
|
`IteratorType`
|
||||||
: a compatible iterator type
|
: a compatible iterator type
|
||||||
|
|
||||||
|
`SentinelType`
|
||||||
|
: defaults to `IteratorType`; may be a different type comparable to `IteratorType` via `operator!=`, for instance.
|
||||||
|
|
||||||
|
- a custom sentinel type for C++20 ranges
|
||||||
|
- `std::default_sentinel_t`, when `IteratorType` is `std::counted_iterator`
|
||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
`i` (in)
|
`i` (in)
|
||||||
@@ -46,7 +53,7 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
|||||||
: iterator to the start of the input
|
: iterator to the start of the input
|
||||||
|
|
||||||
`last` (in)
|
`last` (in)
|
||||||
: iterator to the end of the input
|
: iterator to the end of the input, or a sentinel value that compares equal to the end iterator with `operator!=`
|
||||||
|
|
||||||
`strict` (in)
|
`strict` (in)
|
||||||
: whether to expect the input to be consumed until EOF (`#!cpp true` by default)
|
: whether to expect the input to be consumed until EOF (`#!cpp true` by default)
|
||||||
@@ -96,6 +103,14 @@ Linear in the size of the input.
|
|||||||
--8<-- "examples/from_cbor.output"
|
--8<-- "examples/from_cbor.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [to_cbor](to_cbor.md) create a CBOR serialization of a JSON value
|
||||||
|
- [from_msgpack](from_msgpack.md) create a JSON value from an input in MessagePack format
|
||||||
|
- [from_bson](from_bson.md) create a JSON value from an input in BSON format
|
||||||
|
- [from_ubjson](from_ubjson.md) create a JSON value from an input in UBJSON format
|
||||||
|
- [from_bjdata](from_bjdata.md) create a JSON value from an input in BJData format
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 2.0.9.
|
- Added in version 2.0.9.
|
||||||
@@ -103,6 +118,8 @@ Linear in the size of the input.
|
|||||||
- Changed to consume input adapters, removed `start_index` parameter, and added `strict` parameter in version 3.0.0.
|
- Changed to consume input adapters, removed `start_index` parameter, and added `strict` parameter in version 3.0.0.
|
||||||
- Added `allow_exceptions` parameter in version 3.2.0.
|
- Added `allow_exceptions` parameter in version 3.2.0.
|
||||||
- Added `tag_handler` parameter in version 3.9.0.
|
- Added `tag_handler` parameter in version 3.9.0.
|
||||||
|
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
|
||||||
|
- Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0.
|
||||||
|
|
||||||
!!! warning "Deprecation"
|
!!! warning "Deprecation"
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ static basic_json from_msgpack(InputType&& i,
|
|||||||
const bool strict = true,
|
const bool strict = true,
|
||||||
const bool allow_exceptions = true);
|
const bool allow_exceptions = true);
|
||||||
// (2)
|
// (2)
|
||||||
template<typename IteratorType>
|
template<typename IteratorType, typename SentinelType = IteratorType>
|
||||||
static basic_json from_msgpack(IteratorType first, IteratorType last,
|
static basic_json from_msgpack(IteratorType first, SentinelType last,
|
||||||
const bool strict = true,
|
const bool strict = true,
|
||||||
const bool allow_exceptions = true);
|
const bool allow_exceptions = true);
|
||||||
```
|
```
|
||||||
@@ -16,7 +16,7 @@ static basic_json from_msgpack(IteratorType first, IteratorType last,
|
|||||||
Deserializes a given input to a JSON value using the MessagePack serialization format.
|
Deserializes a given input to a JSON value using the MessagePack serialization format.
|
||||||
|
|
||||||
1. Reads from a compatible input.
|
1. Reads from a compatible input.
|
||||||
2. Reads from an iterator range.
|
2. Reads from an iterator range, or an iterator and a sentinel of a different type (C++20 ranges support).
|
||||||
|
|
||||||
The exact mapping and its limitations are described on a [dedicated page](../../features/binary_formats/messagepack.md).
|
The exact mapping and its limitations are described on a [dedicated page](../../features/binary_formats/messagepack.md).
|
||||||
|
|
||||||
@@ -29,11 +29,18 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
|||||||
- a `FILE` pointer
|
- a `FILE` pointer
|
||||||
- a C-style array of characters
|
- a C-style array of characters
|
||||||
- a pointer to a null-terminated string of single byte characters
|
- a pointer to a null-terminated string of single byte characters
|
||||||
- an object `obj` for which `begin(obj)` and `end(obj)` produces a valid pair of iterators.
|
- a container `obj` for which `begin(obj)` and `end(obj)` produce a valid pair of iterators
|
||||||
|
(as found via ADL or member functions, with semantics compatible to `std::begin` and `std::end`)
|
||||||
|
|
||||||
`IteratorType`
|
`IteratorType`
|
||||||
: a compatible iterator type
|
: a compatible iterator type
|
||||||
|
|
||||||
|
`SentinelType`
|
||||||
|
: defaults to `IteratorType`; may be a different type comparable to `IteratorType` via `operator!=`, for instance.
|
||||||
|
|
||||||
|
- a custom sentinel type for C++20 ranges
|
||||||
|
- `std::default_sentinel_t`, when `IteratorType` is `std::counted_iterator`
|
||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
`i` (in)
|
`i` (in)
|
||||||
@@ -43,7 +50,7 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
|||||||
: iterator to the start of the input
|
: iterator to the start of the input
|
||||||
|
|
||||||
`last` (in)
|
`last` (in)
|
||||||
: iterator to the end of the input
|
: iterator to the end of the input, or a sentinel value that compares equal to the end iterator with `operator!=`
|
||||||
|
|
||||||
`strict` (in)
|
`strict` (in)
|
||||||
: whether to expect the input to be consumed until EOF (`#!cpp true` by default)
|
: whether to expect the input to be consumed until EOF (`#!cpp true` by default)
|
||||||
@@ -89,19 +96,29 @@ Linear in the size of the input.
|
|||||||
--8<-- "examples/from_msgpack.output"
|
--8<-- "examples/from_msgpack.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [to_msgpack](to_msgpack.md) create a MessagePack serialization of a JSON value
|
||||||
|
- [from_cbor](from_cbor.md) create a JSON value from an input in CBOR format
|
||||||
|
- [from_bson](from_bson.md) create a JSON value from an input in BSON format
|
||||||
|
- [from_ubjson](from_ubjson.md) create a JSON value from an input in UBJSON format
|
||||||
|
- [from_bjdata](from_bjdata.md) create a JSON value from an input in BJData format
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 2.0.9.
|
- Added in version 2.0.9.
|
||||||
- Parameter `start_index` since version 2.1.1.
|
- Parameter `start_index` since version 2.1.1.
|
||||||
- Changed to consume input adapters, removed `start_index` parameter, and added `strict` parameter in version 3.0.0.
|
- Changed to consume input adapters, removed `start_index` parameter, and added `strict` parameter in version 3.0.0.
|
||||||
- Added `allow_exceptions` parameter in version 3.2.0.
|
- Added `allow_exceptions` parameter in version 3.2.0.
|
||||||
|
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
|
||||||
|
- Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0.
|
||||||
|
|
||||||
!!! warning "Deprecation"
|
!!! warning "Deprecation"
|
||||||
|
|
||||||
- Overload (2) replaces calls to `from_msgpack` with a pointer and a length as first two parameters, which has been
|
- Overload (2) replaces calls to `from_msgpack` with a pointer and a length as first two parameters, which has been
|
||||||
deprecated in version 3.8.0. This overload will be removed in version 4.0.0. Please replace all calls like
|
deprecated in version 3.8.0. This overload will be removed in version 4.0.0. Please replace all calls like
|
||||||
`#!cpp from_msgpack(ptr, len, ...);` with `#!cpp from_msgpack(ptr, ptr+len, ...);`.
|
`#!cpp from_msgpack(ptr, len, ...);` with `#!cpp from_msgpack(ptr, ptr+len, ...);`.
|
||||||
- Overload (2) replaces calls to `from_cbor` with a pair of iterators as their first parameter, which has been
|
- Overload (2) replaces calls to `from_msgpack` with a pair of iterators as their first parameter, which has been
|
||||||
deprecated in version 3.8.0. This overload will be removed in version 4.0.0. Please replace all calls like
|
deprecated in version 3.8.0. This overload will be removed in version 4.0.0. Please replace all calls like
|
||||||
`#!cpp from_msgpack({ptr, ptr+len}, ...);` with `#!cpp from_msgpack(ptr, ptr+len, ...);`.
|
`#!cpp from_msgpack({ptr, ptr+len}, ...);` with `#!cpp from_msgpack(ptr, ptr+len, ...);`.
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ static basic_json from_ubjson(InputType&& i,
|
|||||||
const bool strict = true,
|
const bool strict = true,
|
||||||
const bool allow_exceptions = true);
|
const bool allow_exceptions = true);
|
||||||
// (2)
|
// (2)
|
||||||
template<typename IteratorType>
|
template<typename IteratorType, typename SentinelType = IteratorType>
|
||||||
static basic_json from_ubjson(IteratorType first, IteratorType last,
|
static basic_json from_ubjson(IteratorType first, SentinelType last,
|
||||||
const bool strict = true,
|
const bool strict = true,
|
||||||
const bool allow_exceptions = true);
|
const bool allow_exceptions = true);
|
||||||
```
|
```
|
||||||
@@ -16,7 +16,7 @@ static basic_json from_ubjson(IteratorType first, IteratorType last,
|
|||||||
Deserializes a given input to a JSON value using the UBJSON (Universal Binary JSON) serialization format.
|
Deserializes a given input to a JSON value using the UBJSON (Universal Binary JSON) serialization format.
|
||||||
|
|
||||||
1. Reads from a compatible input.
|
1. Reads from a compatible input.
|
||||||
2. Reads from an iterator range.
|
2. Reads from an iterator range, or an iterator and a sentinel of a different type (C++20 ranges support).
|
||||||
|
|
||||||
The exact mapping and its limitations are described on a [dedicated page](../../features/binary_formats/ubjson.md).
|
The exact mapping and its limitations are described on a [dedicated page](../../features/binary_formats/ubjson.md).
|
||||||
|
|
||||||
@@ -29,11 +29,18 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
|||||||
- a `FILE` pointer
|
- a `FILE` pointer
|
||||||
- a C-style array of characters
|
- a C-style array of characters
|
||||||
- a pointer to a null-terminated string of single byte characters
|
- a pointer to a null-terminated string of single byte characters
|
||||||
- an object `obj` for which `begin(obj)` and `end(obj)` produces a valid pair of iterators.
|
- a container `obj` for which `begin(obj)` and `end(obj)` produce a valid pair of iterators
|
||||||
|
(as found via ADL or member functions, with semantics compatible to `std::begin` and `std::end`)
|
||||||
|
|
||||||
`IteratorType`
|
`IteratorType`
|
||||||
: a compatible iterator type
|
: a compatible iterator type
|
||||||
|
|
||||||
|
`SentinelType`
|
||||||
|
: defaults to `IteratorType`; may be a different type comparable to `IteratorType` via `operator!=`, for instance.
|
||||||
|
|
||||||
|
- a custom sentinel type for C++20 ranges
|
||||||
|
- `std::default_sentinel_t`, when `IteratorType` is `std::counted_iterator`
|
||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
`i` (in)
|
`i` (in)
|
||||||
@@ -43,7 +50,7 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
|||||||
: iterator to the start of the input
|
: iterator to the start of the input
|
||||||
|
|
||||||
`last` (in)
|
`last` (in)
|
||||||
: iterator to the end of the input
|
: iterator to the end of the input, or a sentinel value that compares equal to the end iterator with `operator!=`
|
||||||
|
|
||||||
`strict` (in)
|
`strict` (in)
|
||||||
: whether to expect the input to be consumed until EOF (`#!cpp true` by default)
|
: whether to expect the input to be consumed until EOF (`#!cpp true` by default)
|
||||||
@@ -65,8 +72,10 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
|
|||||||
- Throws [parse_error.110](../../home/exceptions.md#jsonexceptionparse_error110) if the given input ends prematurely or
|
- Throws [parse_error.110](../../home/exceptions.md#jsonexceptionparse_error110) if the given input ends prematurely or
|
||||||
the end of the file was not reached when `strict` was set to true
|
the end of the file was not reached when `strict` was set to true
|
||||||
- Throws [parse_error.112](../../home/exceptions.md#jsonexceptionparse_error112) if a parse error occurs
|
- Throws [parse_error.112](../../home/exceptions.md#jsonexceptionparse_error112) if a parse error occurs
|
||||||
- Throws [parse_error.113](../../home/exceptions.md#jsonexceptionparse_error113) if a string could not be parsed
|
- Throws [parse_error.113](../../home/exceptions.md#jsonexceptionparse_error113) if a string could not be parsed
|
||||||
successfully
|
successfully
|
||||||
|
- Throws [out_of_range.408](../../home/exceptions.md#jsonexceptionout_of_range408) if the size of an optimized container
|
||||||
|
or n-dimensional array cannot be represented by `std::size_t`
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
@@ -88,10 +97,20 @@ Linear in the size of the input.
|
|||||||
--8<-- "examples/from_ubjson.output"
|
--8<-- "examples/from_ubjson.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [to_ubjson](to_ubjson.md) create a UBJSON serialization of a JSON value
|
||||||
|
- [from_cbor](from_cbor.md) create a JSON value from an input in CBOR format
|
||||||
|
- [from_msgpack](from_msgpack.md) create a JSON value from an input in MessagePack format
|
||||||
|
- [from_bson](from_bson.md) create a JSON value from an input in BSON format
|
||||||
|
- [from_bjdata](from_bjdata.md) create a JSON value from an input in BJData format
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 3.1.0.
|
- Added in version 3.1.0.
|
||||||
- Added `allow_exceptions` parameter in version 3.2.0.
|
- Added `allow_exceptions` parameter in version 3.2.0.
|
||||||
|
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
|
||||||
|
- Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0.
|
||||||
|
|
||||||
!!! warning "Deprecation"
|
!!! warning "Deprecation"
|
||||||
|
|
||||||
|
|||||||
@@ -88,12 +88,39 @@ constexpr const PointerType get_ptr() const noexcept;
|
|||||||
|
|
||||||
Depends on what `json_serializer<ValueType>` `from_json()` method throws
|
Depends on what `json_serializer<ValueType>` `from_json()` method throws
|
||||||
|
|
||||||
|
## Complexity
|
||||||
|
|
||||||
|
Depends on the `json_serializer<ValueType>::from_json()` implementation for overloads (1) and (2); constant for
|
||||||
|
overload (3).
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
!!! danger "Undefined behavior"
|
!!! danger "Undefined behavior for pointers"
|
||||||
|
|
||||||
Writing data to the pointee (overload 3) of the result yields an undefined state.
|
Writing data to the pointee (overload 3) of the result yields an undefined state.
|
||||||
|
|
||||||
|
!!! danger "Undefined behavior for numeric conversions"
|
||||||
|
|
||||||
|
Conversions between numeric types are performed by the corresponding
|
||||||
|
`from_json()` implementation using the target C++ type. When converting
|
||||||
|
between numeric types, the library does not check whether the source
|
||||||
|
value is representable by the target type.
|
||||||
|
|
||||||
|
If the source value is outside the range of the target type, the behavior
|
||||||
|
is the same as the corresponding C++ conversion. In particular, converting
|
||||||
|
a floating-point value to an integer type that cannot represent the value
|
||||||
|
results in undefined behavior.
|
||||||
|
|
||||||
|
See [Number conversion](../../features/types/number_handling.md#number-conversion)
|
||||||
|
for more information.
|
||||||
|
|
||||||
|
!!! note "`std::optional` conversions"
|
||||||
|
|
||||||
|
Prior to version 3.13.0, `#!cpp get<std::optional<T>>()` (and other conversions to `std::optional<T>`) failed to
|
||||||
|
compile in every configuration, due to an internal implementation bug that made the `from_json` overload for
|
||||||
|
`std::optional` unreachable regardless of the [`JSON_USE_IMPLICIT_CONVERSIONS`](../macros/json_use_implicit_conversions.md)
|
||||||
|
setting. This has been fixed.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
??? example
|
??? example
|
||||||
@@ -129,6 +156,14 @@ Depends on what `json_serializer<ValueType>` `from_json()` method throws
|
|||||||
--8<-- "examples/get__PointerType.output"
|
--8<-- "examples/get__PointerType.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [get_to](get_to.md) convert and write into a passed value
|
||||||
|
- [get_ptr](get_ptr.md) get a pointer to the stored value
|
||||||
|
- [get_ref](get_ref.md) get a reference to the stored value
|
||||||
|
- [operator ValueType](operator_ValueType.md) get a value via implicit conversion
|
||||||
|
- [Converting values](../../features/conversions.md) - the type conversions article
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
1. Since version 2.1.0.
|
1. Since version 2.1.0.
|
||||||
|
|||||||
@@ -40,6 +40,11 @@ Constant.
|
|||||||
--8<-- "examples/get_binary.output"
|
--8<-- "examples/get_binary.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [get](get.md) get a value (explicit conversion)
|
||||||
|
- [get_ref](get_ref.md) get a reference to the stored value
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 3.8.0.
|
- Added in version 3.8.0.
|
||||||
@@ -34,6 +34,10 @@ the input parameter, allowing chaining calls
|
|||||||
|
|
||||||
Depends on what `json_serializer<ValueType>` `from_json()` method throws
|
Depends on what `json_serializer<ValueType>` `from_json()` method throws
|
||||||
|
|
||||||
|
## Complexity
|
||||||
|
|
||||||
|
Depends on the `json_serializer<ValueType>::from_json()` implementation.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
??? example
|
??? example
|
||||||
@@ -53,6 +57,13 @@ Depends on what `json_serializer<ValueType>` `from_json()` method throws
|
|||||||
--8<-- "examples/get_to.output"
|
--8<-- "examples/get_to.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [get](get.md) get a value (explicit conversion)
|
||||||
|
- [get_ref](get_ref.md) get a reference to the stored value
|
||||||
|
- [get_ptr](get_ptr.md) get a pointer to the stored value
|
||||||
|
- [Converting values](../../features/conversions.md) - the type conversions article
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Since version 3.3.0.
|
- Since version 3.3.0.
|
||||||
@@ -301,6 +301,7 @@ Access to the JSON value
|
|||||||
- [**operator<<(std::ostream&)**](../operator_ltlt.md) - serialize to stream
|
- [**operator<<(std::ostream&)**](../operator_ltlt.md) - serialize to stream
|
||||||
- [**operator>>(std::istream&)**](../operator_gtgt.md) - deserialize from stream
|
- [**operator>>(std::istream&)**](../operator_gtgt.md) - deserialize from stream
|
||||||
- [**to_string**](to_string.md) - user-defined `to_string` function for JSON values
|
- [**to_string**](to_string.md) - user-defined `to_string` function for JSON values
|
||||||
|
- [**format_as**](format_as.md) - user-defined `format_as` function for JSON values (fmt support)
|
||||||
|
|
||||||
## Literals
|
## Literals
|
||||||
|
|
||||||
@@ -308,6 +309,7 @@ Access to the JSON value
|
|||||||
|
|
||||||
## Helper classes
|
## Helper classes
|
||||||
|
|
||||||
|
- [**std::formatter<basic_json>**](std_formatter.md) - make JSON values formattable with `std::format`
|
||||||
- [**std::hash<basic_json>**](std_hash.md) - return a hash value for a JSON object
|
- [**std::hash<basic_json>**](std_hash.md) - return a hash value for a JSON object
|
||||||
- [**std::swap<basic_json>**](std_swap.md) - exchanges the values of two JSON objects
|
- [**std::swap<basic_json>**](std_swap.md) - exchanges the values of two JSON objects
|
||||||
|
|
||||||
|
|||||||
@@ -96,8 +96,8 @@ Strong exception safety: if an exception occurs, the original value stays intact
|
|||||||
5. The function can throw the following exceptions:
|
5. The function can throw the following exceptions:
|
||||||
- Throws [`type_error.309`](../../home/exceptions.md#jsonexceptiontype_error309) if called on JSON values other than
|
- Throws [`type_error.309`](../../home/exceptions.md#jsonexceptiontype_error309) if called on JSON values other than
|
||||||
objects; example: `"cannot use insert() with string"`
|
objects; example: `"cannot use insert() with string"`
|
||||||
- Throws [`invalid_iterator.202`](../../home/exceptions.md#jsonexceptioninvalid_iterator202) if called on an
|
- Throws [`invalid_iterator.202`](../../home/exceptions.md#jsonexceptioninvalid_iterator202) if `first` or `last`
|
||||||
iterator which does not belong to the current JSON value; example: `"iterator does not fit current value"`
|
do not point to an object; example: `"iterators first and last must point to objects"`
|
||||||
- Throws [`invalid_iterator.210`](../../home/exceptions.md#jsonexceptioninvalid_iterator210) if `first` and `last`
|
- Throws [`invalid_iterator.210`](../../home/exceptions.md#jsonexceptioninvalid_iterator210) if `first` and `last`
|
||||||
do not belong to the same JSON value; example: `"iterators do not fit"`
|
do not belong to the same JSON value; example: `"iterators do not fit"`
|
||||||
|
|
||||||
@@ -181,6 +181,13 @@ Strong exception safety: if an exception occurs, the original value stays intact
|
|||||||
--8<-- "examples/insert__range_object.output"
|
--8<-- "examples/insert__range_object.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [emplace](emplace.md) add a value to an object
|
||||||
|
- [emplace_back](emplace_back.md) add a value to an array
|
||||||
|
- [push_back](push_back.md) add a value to an array/object
|
||||||
|
- [update](update.md) merges objects
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
1. Added in version 1.0.0.
|
1. Added in version 1.0.0.
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ classDiagram
|
|||||||
|
|
||||||
## See also
|
## See also
|
||||||
|
|
||||||
|
- [`exception`](exception.md) for the base class of all exceptions thrown by the library
|
||||||
- [List of iterator errors](../../home/exceptions.md#iterator-errors)
|
- [List of iterator errors](../../home/exceptions.md#iterator-errors)
|
||||||
- [`parse_error`](parse_error.md) for exceptions indicating a parse error
|
- [`parse_error`](parse_error.md) for exceptions indicating a parse error
|
||||||
- [`type_error`](type_error.md) for exceptions indicating executing a member function with a wrong type
|
- [`type_error`](type_error.md) for exceptions indicating executing a member function with a wrong type
|
||||||
|
|||||||
@@ -45,11 +45,13 @@ Constant.
|
|||||||
|
|
||||||
When a value is discarded by a callback function (see [`parser_callback_t`](parser_callback_t.md)) during parsing,
|
When a value is discarded by a callback function (see [`parser_callback_t`](parser_callback_t.md)) during parsing,
|
||||||
then it is removed when it is part of a structured value. For instance, if the second value of an array is discarded,
|
then it is removed when it is part of a structured value. For instance, if the second value of an array is discarded,
|
||||||
instead of `#!json [null, discarded, false]`, the array `#!json [null, false]` is returned. Only if the top-level
|
instead of `#!json [null, discarded, false]`, the array `#!json [null, false]` is returned. If the top-level value
|
||||||
value is discarded, the return value of the `parse` call is discarded.
|
itself is discarded by the callback, the `parse` call returns a `#!json null` value.
|
||||||
|
|
||||||
This function will always be `#!cpp false` for JSON values after parsing. That is, discarded values can only occur
|
After a successful parse, this function always returns `#!cpp false`: discarded values can only occur during parsing and
|
||||||
during parsing, but will be removed when inside a structured value or replaced by null in other cases.
|
are either removed when inside a structured value or replaced by `#!json null` at the top level. The exception is parsing
|
||||||
|
with `allow_exceptions` set to `#!cpp false`: a parse error then yields a discarded value for which this function returns
|
||||||
|
`#!cpp true` (see [`parse`](parse.md)).
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ unsigned) and floating-point values.
|
|||||||
|
|
||||||
## Return value
|
## Return value
|
||||||
|
|
||||||
`#!cpp true` if type is number (regardless whether integer, unsigned integer, or floating-type), `#!cpp false` otherwise.
|
`#!cpp true` if type is number (regardless whether integer, unsigned integer, or floating-point), `#!cpp false` otherwise.
|
||||||
|
|
||||||
## Exception safety
|
## Exception safety
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,17 @@ for (auto& [key, val] : j_object.items())
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you need to name the type of the dereferenced element explicitly (e.g., to write a standalone function that
|
||||||
|
takes it as a parameter, or to use `items()` with `std::for_each`), use `decltype`:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
using element_type = decltype(*j_object.items().begin());
|
||||||
|
```
|
||||||
|
|
||||||
|
The per-element type (`iteration_proxy_value`) lives in the library's internal `detail` namespace and is
|
||||||
|
intentionally unspecified as a stable, named type -- `decltype` is the supported way to obtain it, but its exact
|
||||||
|
name/definition may change between versions.
|
||||||
|
|
||||||
## Return value
|
## Return value
|
||||||
|
|
||||||
iteration proxy object wrapping the current value with an interface to use in range-based for loops
|
iteration proxy object wrapping the current value with an interface to use in range-based for loops
|
||||||
@@ -84,6 +95,11 @@ When iterating over an array, `key()` will return the index of the element as st
|
|||||||
--8<-- "examples/items.output"
|
--8<-- "examples/items.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [begin](begin.md) returns an iterator to the first element
|
||||||
|
- [end](end.md) returns an iterator to one past the last element
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added `iterator_wrapper` in version 3.0.0.
|
- Added `iterator_wrapper` in version 3.0.0.
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ JSON object holding version information
|
|||||||
|
|
||||||
| key | description |
|
| key | description |
|
||||||
|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| `compiler` | Information on the used compiler. It is an object with the following keys: `c++` (the used C++ standard), `family` (the compiler family; possible values are `clang`, `icc`, `gcc`, `ilecpp`, `msvc`, `pgcpp`, `sunpro`, and `unknown`), and `version` (the compiler version). |
|
| `compiler` | Information on the used compiler. It is an object with the following keys: `c++` (the used C++ standard), `family` (the compiler family; possible values are `clang`, `icc`, `gcc`, `ilecpp`, `msvc`, `pgcpp`, `sunpro`, and `unknown`), and `version` (the compiler version). On HP aCC compilers, `compiler` is instead the plain string `hp`. |
|
||||||
| `copyright` | The copyright line for the library as string. |
|
| `copyright` | The copyright line for the library as string. |
|
||||||
| `name` | The name of the library as string. |
|
| `name` | The name of the library as string. |
|
||||||
| `platform` | The used platform as string. Possible values are `win32`, `linux`, `apple`, `unix`, and `unknown`. |
|
| `platform` | The used platform as string. Possible values are `win32`, `linux`, `apple`, `unix`, and `unknown`. |
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ With the default values for `NumberIntegerType` (`std::int64_t`), the default va
|
|||||||
- The restrictions about leading zeros are not enforced in C++. Instead, leading zeros in integer literals lead to an
|
- The restrictions about leading zeros are not enforced in C++. Instead, leading zeros in integer literals lead to an
|
||||||
interpretation as an octal number. Internally, the value will be stored as a decimal number. For instance, the C++
|
interpretation as an octal number. Internally, the value will be stored as a decimal number. For instance, the C++
|
||||||
integer literal `010` will be serialized to `8`. During deserialization, leading zeros yield an error.
|
integer literal `010` will be serialized to `8`. During deserialization, leading zeros yield an error.
|
||||||
- Not-a-number (NaN) values will be serialized to `null`.
|
|
||||||
|
|
||||||
#### Limits
|
#### Limits
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ With the default values for `NumberUnsignedType` (`std::uint64_t`), the default
|
|||||||
- The restrictions about leading zeros are not enforced in C++. Instead, leading zeros in integer literals lead to an
|
- The restrictions about leading zeros are not enforced in C++. Instead, leading zeros in integer literals lead to an
|
||||||
interpretation as an octal number. Internally, the value will be stored as a decimal number. For instance, the C++
|
interpretation as an octal number. Internally, the value will be stored as a decimal number. For instance, the C++
|
||||||
integer literal `010` will be serialized to `8`. During deserialization, leading zeros yield an error.
|
integer literal `010` will be serialized to `8`. During deserialization, leading zeros yield an error.
|
||||||
- Not-a-number (NaN) values will be serialized to `null`.
|
|
||||||
|
|
||||||
#### Limits
|
#### Limits
|
||||||
|
|
||||||
@@ -45,7 +44,7 @@ when used in a constructor. During deserialization, too large or small integer n
|
|||||||
as [`number_integer_t`](number_integer_t.md) or [`number_float_t`](number_float_t.md).
|
as [`number_integer_t`](number_integer_t.md) or [`number_float_t`](number_float_t.md).
|
||||||
|
|
||||||
[RFC 8259](https://tools.ietf.org/html/rfc8259) further states:
|
[RFC 8259](https://tools.ietf.org/html/rfc8259) further states:
|
||||||
> Note that when such software is used, numbers that are integers and are in the range \f$[-2^{53}+1, 2^{53}-1]\f$ are
|
> Note that when such software is used, numbers that are integers and are in the range $[-2^{53}+1, 2^{53}-1]$ are
|
||||||
> interoperable in the sense that implementations will agree exactly on their numeric values.
|
> interoperable in the sense that implementations will agree exactly on their numeric values.
|
||||||
|
|
||||||
As this range is a subrange (when considered in conjunction with the `number_integer_t` type) of the exactly supported
|
As this range is a subrange (when considered in conjunction with the `number_integer_t` type) of the exactly supported
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ the initializer list constructor `basic_json(initializer_list_t, bool, value_t)`
|
|||||||
|
|
||||||
- [`basic_json(initializer_list_t)`](basic_json.md) - create a JSON value from an initializer list
|
- [`basic_json(initializer_list_t)`](basic_json.md) - create a JSON value from an initializer list
|
||||||
- [`array`](array.md) - create a JSON array value from an initializer list
|
- [`array`](array.md) - create a JSON array value from an initializer list
|
||||||
|
- [Creating JSON values](../../features/creating_values.md) - the article on creating JSON values
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,8 @@ behavior:
|
|||||||
object will agree on the name-value mappings.
|
object will agree on the name-value mappings.
|
||||||
- When the names within an object are not unique, it is unspecified which one of the values for a given key will be
|
- When the names within an object are not unique, it is unspecified which one of the values for a given key will be
|
||||||
chosen. For instance, `#!json {"key": 2, "key": 1}` could be equal to either `#!json {"key": 1}` or
|
chosen. For instance, `#!json {"key": 2, "key": 1}` could be equal to either `#!json {"key": 1}` or
|
||||||
`#!json {"key": 2}`.
|
`#!json {"key": 2}`. To reject duplicate keys instead of silently resolving them one way or another, see
|
||||||
|
[this parsing recipe](../../features/parsing/parser_callbacks.md#recipe-rejecting-duplicate-object-keys).
|
||||||
- Internally, name/value pairs are stored in lexicographical order of the names. Objects will also be serialized (see
|
- Internally, name/value pairs are stored in lexicographical order of the names. Objects will also be serialized (see
|
||||||
[`dump`](dump.md)) in this order. For instance, `#!json {"b": 1, "a": 2}` and `#!json {"a": 2, "b": 1}` will be stored
|
[`dump`](dump.md)) in this order. For instance, `#!json {"b": 1, "a": 2}` and `#!json {"a": 2, "b": 1}` will be stored
|
||||||
and serialized as `#!json {"a": 2, "b": 1}`.
|
and serialized as `#!json {"a": 2, "b": 1}`.
|
||||||
@@ -93,6 +94,15 @@ alphabetical order as `std::map` with `std::less` is used by default. Please not
|
|||||||
[RFC 8259](https://tools.ietf.org/html/rfc8259), because any order implements the specified "unordered" nature of JSON
|
[RFC 8259](https://tools.ietf.org/html/rfc8259), because any order implements the specified "unordered" nature of JSON
|
||||||
objects.
|
objects.
|
||||||
|
|
||||||
|
#### Cross-`basic_json` conversion requirements
|
||||||
|
|
||||||
|
When converting an object from one `basic_json` specialization to another via the
|
||||||
|
[converting constructor](basic_json.md#overload-4), the target `object_t`'s `key_type` must be
|
||||||
|
directly constructible from the source `basic_json`'s `string_t` type (or more generally, from the
|
||||||
|
source object's key type). If this requirement is not met, the conversion does not fail; instead,
|
||||||
|
the object is silently converted as an array of key-value pairs, which is incorrect. See
|
||||||
|
[issue #3425](https://github.com/nlohmann/json/issues/3425) for details and an example.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
??? example
|
??? example
|
||||||
|
|||||||
@@ -50,9 +50,12 @@ invalidates all iterators and all references.
|
|||||||
|
|
||||||
## Exceptions
|
## Exceptions
|
||||||
|
|
||||||
All functions can throw the following exception:
|
1. Throws [`type_error.308`](../../home/exceptions.md#jsonexceptiontype_error308) when called on a type other than
|
||||||
- Throws [`type_error.308`](../../home/exceptions.md#jsonexceptiontype_error308) when called on a type other than
|
JSON array or null; example: `"cannot use push_back() with number"`
|
||||||
JSON array or null; example: `"cannot use operator+=() with number"`
|
2. Throws [`type_error.308`](../../home/exceptions.md#jsonexceptiontype_error308) when called on a type other than
|
||||||
|
JSON object or null; example: `"cannot use push_back() with number"`
|
||||||
|
3. Throws [`type_error.308`](../../home/exceptions.md#jsonexceptiontype_error308) when called on a type other than
|
||||||
|
JSON array or null; example: `"cannot use push_back() with number"`
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ basic_json& operator=(basic_json other) noexcept (
|
|||||||
std::is_nothrow_move_constructible<value_t>::value &&
|
std::is_nothrow_move_constructible<value_t>::value &&
|
||||||
std::is_nothrow_move_assignable<value_t>::value &&
|
std::is_nothrow_move_assignable<value_t>::value &&
|
||||||
std::is_nothrow_move_constructible<json_value>::value &&
|
std::is_nothrow_move_constructible<json_value>::value &&
|
||||||
std::is_nothrow_move_assignable<json_value>::value
|
std::is_nothrow_move_assignable<json_value>::value &&
|
||||||
|
std::is_nothrow_move_assignable<json_base_class_t>::value
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -17,6 +18,10 @@ constructor, destructor, and the `swap()` member function.
|
|||||||
`other` (in)
|
`other` (in)
|
||||||
: value to copy from
|
: value to copy from
|
||||||
|
|
||||||
|
## Exception safety
|
||||||
|
|
||||||
|
Strong guarantee: if an exception is thrown while copying `other`, there are no changes to `#!cpp *this`.
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
Linear.
|
Linear.
|
||||||
@@ -38,6 +43,11 @@ Linear.
|
|||||||
--8<-- "examples/basic_json__copyassignment.output"
|
--8<-- "examples/basic_json__copyassignment.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [basic_json](basic_json.md) create a JSON value
|
||||||
|
- [swap](swap.md) exchanges the contents of two JSON values
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 1.0.0.
|
- Added in version 1.0.0.
|
||||||
@@ -83,6 +83,8 @@ Strong exception safety: if an exception occurs, the original value stays intact
|
|||||||
in the passed JSON pointer `ptr` for the const version.
|
in the passed JSON pointer `ptr` for the const version.
|
||||||
- Throws [`out_of_range.404`](../../home/exceptions.md#jsonexceptionout_of_range404) if the JSON pointer `ptr` can
|
- Throws [`out_of_range.404`](../../home/exceptions.md#jsonexceptionout_of_range404) if the JSON pointer `ptr` can
|
||||||
not be resolved.
|
not be resolved.
|
||||||
|
- Throws [`out_of_range.410`](../../home/exceptions.md#jsonexceptionout_of_range410) if an array index in the passed
|
||||||
|
JSON pointer `ptr` exceeds the range of `size_type` (e.g., on 32-bit platforms).
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
@@ -95,7 +97,10 @@ Strong exception safety: if an exception occurs, the original value stays intact
|
|||||||
|
|
||||||
!!! danger "Undefined behavior and runtime assertions"
|
!!! danger "Undefined behavior and runtime assertions"
|
||||||
|
|
||||||
1. If the element with key `idx` does not exist, the behavior is undefined.
|
The following cases apply to the **const** overloads; the non-const overloads instead insert the missing element
|
||||||
|
(see the notes below).
|
||||||
|
|
||||||
|
1. If the element at index `idx` does not exist, the behavior is undefined.
|
||||||
2. If the element with key `key` does not exist, the behavior is undefined and is **guarded by a
|
2. If the element with key `key` does not exist, the behavior is undefined and is **guarded by a
|
||||||
[runtime assertion](../../features/assertions.md)**!
|
[runtime assertion](../../features/assertions.md)**!
|
||||||
|
|
||||||
@@ -119,6 +124,15 @@ Strong exception safety: if an exception occurs, the original value stays intact
|
|||||||
filled with `#!json null`.
|
filled with `#!json null`.
|
||||||
- The special value `-` is treated as a synonym for the index past the end.
|
- The special value `-` is treated as a synonym for the index past the end.
|
||||||
|
|
||||||
|
!!! note "Creating intermediate levels that don't exist yet"
|
||||||
|
|
||||||
|
When the JSON pointer traverses intermediate levels that don't exist at all yet (not just a missing
|
||||||
|
leaf), each missing level is created as an array or an object depending on whether the corresponding
|
||||||
|
pointer token parses as a non-negative integer: a numeric token creates an array, a non-numeric token
|
||||||
|
creates an object. For example, on an initially `#!json null` value, `/foo/0/0/0` creates nested arrays,
|
||||||
|
while `/foo/one/one/one` creates nested objects. This is not specified by the JSON Pointer RFC; it is
|
||||||
|
this library's own, intentional disambiguation rule. See also [JSON Pointer](../../features/json_pointer.md).
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
??? example "Example: (1) access specified array element"
|
??? example "Example: (1) access specified array element"
|
||||||
@@ -246,5 +260,6 @@ Strong exception safety: if an exception occurs, the original value stays intact
|
|||||||
1. Added in version 1.0.0.
|
1. Added in version 1.0.0.
|
||||||
2. Added in version 1.0.0. Added overloads for `T* key` in version 1.1.0. Removed overloads for `T* key` (replaced by 3)
|
2. Added in version 1.0.0. Added overloads for `T* key` in version 1.1.0. Removed overloads for `T* key` (replaced by 3)
|
||||||
in version 3.11.0.
|
in version 3.11.0.
|
||||||
3. Added in version 3.11.0.
|
3. Added in version 3.11.0. Fixed in version 3.13.0 to consistently accept `std::string_view`-convertible keys, as
|
||||||
|
already supported by [`at`](at.md), [`value`](value.md), [`find`](find.md), and other lookup functions.
|
||||||
4. Added in version 2.0.0.
|
4. Added in version 2.0.0.
|
||||||
@@ -75,6 +75,11 @@ Linear in the size of the JSON value.
|
|||||||
--8<-- "examples/operator__ValueType.output"
|
--8<-- "examples/operator__ValueType.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [get](get.md) get a value (explicit conversion)
|
||||||
|
- [Converting values](../../features/conversions.md) - the type conversions article
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Since version 1.0.0.
|
- Since version 1.0.0.
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class basic_json {
|
|||||||
```
|
```
|
||||||
|
|
||||||
1. Compares two JSON values for equality according to the following rules:
|
1. Compares two JSON values for equality according to the following rules:
|
||||||
- Two JSON values are equal if (1) neither value is discarded, or (2) they are of the same type and their stored
|
- Two JSON values are equal if (1) neither value is discarded, and (2) they are of the same type and their stored
|
||||||
values are the same according to their respective `operator==`.
|
values are the same according to their respective `operator==`.
|
||||||
- Integer and floating-point numbers are automatically converted before comparison.
|
- Integer and floating-point numbers are automatically converted before comparison.
|
||||||
|
|
||||||
@@ -79,13 +79,13 @@ Linear.
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Or you can self-defined operator equal function like this:
|
Or you can define your own equality function like this:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
bool my_equal(const_reference lhs, const_reference rhs)
|
bool my_equal(const_reference lhs, const_reference rhs)
|
||||||
{
|
{
|
||||||
const auto lhs_type lhs.type();
|
const auto lhs_type = lhs.type();
|
||||||
const auto rhs_type rhs.type();
|
const auto rhs_type = rhs.type();
|
||||||
if (lhs_type == rhs_type)
|
if (lhs_type == rhs_type)
|
||||||
{
|
{
|
||||||
switch(lhs_type)
|
switch(lhs_type)
|
||||||
@@ -162,6 +162,11 @@ Linear.
|
|||||||
--8<-- "examples/operator__equal__nullptr_t.output"
|
--8<-- "examples/operator__equal__nullptr_t.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [operator!=](operator_ne.md) compare for inequality
|
||||||
|
- [operator<=>](operator_spaceship.md) comparison: 3-way (C++20)
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
1. Added in version 1.0.0. Added C++20 member functions in version 3.11.0.
|
1. Added in version 1.0.0. Added C++20 member functions in version 3.11.0.
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ bool operator>=(ScalarType lhs, const const_reference rhs) noexcept; // (2)
|
|||||||
|
|
||||||
## Return value
|
## Return value
|
||||||
|
|
||||||
whether `lhs` is less than or equal to `rhs`
|
whether `lhs` is greater than or equal to `rhs`
|
||||||
|
|
||||||
## Exception safety
|
## Exception safety
|
||||||
|
|
||||||
|
|||||||
@@ -19,10 +19,8 @@ class basic_json {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Compares two JSON values for inequality according to the following rules:
|
1. Compares two JSON values for inequality. Returns `#!cpp !(lhs == rhs)` (until C++20) or `#!cpp !(*this == rhs)` (since C++20).
|
||||||
- The comparison always yields `#!cpp false` if (1) either operand is discarded, or (2) either operand is `NaN` and
|
- This means the comparison is simply the logical negation of `operator==`, including for special values like `NaN` and `discarded`.
|
||||||
the other operand is either `NaN` or any other number.
|
|
||||||
- Otherwise, returns the result of `#!cpp !(lhs == rhs)` (until C++20) or `#!cpp !(*this == rhs)` (since C++20).
|
|
||||||
|
|
||||||
2. Compares a JSON value and a scalar or a scalar and a JSON value for inequality by converting the scalar to a JSON
|
2. Compares a JSON value and a scalar or a scalar and a JSON value for inequality by converting the scalar to a JSON
|
||||||
value and comparing both JSON values according to 1.
|
value and comparing both JSON values according to 1.
|
||||||
@@ -54,13 +52,12 @@ Linear.
|
|||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
!!! note "Comparing `NaN`"
|
!!! note "Comparing `NaN` and `discarded`"
|
||||||
|
|
||||||
`NaN` values are unordered within the domain of numbers.
|
Since `operator!=` is defined as `!(a == b)`, the behavior for special values follows that of `operator==`:
|
||||||
The following comparisons all yield `#!cpp false`:
|
|
||||||
1. Comparing a `NaN` with itself.
|
- For `NaN` values: `NaN == NaN` yields `#!cpp false`, so `NaN != NaN` yields `#!cpp true`.
|
||||||
2. Comparing a `NaN` with another `NaN`.
|
- For `discarded` values: `discarded == x` yields `#!cpp false` for any `x`, so `discarded != x` yields `#!cpp true`.
|
||||||
3. Comparing a `NaN` and any other number.
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
@@ -94,5 +91,7 @@ Linear.
|
|||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
1. Added in version 1.0.0. Added C++20 member functions in version 3.11.0.
|
1. Added in version 1.0.0. Added C++20 member functions in version 3.11.0. Changed in version 3.13.0 to remove
|
||||||
2. Added in version 1.0.0. Added C++20 member functions in version 3.11.0.
|
special-casing for `NaN` and `discarded` values; `operator!=` now consistently means `!(a == b)`.
|
||||||
|
2. Added in version 1.0.0. Added C++20 member functions in version 3.11.0. Changed in version 3.13.0 to remove
|
||||||
|
special-casing for `NaN` and `discarded` values; `operator!=` now consistently means `!(a == b)`.
|
||||||
@@ -66,6 +66,7 @@ classDiagram
|
|||||||
|
|
||||||
## See also
|
## See also
|
||||||
|
|
||||||
|
- [`exception`](exception.md) for the base class of all exceptions thrown by the library
|
||||||
- [List of other errors](../../home/exceptions.md#further-exceptions)
|
- [List of other errors](../../home/exceptions.md#further-exceptions)
|
||||||
- [`parse_error`](parse_error.md) for exceptions indicating a parse error
|
- [`parse_error`](parse_error.md) for exceptions indicating a parse error
|
||||||
- [`invalid_iterator`](invalid_iterator.md) for exceptions indicating errors with iterators
|
- [`invalid_iterator`](invalid_iterator.md) for exceptions indicating errors with iterators
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ classDiagram
|
|||||||
|
|
||||||
## See also
|
## See also
|
||||||
|
|
||||||
|
- [`exception`](exception.md) for the base class of all exceptions thrown by the library
|
||||||
- [List of out-of-range errors](../../home/exceptions.md#out-of-range)
|
- [List of out-of-range errors](../../home/exceptions.md#out-of-range)
|
||||||
- [`parse_error`](parse_error.md) for exceptions indicating a parse error
|
- [`parse_error`](parse_error.md) for exceptions indicating a parse error
|
||||||
- [`invalid_iterator`](invalid_iterator.md) for exceptions indicating errors with iterators
|
- [`invalid_iterator`](invalid_iterator.md) for exceptions indicating errors with iterators
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ static basic_json parse(InputType&& i,
|
|||||||
const bool ignore_trailing_commas = false);
|
const bool ignore_trailing_commas = false);
|
||||||
|
|
||||||
// (2)
|
// (2)
|
||||||
template<typename IteratorType>
|
template<typename IteratorType, typename SentinelType = IteratorType>
|
||||||
static basic_json parse(IteratorType first, IteratorType last,
|
static basic_json parse(IteratorType first, SentinelType last,
|
||||||
const parser_callback_t cb = nullptr,
|
const parser_callback_t cb = nullptr,
|
||||||
const bool allow_exceptions = true,
|
const bool allow_exceptions = true,
|
||||||
const bool ignore_comments = false,
|
const bool ignore_comments = false,
|
||||||
@@ -19,10 +19,11 @@ static basic_json parse(IteratorType first, IteratorType last,
|
|||||||
```
|
```
|
||||||
|
|
||||||
1. Deserialize from a compatible input.
|
1. Deserialize from a compatible input.
|
||||||
2. Deserialize from a pair of character iterators
|
2. Deserialize from a pair of character iterators, or an iterator and a sentinel of a different type (C++20 ranges support)
|
||||||
|
|
||||||
The `value_type` of the iterator must be an integral type with size of 1, 2, or 4 bytes, which will be interpreted
|
The `value_type` of the iterator must be an integral type with size of 1, 2, or 4 bytes, which will be interpreted
|
||||||
respectively as UTF-8, UTF-16, and UTF-32.
|
respectively as UTF-8, UTF-16, and UTF-32. If `SentinelType` differs from `IteratorType`, it must be comparable to
|
||||||
|
the iterator type with `operator!=`.
|
||||||
|
|
||||||
## Template parameters
|
## Template parameters
|
||||||
|
|
||||||
@@ -34,7 +35,8 @@ static basic_json parse(IteratorType first, IteratorType last,
|
|||||||
- a C-style array of characters
|
- a C-style array of characters
|
||||||
- a pointer to a null-terminated string of single byte characters (throws if null)
|
- a pointer to a null-terminated string of single byte characters (throws if null)
|
||||||
- a `std::string`
|
- a `std::string`
|
||||||
- an object `obj` for which `begin(obj)` and `end(obj)` produces a valid pair of iterators.
|
- a container `obj` for which `begin(obj)` and `end(obj)` produce a valid pair of iterators
|
||||||
|
(as found via ADL or member functions, with semantics compatible to `std::begin` and `std::end`)
|
||||||
|
|
||||||
`IteratorType`
|
`IteratorType`
|
||||||
: a compatible iterator type, for instance.
|
: a compatible iterator type, for instance.
|
||||||
@@ -42,6 +44,12 @@ static basic_json parse(IteratorType first, IteratorType last,
|
|||||||
- a pair of `std::string::iterator` or `std::vector<std::uint8_t>::iterator`
|
- a pair of `std::string::iterator` or `std::vector<std::uint8_t>::iterator`
|
||||||
- a pair of pointers such as `ptr` and `ptr + len`
|
- a pair of pointers such as `ptr` and `ptr + len`
|
||||||
|
|
||||||
|
`SentinelType`
|
||||||
|
: defaults to `IteratorType`; may be a different type comparable to `IteratorType` via `operator!=`, for instance.
|
||||||
|
|
||||||
|
- a custom sentinel type for C++20 ranges
|
||||||
|
- `std::default_sentinel_t`, when `IteratorType` is `std::counted_iterator`
|
||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
`i` (in)
|
`i` (in)
|
||||||
@@ -66,7 +74,7 @@ static basic_json parse(IteratorType first, IteratorType last,
|
|||||||
: iterator to the start of a character range
|
: iterator to the start of a character range
|
||||||
|
|
||||||
`last` (in)
|
`last` (in)
|
||||||
: iterator to the end of a character range
|
: iterator to the end of a character range, or a sentinel value that compares equal to the end iterator with `operator!=`
|
||||||
|
|
||||||
## Return value
|
## Return value
|
||||||
|
|
||||||
@@ -81,9 +89,6 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
|
|||||||
|
|
||||||
- Throws [`parse_error.101`](../../home/exceptions.md#jsonexceptionparse_error101) in case of an unexpected token, or
|
- Throws [`parse_error.101`](../../home/exceptions.md#jsonexceptionparse_error101) in case of an unexpected token, or
|
||||||
empty input like a null `FILE*` or `char*` pointer.
|
empty input like a null `FILE*` or `char*` pointer.
|
||||||
- Throws [`parse_error.102`](../../home/exceptions.md#jsonexceptionparse_error102) if `to_unicode` fails or surrogate
|
|
||||||
error.
|
|
||||||
- Throws [`parse_error.103`](../../home/exceptions.md#jsonexceptionparse_error103) if `to_unicode` fails.
|
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
@@ -95,6 +100,9 @@ super-linear complexity.
|
|||||||
|
|
||||||
A UTF-8 byte order mark is silently ignored.
|
A UTF-8 byte order mark is silently ignored.
|
||||||
|
|
||||||
|
Invalid Unicode escapes and unpaired surrogates in the input are reported as
|
||||||
|
[`parse_error.101`](../../home/exceptions.md#jsonexceptionparse_error101) with a detailed message.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
??? example "Parsing from a character array"
|
??? example "Parsing from a character array"
|
||||||
@@ -183,7 +191,7 @@ A UTF-8 byte order mark is silently ignored.
|
|||||||
|
|
||||||
??? example "Effect of `allow_exceptions` parameter"
|
??? example "Effect of `allow_exceptions` parameter"
|
||||||
|
|
||||||
The example below demonstrates the effect of the `allow_exceptions` parameter in the ´parse()` function.
|
The example below demonstrates the effect of the `allow_exceptions` parameter in the `parse()` function.
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
--8<-- "examples/parse__allow_exceptions.cpp"
|
--8<-- "examples/parse__allow_exceptions.cpp"
|
||||||
@@ -226,6 +234,7 @@ A UTF-8 byte order mark is silently ignored.
|
|||||||
## See also
|
## See also
|
||||||
|
|
||||||
- [accept](accept.md) - check if the input is valid JSON
|
- [accept](accept.md) - check if the input is valid JSON
|
||||||
|
- [sax_parse](sax_parse.md) - parse input using the SAX interface
|
||||||
- [operator>>](../operator_gtgt.md) - deserialize from stream
|
- [operator>>](../operator_gtgt.md) - deserialize from stream
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
@@ -234,7 +243,9 @@ A UTF-8 byte order mark is silently ignored.
|
|||||||
- Overload for contiguous containers (1) added in version 2.0.3.
|
- Overload for contiguous containers (1) added in version 2.0.3.
|
||||||
- Ignoring comments via `ignore_comments` added in version 3.9.0.
|
- Ignoring comments via `ignore_comments` added in version 3.9.0.
|
||||||
- Changed [runtime assertion](../../features/assertions.md) in case of `FILE*` null pointers to exception in version 3.12.0.
|
- Changed [runtime assertion](../../features/assertions.md) in case of `FILE*` null pointers to exception in version 3.12.0.
|
||||||
- Added `ignore_trailing_commas` in version 3.12.1.
|
- Added `ignore_trailing_commas` in version 3.13.0.
|
||||||
|
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
|
||||||
|
- Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0.
|
||||||
|
|
||||||
!!! warning "Deprecation"
|
!!! warning "Deprecation"
|
||||||
|
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ or the end of file. This also holds true when reading a byte vector for binary f
|
|||||||
|
|
||||||
## See also
|
## See also
|
||||||
|
|
||||||
|
- [`exception`](exception.md) for the base class of all exceptions thrown by the library
|
||||||
- [List of parse errors](../../home/exceptions.md#parse-errors)
|
- [List of parse errors](../../home/exceptions.md#parse-errors)
|
||||||
- [`invalid_iterator`](invalid_iterator.md) for exceptions indicating errors with iterators
|
- [`invalid_iterator`](invalid_iterator.md) for exceptions indicating errors with iterators
|
||||||
- [`type_error`](type_error.md) for exceptions indicating executing a member function with a wrong type
|
- [`type_error`](type_error.md) for exceptions indicating executing a member function with a wrong type
|
||||||
|
|||||||
@@ -24,6 +24,11 @@ The parser callback distinguishes the following events:
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [parser_callback_t](parser_callback_t.md) callback function type for the parser
|
||||||
|
- [parse](parse.md) deserialize from a compatible input
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 1.0.0.
|
- Added in version 1.0.0.
|
||||||
@@ -29,7 +29,14 @@ Discarding a value (i.e., returning `#!cpp false`) has different effects dependi
|
|||||||
called:
|
called:
|
||||||
|
|
||||||
- Discarded values in structured types are skipped. That is, the parser will behave as if the discarded value was never
|
- Discarded values in structured types are skipped. That is, the parser will behave as if the discarded value was never
|
||||||
read.
|
read. This holds for every value type and for both kinds of parent: a discarded element is removed from the
|
||||||
|
surrounding array, and a discarded member is removed from the surrounding object together with its key.
|
||||||
|
- Arrays and objects can be discarded either at their `parse_event_t::array_start`/`parse_event_t::object_start` event
|
||||||
|
or at their `parse_event_t::array_end`/`parse_event_t::object_end` event, and both remove the whole value. Discarding
|
||||||
|
it at the start event also means the callback is called neither for the content of the value nor for its matching end
|
||||||
|
event.
|
||||||
|
- Discarding a `parse_event_t::key` event discards the whole object member. The callback is still called for the
|
||||||
|
associated value, but its return value has no further effect.
|
||||||
- In case a value outside a structured type is skipped, it is replaced with `null`. This case happens if the top-level
|
- In case a value outside a structured type is skipped, it is replaced with `null`. This case happens if the top-level
|
||||||
element is skipped.
|
element is skipped.
|
||||||
|
|
||||||
@@ -49,7 +56,7 @@ called:
|
|||||||
## Return value
|
## Return value
|
||||||
|
|
||||||
Whether the JSON value which called the function during parsing should be kept (`#!cpp true`) or not (`#!cpp false`). In
|
Whether the JSON value which called the function during parsing should be kept (`#!cpp true`) or not (`#!cpp false`). In
|
||||||
the latter case, it is either skipped completely or replaced by an empty discarded object.
|
the latter case, it is skipped completely, or replaced by `null` if it is the top-level value.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
@@ -68,6 +75,28 @@ the latter case, it is either skipped completely or replaced by an empty discard
|
|||||||
--8<-- "examples/parse__string__parser_callback_t.output"
|
--8<-- "examples/parse__string__parser_callback_t.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example below shows where discarded values are removed. The array and the number are discarded in different
|
||||||
|
ways, but in each case the parse result contains neither the value nor its key.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/parser_callback_t.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```json
|
||||||
|
--8<-- "examples/parser_callback_t.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [parse](parse.md) deserialize from a compatible input
|
||||||
|
- [parse_event_t](parse_event_t.md) enumeration of parser events
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 1.0.0.
|
- Added in version 1.0.0.
|
||||||
|
- Fixed in version 3.13.0 to also remove discarded values from a parent object; before, discarding an array or a value
|
||||||
|
stored under an object key left a discarded member behind, which made the parse result serialize to invalid JSON.
|
||||||
@@ -32,7 +32,9 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
|
|||||||
could not be resolved successfully in the current JSON value; example: `"key baz not found"`.
|
could not be resolved successfully in the current JSON value; example: `"key baz not found"`.
|
||||||
- Throws [`out_of_range.405`](../../home/exceptions.md#jsonexceptionout_of_range405) if JSON pointer has no parent
|
- Throws [`out_of_range.405`](../../home/exceptions.md#jsonexceptionout_of_range405) if JSON pointer has no parent
|
||||||
("add", "remove", "move")
|
("add", "remove", "move")
|
||||||
- Throws [`out_of_range.501`](../../home/exceptions.md#jsonexceptionother_error501) if "test" operation was
|
- Throws [`out_of_range.411`](../../home/exceptions.md#jsonexceptionout_of_range411) if an "add" operation's target
|
||||||
|
location has a parent that is neither an object nor an array.
|
||||||
|
- Throws [`other_error.501`](../../home/exceptions.md#jsonexceptionother_error501) if "test" operation was
|
||||||
unsuccessful.
|
unsuccessful.
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
@@ -71,3 +73,5 @@ is thrown. In any case, the original value is not changed: the patch is applied
|
|||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 2.0.0.
|
- Added in version 2.0.0.
|
||||||
|
- Added [`out_of_range.411`](../../home/exceptions.md#jsonexceptionout_of_range411) and stopped relying on an internal assertion when an "add" operation's
|
||||||
|
target location has a non-object/non-array parent in version 3.13.0.
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
# <small>nlohmann::basic_json::</small>patch_inplace
|
# <small>nlohmann::basic_json::</small>patch_inplace
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
void patch_inplace(const basic_json& json_patch) const;
|
void patch_inplace(const basic_json& json_patch);
|
||||||
```
|
```
|
||||||
|
|
||||||
[JSON Patch](http://jsonpatch.com) defines a JSON document structure for expressing a sequence of operations to apply to
|
[JSON Patch](http://jsonpatch.com) defines a JSON document structure for expressing a sequence of operations to apply to
|
||||||
@@ -28,7 +28,9 @@ No guarantees, value may be corrupted by an unsuccessful patch operation.
|
|||||||
could not be resolved successfully in the current JSON value; example: `"key baz not found"`.
|
could not be resolved successfully in the current JSON value; example: `"key baz not found"`.
|
||||||
- Throws [`out_of_range.405`](../../home/exceptions.md#jsonexceptionout_of_range405) if JSON pointer has no parent
|
- Throws [`out_of_range.405`](../../home/exceptions.md#jsonexceptionout_of_range405) if JSON pointer has no parent
|
||||||
("add", "remove", "move")
|
("add", "remove", "move")
|
||||||
- Throws [`out_of_range.501`](../../home/exceptions.md#jsonexceptionother_error501) if "test" operation was
|
- Throws [`out_of_range.411`](../../home/exceptions.md#jsonexceptionout_of_range411) if an "add" operation's target
|
||||||
|
location has a parent that is neither an object nor an array.
|
||||||
|
- Throws [`other_error.501`](../../home/exceptions.md#jsonexceptionother_error501) if "test" operation was
|
||||||
unsuccessful.
|
unsuccessful.
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
@@ -62,9 +64,11 @@ function throws an exception.
|
|||||||
|
|
||||||
- [RFC 6902 (JSON Patch)](https://tools.ietf.org/html/rfc6902)
|
- [RFC 6902 (JSON Patch)](https://tools.ietf.org/html/rfc6902)
|
||||||
- [RFC 6901 (JSON Pointer)](https://tools.ietf.org/html/rfc6901)
|
- [RFC 6901 (JSON Pointer)](https://tools.ietf.org/html/rfc6901)
|
||||||
- [patch](patch.md) applies a JSON Merge Patch
|
- [patch](patch.md) applies a JSON Patch
|
||||||
- [merge_patch](merge_patch.md) applies a JSON Merge Patch
|
- [merge_patch](merge_patch.md) applies a JSON Merge Patch
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 3.11.0.
|
- Added in version 3.11.0.
|
||||||
|
- Added [`out_of_range.411`](../../home/exceptions.md#jsonexceptionout_of_range411) and stopped relying on an internal assertion when an "add" operation's
|
||||||
|
target location has a non-object/non-array parent in version 3.13.0.
|
||||||
@@ -46,9 +46,12 @@ invalidates all iterators and all references.
|
|||||||
|
|
||||||
## Exceptions
|
## Exceptions
|
||||||
|
|
||||||
All functions can throw the following exception:
|
1. Throws [`type_error.308`](../../home/exceptions.md#jsonexceptiontype_error308) when called on a type other than
|
||||||
- Throws [`type_error.308`](../../home/exceptions.md#jsonexceptiontype_error308) when called on a type other than
|
JSON array or null; example: `"cannot use push_back() with number"`
|
||||||
JSON array or null; example: `"cannot use push_back() with number"`
|
2. Throws [`type_error.308`](../../home/exceptions.md#jsonexceptiontype_error308) when called on a type other than
|
||||||
|
JSON object or null; example: `"cannot use push_back() with number"`
|
||||||
|
3. Throws [`type_error.308`](../../home/exceptions.md#jsonexceptiontype_error308) when called on a type other than
|
||||||
|
JSON array or null; example: `"cannot use push_back() with number"`
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
@@ -112,6 +115,7 @@ All functions can throw the following exception:
|
|||||||
|
|
||||||
- [emplace_back](emplace_back.md) add a value to an array
|
- [emplace_back](emplace_back.md) add a value to an array
|
||||||
- [operator+=](operator+=.md) add a value to an array/object
|
- [operator+=](operator+=.md) add a value to an array/object
|
||||||
|
- [Modifying values](../../features/modifying_values.md) - the article on modifying values
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ Returns an iterator to the reverse-beginning; that is, the last element.
|
|||||||
|
|
||||||
## Return value
|
## Return value
|
||||||
|
|
||||||
reverse iterator to the first element
|
reverse iterator to the last element
|
||||||
|
|
||||||
## Exception safety
|
## Exception safety
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ Constant.
|
|||||||
|
|
||||||
??? example
|
??? example
|
||||||
|
|
||||||
The following code shows an example for `eend()`.
|
The following code shows an example for `rend()`.
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
--8<-- "examples/rend.cpp"
|
--8<-- "examples/rend.cpp"
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ static bool sax_parse(InputType&& i,
|
|||||||
const bool ignore_trailing_commas = false);
|
const bool ignore_trailing_commas = false);
|
||||||
|
|
||||||
// (2)
|
// (2)
|
||||||
template<class IteratorType, class SAX>
|
template<class IteratorType, class SAX, class SentinelType = IteratorType>
|
||||||
static bool sax_parse(IteratorType first, IteratorType last,
|
static bool sax_parse(IteratorType first, SentinelType last,
|
||||||
SAX* sax,
|
SAX* sax,
|
||||||
input_format_t format = input_format_t::json,
|
input_format_t format = input_format_t::json,
|
||||||
const bool strict = true,
|
const bool strict = true,
|
||||||
@@ -23,10 +23,11 @@ static bool sax_parse(IteratorType first, IteratorType last,
|
|||||||
Read from input and generate SAX events
|
Read from input and generate SAX events
|
||||||
|
|
||||||
1. Read from a compatible input.
|
1. Read from a compatible input.
|
||||||
2. Read from a pair of character iterators
|
2. Read from a pair of character iterators, or an iterator and a sentinel of a different type (C++20 ranges support)
|
||||||
|
|
||||||
The value_type of the iterator must be an integral type with a size of 1, 2, or 4 bytes, which will be interpreted
|
The value_type of the iterator must be an integral type with a size of 1, 2, or 4 bytes, which will be interpreted
|
||||||
respectively as UTF-8, UTF-16, and UTF-32.
|
respectively as UTF-8, UTF-16, and UTF-32. If `SentinelType` differs from `IteratorType`, it must be comparable to
|
||||||
|
the iterator type with `operator!=`.
|
||||||
|
|
||||||
The SAX event lister must follow the interface of [`json_sax`](../json_sax/index.md).
|
The SAX event lister must follow the interface of [`json_sax`](../json_sax/index.md).
|
||||||
|
|
||||||
@@ -39,14 +40,21 @@ The SAX event lister must follow the interface of [`json_sax`](../json_sax/index
|
|||||||
- a `FILE` pointer
|
- a `FILE` pointer
|
||||||
- a C-style array of characters
|
- a C-style array of characters
|
||||||
- a pointer to a null-terminated string of single byte characters
|
- a pointer to a null-terminated string of single byte characters
|
||||||
- an object `obj` for which `begin(obj)` and `end(obj)` produces a valid pair of
|
- a container `obj` for which `begin(obj)` and `end(obj)` produce a valid pair of iterators
|
||||||
iterators.
|
(as found via ADL or member functions, with semantics compatible to `std::begin` and `std::end`)
|
||||||
|
|
||||||
`IteratorType`
|
`IteratorType`
|
||||||
: Description
|
: a compatible iterator type for overload (2); a pair of character iterators whose `value_type` is an integral type
|
||||||
|
with a size of 1, 2, or 4 bytes (interpreted respectively as UTF-8, UTF-16, and UTF-32)
|
||||||
|
|
||||||
|
`SentinelType`
|
||||||
|
: defaults to `IteratorType`; may be a different type comparable to `IteratorType` via `operator!=`, for overload (2), for instance.
|
||||||
|
|
||||||
|
- a custom sentinel type for C++20 ranges
|
||||||
|
- `std::default_sentinel_t`, when `IteratorType` is `std::counted_iterator`
|
||||||
|
|
||||||
`SAX`
|
`SAX`
|
||||||
: Description
|
: a class fulfilling the SAX event listener interface; see [`json_sax`](../json_sax/index.md)
|
||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
@@ -61,7 +69,8 @@ The SAX event lister must follow the interface of [`json_sax`](../json_sax/index
|
|||||||
[`input_format_t`](input_format_t.md) for more information
|
[`input_format_t`](input_format_t.md) for more information
|
||||||
|
|
||||||
`strict` (in)
|
`strict` (in)
|
||||||
: whether the input has to be consumed completely (optional, `#!cpp true` by default)
|
: whether the input has to be consumed completely (optional, `#!cpp true` by default); when `#!cpp false` and the
|
||||||
|
input is a `#!cpp std::istream`, the stream is left positioned right after the parsed value
|
||||||
|
|
||||||
`ignore_comments` (in)
|
`ignore_comments` (in)
|
||||||
: whether comments should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error
|
: whether comments should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error
|
||||||
@@ -75,7 +84,7 @@ The SAX event lister must follow the interface of [`json_sax`](../json_sax/index
|
|||||||
: iterator to the start of a character range
|
: iterator to the start of a character range
|
||||||
|
|
||||||
`last` (in)
|
`last` (in)
|
||||||
: iterator to the end of a character range
|
: iterator to the end of a character range, or a sentinel value that compares equal to the end iterator with `operator!=`
|
||||||
|
|
||||||
## Return value
|
## Return value
|
||||||
|
|
||||||
@@ -89,10 +98,6 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
|
|||||||
|
|
||||||
- Throws [`parse_error.101`](../../home/exceptions.md#jsonexceptionparse_error101) in case of an unexpected token, or
|
- Throws [`parse_error.101`](../../home/exceptions.md#jsonexceptionparse_error101) in case of an unexpected token, or
|
||||||
empty input like a null `FILE*` or `char*` pointer.
|
empty input like a null `FILE*` or `char*` pointer.
|
||||||
- Throws [`parse_error.102`](../../home/exceptions.md#jsonexceptionparse_error102) if `to_unicode` fails or surrogate
|
|
||||||
error.
|
|
||||||
- Throws [`parse_error.103`](../../home/exceptions.md#jsonexceptionparse_error103) if `to_unicode` fails.
|
|
||||||
- Throws [`other_error.502`](../../home/exceptions.md#jsonexceptionother_error502) if `sax` is a null pointer.
|
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
@@ -120,12 +125,20 @@ A UTF-8 byte order mark is silently ignored.
|
|||||||
--8<-- "examples/sax_parse.output"
|
--8<-- "examples/sax_parse.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [parse](parse.md) - deserialize from a compatible input
|
||||||
|
- [accept](accept.md) - check if the input is valid JSON
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 3.2.0.
|
- Added in version 3.2.0.
|
||||||
- Ignoring comments via `ignore_comments` added in version 3.9.0.
|
- Ignoring comments via `ignore_comments` added in version 3.9.0.
|
||||||
- Added `ignore_trailing_commas` in version 3.12.1.
|
- Added `ignore_trailing_commas` in version 3.13.0.
|
||||||
- Added `json.exception.other_error.502` exception in version 3.12.1.
|
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
|
||||||
|
- Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0.
|
||||||
|
- Changed in version 4.0.0 to leave a `#!cpp std::istream` positioned right after the parsed value when `strict` is
|
||||||
|
`#!cpp false`; see [`operator>>`](../operator_gtgt.md#notes).
|
||||||
|
|
||||||
!!! warning "Deprecation"
|
!!! warning "Deprecation"
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
# <small>std::</small>formatter<nlohmann::basic_json\>
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
namespace std {
|
||||||
|
template <>
|
||||||
|
struct formatter<nlohmann::basic_json, char>;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Specialization to make JSON values formattable with [`std::format`](https://en.cppreference.com/w/cpp/utility/format/format)
|
||||||
|
(and the other members of C++20's `<format>` header, such as `std::format_to`).
|
||||||
|
|
||||||
|
A subset of the [standard format spec grammar](https://en.cppreference.com/w/cpp/utility/format/spec) is
|
||||||
|
supported, repurposed for JSON pretty-printing; any other spec component (sign, the `0` flag, precision,
|
||||||
|
`L`, a dynamic width such as `#!cpp "{:{}}"`, or a trailing type character) throws
|
||||||
|
[`std::format_error`](https://en.cppreference.com/w/cpp/utility/format/format_error):
|
||||||
|
|
||||||
|
- `#!cpp "{}"` serializes the value the same way as [`dump()`](dump.md) (compact, no whitespace).
|
||||||
|
- `#!cpp "{:#}"` ("alternate form") serializes the value the same way as `#!cpp dump(4)` (pretty-printed
|
||||||
|
with an indent of 4).
|
||||||
|
- A width, with or without `#!cpp "#"` (e.g. `#!cpp "{:2}"` or `#!cpp "{:#2}"`), serializes the value the
|
||||||
|
same way as `#!cpp dump(width)` — a width on its own implies pretty-printing, since an indent size has
|
||||||
|
no meaning for compact output.
|
||||||
|
- `fill-and-align` (e.g. `#!cpp "{:.>#}"` or `#!cpp "{:.>3}"`) picks a custom indent character, the same
|
||||||
|
way as `#!cpp dump(indent, indent_char)`. The alignment direction itself (`#!cpp '<'`, `#!cpp '>'`,
|
||||||
|
`#!cpp '^'`) has no separate meaning for JSON values — only the fill character before it is used, and
|
||||||
|
any of the three directions is accepted.
|
||||||
|
|
||||||
|
This specialization is only available for `#!cpp char`-based JSON values and only if the standard library
|
||||||
|
provides `<format>`, controlled by the [`JSON_HAS_STD_FORMAT`](../macros/json_has_std_format.md) macro.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example shows how to format JSON values with `std::format`.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/std_formatter.c++20.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```json
|
||||||
|
--8<-- "examples/std_formatter.c++20.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [dump](dump.md) - serialization
|
||||||
|
- [operator<<(std::ostream&)](../operator_ltlt.md) - serialize to stream
|
||||||
|
- [format_as](format_as.md) - customization point used by `fmt::format` (fmtlib)
|
||||||
|
- [Serialization](../../features/serialization.md) - the serialization article
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.13.0.
|
||||||
@@ -16,6 +16,14 @@ Exchanges the values of two JSON objects.
|
|||||||
`j2` (in, out)
|
`j2` (in, out)
|
||||||
: value to be replaced by `j1`
|
: value to be replaced by `j1`
|
||||||
|
|
||||||
|
## Exception safety
|
||||||
|
|
||||||
|
No-throw guarantee: this function never throws exceptions.
|
||||||
|
|
||||||
|
## Complexity
|
||||||
|
|
||||||
|
Constant.
|
||||||
|
|
||||||
## Possible implementation
|
## Possible implementation
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ The type used to store JSON strings.
|
|||||||
[RFC 8259](https://tools.ietf.org/html/rfc8259) describes JSON strings as follows:
|
[RFC 8259](https://tools.ietf.org/html/rfc8259) describes JSON strings as follows:
|
||||||
> A string is a sequence of zero or more Unicode characters.
|
> A string is a sequence of zero or more Unicode characters.
|
||||||
|
|
||||||
To store objects in C++, a type is defined by the template parameter described below. Unicode values are split by the
|
To store strings in C++, a type is defined by the template parameter described below. Unicode values are split by the
|
||||||
JSON class into byte-sized characters during deserialization.
|
JSON class into byte-sized characters during deserialization.
|
||||||
|
|
||||||
## Template parameters
|
## Template parameters
|
||||||
@@ -18,6 +18,11 @@ JSON class into byte-sized characters during deserialization.
|
|||||||
: the container to store strings (e.g., `std::string`). Note this container is used for keys/names in objects, see
|
: the container to store strings (e.g., `std::string`). Note this container is used for keys/names in objects, see
|
||||||
[object_t](object_t.md).
|
[object_t](object_t.md).
|
||||||
|
|
||||||
|
`StringType` must have a `char`-compatible `value_type`: the library relies on UTF-8/`char`-based storage and
|
||||||
|
processing internally, so `std::wstring`, `std::u16string`, and `std::u32string` are **not** valid choices for
|
||||||
|
`StringType`. To work with wide-character data, convert it to/from UTF-8 at the boundary instead -- see the
|
||||||
|
FAQ's [wide string handling](../../home/faq.md#wide-string-handling) section for a conversion recipe.
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
#### Default type
|
#### Default type
|
||||||
@@ -45,6 +50,15 @@ This implementation is interoperable as it does compare strings code unit by cod
|
|||||||
String values are stored as pointers in a `basic_json` type. That is, for any access to string values, a pointer of type
|
String values are stored as pointers in a `basic_json` type. That is, for any access to string values, a pointer of type
|
||||||
`string_t*` must be dereferenced.
|
`string_t*` must be dereferenced.
|
||||||
|
|
||||||
|
#### Cross-`basic_json` conversion requirements
|
||||||
|
|
||||||
|
When converting a string value from one `basic_json` specialization to another via the
|
||||||
|
[converting constructor](basic_json.md#overload-4), the target `string_t` must be directly
|
||||||
|
constructible from the source `basic_json`'s `string_t` type. If this requirement is not met, the
|
||||||
|
conversion does not fail; instead, the string is silently converted as an array of character codes,
|
||||||
|
which is incorrect. See [issue #3425](https://github.com/nlohmann/json/issues/3425) for details
|
||||||
|
and an example.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
??? example
|
??? example
|
||||||
|
|||||||
@@ -2,10 +2,20 @@
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
// (1)
|
// (1)
|
||||||
void swap(reference other) noexcept;
|
void swap(reference other) noexcept (
|
||||||
|
std::is_nothrow_move_constructible<value_t>::value &&
|
||||||
|
std::is_nothrow_move_assignable<value_t>::value &&
|
||||||
|
std::is_nothrow_move_constructible<json_value>::value &&
|
||||||
|
std::is_nothrow_move_assignable<json_value>::value
|
||||||
|
);
|
||||||
|
|
||||||
// (2)
|
// (2)
|
||||||
void swap(reference left, reference right) noexcept;
|
friend void swap(reference left, reference right) noexcept (
|
||||||
|
std::is_nothrow_move_constructible<value_t>::value &&
|
||||||
|
std::is_nothrow_move_assignable<value_t>::value &&
|
||||||
|
std::is_nothrow_move_constructible<json_value>::value &&
|
||||||
|
std::is_nothrow_move_assignable<json_value>::value
|
||||||
|
);
|
||||||
|
|
||||||
// (3)
|
// (3)
|
||||||
void swap(array_t& other);
|
void swap(array_t& other);
|
||||||
@@ -56,15 +66,15 @@ void swap(typename binary_t::container_type& other);
|
|||||||
1. No-throw guarantee: this function never throws exceptions.
|
1. No-throw guarantee: this function never throws exceptions.
|
||||||
2. No-throw guarantee: this function never throws exceptions.
|
2. No-throw guarantee: this function never throws exceptions.
|
||||||
3. Throws [`type_error.310`](../../home/exceptions.md#jsonexceptiontype_error310) if called on JSON values other than
|
3. Throws [`type_error.310`](../../home/exceptions.md#jsonexceptiontype_error310) if called on JSON values other than
|
||||||
arrays; example: `"cannot use swap() with boolean"`
|
arrays; example: `"cannot use swap(array_t&) with boolean"`
|
||||||
4. Throws [`type_error.310`](../../home/exceptions.md#jsonexceptiontype_error310) if called on JSON values other than
|
4. Throws [`type_error.310`](../../home/exceptions.md#jsonexceptiontype_error310) if called on JSON values other than
|
||||||
objects; example: `"cannot use swap() with boolean"`
|
objects; example: `"cannot use swap(object_t&) with boolean"`
|
||||||
5. Throws [`type_error.310`](../../home/exceptions.md#jsonexceptiontype_error310) if called on JSON values other than
|
5. Throws [`type_error.310`](../../home/exceptions.md#jsonexceptiontype_error310) if called on JSON values other than
|
||||||
strings; example: `"cannot use swap() with boolean"`
|
strings; example: `"cannot use swap(string_t&) with boolean"`
|
||||||
6. Throws [`type_error.310`](../../home/exceptions.md#jsonexceptiontype_error310) if called on JSON values other than
|
6. Throws [`type_error.310`](../../home/exceptions.md#jsonexceptiontype_error310) if called on JSON values other than
|
||||||
binaries; example: `"cannot use swap() with boolean"`
|
binaries; example: `"cannot use swap(binary_t&) with boolean"`
|
||||||
7. Throws [`type_error.310`](../../home/exceptions.md#jsonexceptiontype_error310) if called on JSON values other than
|
7. Throws [`type_error.310`](../../home/exceptions.md#jsonexceptiontype_error310) if called on JSON values other than
|
||||||
binaries; example: `"cannot use swap() with boolean"`
|
binaries; example: `"cannot use swap(binary_t::container_type&) with boolean"`
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
@@ -128,7 +138,7 @@ Constant.
|
|||||||
--8<-- "examples/swap__string_t.output"
|
--8<-- "examples/swap__string_t.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
??? example "Example: Swap string (6)"
|
??? example "Example: Swap binary (6)"
|
||||||
|
|
||||||
The example below shows how binary values can be swapped with `swap()`.
|
The example below shows how binary values can be swapped with `swap()`.
|
||||||
|
|
||||||
@@ -145,6 +155,8 @@ Constant.
|
|||||||
## See also
|
## See also
|
||||||
|
|
||||||
- [std::swap<basic_json\>](std_swap.md)
|
- [std::swap<basic_json\>](std_swap.md)
|
||||||
|
- [operator=](operator=.md) copy assignment
|
||||||
|
- [basic_json](basic_json.md) create a JSON value
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -72,6 +72,14 @@ Linear in the size of the JSON value `j`.
|
|||||||
--8<-- "examples/to_bjdata.output"
|
--8<-- "examples/to_bjdata.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [from_bjdata](from_bjdata.md) create a JSON value from an input in BJData format
|
||||||
|
- [to_cbor](to_cbor.md) create a CBOR serialization of a JSON value
|
||||||
|
- [to_msgpack](to_msgpack.md) create a MessagePack serialization of a JSON value
|
||||||
|
- [to_bson](to_bson.md) create a BSON serialization of a JSON value
|
||||||
|
- [to_ubjson](to_ubjson.md) create a UBJSON serialization of a JSON value
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 3.11.0.
|
- Added in version 3.11.0.
|
||||||
|
|||||||
@@ -34,6 +34,16 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
|||||||
|
|
||||||
Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
|
Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
|
||||||
|
|
||||||
|
## Exceptions
|
||||||
|
|
||||||
|
- Throws [`type_error.317`](../../home/exceptions.md#jsonexceptiontype_error317) if the top-level type of the JSON value
|
||||||
|
is not an object; example: `"to serialize to BSON, top-level type must be object, but is string"`
|
||||||
|
- Throws [`out_of_range.409`](../../home/exceptions.md#jsonexceptionout_of_range409) if a key in the JSON object contains
|
||||||
|
a null byte (code point U+0000); example: `"BSON key cannot contain code point U+0000 (at byte 2)"`
|
||||||
|
- Throws [`out_of_range.412`](../../home/exceptions.md#jsonexceptionout_of_range412) if the length of a document, array,
|
||||||
|
string, or binary value exceeds the range of the 32-bit BSON length field; example:
|
||||||
|
`"BSON length 2147483661 exceeds maximum of 2147483647"`
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
Linear in the size of the JSON value `j`.
|
Linear in the size of the JSON value `j`.
|
||||||
@@ -54,6 +64,14 @@ Linear in the size of the JSON value `j`.
|
|||||||
--8<-- "examples/to_bson.output"
|
--8<-- "examples/to_bson.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [from_bson](from_bson.md) create a JSON value from an input in BSON format
|
||||||
|
- [to_cbor](to_cbor.md) create a CBOR serialization of a JSON value
|
||||||
|
- [to_msgpack](to_msgpack.md) create a MessagePack serialization of a JSON value
|
||||||
|
- [to_ubjson](to_ubjson.md) create a UBJSON serialization of a JSON value
|
||||||
|
- [to_bjdata](to_bjdata.md) create a BJData serialization of a JSON value
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 3.4.0.
|
- Added in version 3.4.0.
|
||||||
@@ -55,6 +55,14 @@ Linear in the size of the JSON value `j`.
|
|||||||
--8<-- "examples/to_cbor.output"
|
--8<-- "examples/to_cbor.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [from_cbor](from_cbor.md) create a JSON value from an input in CBOR format
|
||||||
|
- [to_msgpack](to_msgpack.md) create a MessagePack serialization of a JSON value
|
||||||
|
- [to_bson](to_bson.md) create a BSON serialization of a JSON value
|
||||||
|
- [to_ubjson](to_ubjson.md) create a UBJSON serialization of a JSON value
|
||||||
|
- [to_bjdata](to_bjdata.md) create a BJData serialization of a JSON value
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 2.0.9.
|
- Added in version 2.0.9.
|
||||||
|
|||||||
@@ -54,6 +54,14 @@ Linear in the size of the JSON value `j`.
|
|||||||
--8<-- "examples/to_msgpack.output"
|
--8<-- "examples/to_msgpack.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [from_msgpack](from_msgpack.md) create a JSON value from an input in MessagePack format
|
||||||
|
- [to_cbor](to_cbor.md) create a CBOR serialization of a JSON value
|
||||||
|
- [to_bson](to_bson.md) create a BSON serialization of a JSON value
|
||||||
|
- [to_ubjson](to_ubjson.md) create a UBJSON serialization of a JSON value
|
||||||
|
- [to_bjdata](to_bjdata.md) create a BJData serialization of a JSON value
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 2.0.9.
|
- Added in version 2.0.9.
|
||||||
@@ -59,6 +59,7 @@ std::string to_string(const BasicJsonType& j)
|
|||||||
## See also
|
## See also
|
||||||
|
|
||||||
- [dump](dump.md)
|
- [dump](dump.md)
|
||||||
|
- [Serialization](../../features/serialization.md) - the serialization article
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -65,6 +65,14 @@ Linear in the size of the JSON value `j`.
|
|||||||
--8<-- "examples/to_ubjson.output"
|
--8<-- "examples/to_ubjson.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [from_ubjson](from_ubjson.md) create a JSON value from an input in UBJSON format
|
||||||
|
- [to_cbor](to_cbor.md) create a CBOR serialization of a JSON value
|
||||||
|
- [to_msgpack](to_msgpack.md) create a MessagePack serialization of a JSON value
|
||||||
|
- [to_bson](to_bson.md) create a BSON serialization of a JSON value
|
||||||
|
- [to_bjdata](to_bjdata.md) create a BJData serialization of a JSON value
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 3.1.0.
|
- Added in version 3.1.0.
|
||||||
@@ -67,6 +67,7 @@ classDiagram
|
|||||||
|
|
||||||
## See also
|
## See also
|
||||||
|
|
||||||
|
- [`exception`](exception.md) for the base class of all exceptions thrown by the library
|
||||||
- [List of type errors](../../home/exceptions.md#type-errors)
|
- [List of type errors](../../home/exceptions.md#type-errors)
|
||||||
- [`parse_error`](parse_error.md) for exceptions indicating a parse error
|
- [`parse_error`](parse_error.md) for exceptions indicating a parse error
|
||||||
- [`invalid_iterator`](invalid_iterator.md) for exceptions indicating errors with iterators
|
- [`invalid_iterator`](invalid_iterator.md) for exceptions indicating errors with iterators
|
||||||
|
|||||||
@@ -21,6 +21,12 @@ a string representation of the type ([`value_t`](value_t.md)):
|
|||||||
| array | `"array"` |
|
| array | `"array"` |
|
||||||
| binary | `"binary"` |
|
| binary | `"binary"` |
|
||||||
| discarded | `"discarded"` |
|
| discarded | `"discarded"` |
|
||||||
|
| invalid (corrupted value) | `"invalid"` |
|
||||||
|
|
||||||
|
!!! note "The \"invalid\" type"
|
||||||
|
|
||||||
|
The `"invalid"` return value indicates a corrupted JSON value — this can occur if an enum value falls outside the
|
||||||
|
range of valid `value_t` values. This is useful for diagnosing data corruption or internal errors.
|
||||||
|
|
||||||
## Exception safety
|
## Exception safety
|
||||||
|
|
||||||
@@ -52,3 +58,4 @@ Constant.
|
|||||||
- Part of the public API version since 2.1.0.
|
- Part of the public API version since 2.1.0.
|
||||||
- Changed return value to `const char*` and added `noexcept` in version 3.0.0.
|
- Changed return value to `const char*` and added `noexcept` in version 3.0.0.
|
||||||
- Added support for binary type in version 3.8.0.
|
- Added support for binary type in version 3.8.0.
|
||||||
|
- Added `"invalid"` return value for corrupted JSON values in version 3.13.0.
|
||||||
@@ -25,6 +25,10 @@ The function can throw the following exceptions:
|
|||||||
|
|
||||||
- Throws [`type_error.314`](../../home/exceptions.md#jsonexceptiontype_error314) if value is not an object
|
- Throws [`type_error.314`](../../home/exceptions.md#jsonexceptiontype_error314) if value is not an object
|
||||||
- Throws [`type_error.315`](../../home/exceptions.md#jsonexceptiontype_error315) if object values are not primitive
|
- Throws [`type_error.315`](../../home/exceptions.md#jsonexceptiontype_error315) if object values are not primitive
|
||||||
|
- Throws [`type_error.313`](../../home/exceptions.md#jsonexceptiontype_error313) if a key (JSON pointer) leads to a
|
||||||
|
conflicting nesting; example: `"invalid value to unflatten"`
|
||||||
|
- Throws [`parse_error.109`](../../home/exceptions.md#jsonexceptionparse_error109) if an array index in a key is not a
|
||||||
|
number; example: `"array index 'one' is not a number"`
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ void update(const_iterator first, const_iterator last, bool merge_objects = fals
|
|||||||
When `merge_objects` is `#!c false` (default), existing keys are overwritten. When `merge_objects` is `#!c true`,
|
When `merge_objects` is `#!c false` (default), existing keys are overwritten. When `merge_objects` is `#!c true`,
|
||||||
recursively merges objects with common keys.
|
recursively merges objects with common keys.
|
||||||
|
|
||||||
|
If the JSON value is `#!json null`, it is implicitly converted to an empty object before the values are inserted.
|
||||||
|
|
||||||
The function is motivated by Python's [dict.update](https://docs.python.org/3.6/library/stdtypes.html#dict.update)
|
The function is motivated by Python's [dict.update](https://docs.python.org/3.6/library/stdtypes.html#dict.update)
|
||||||
function.
|
function.
|
||||||
|
|
||||||
@@ -28,8 +30,8 @@ iterators (including the `end()` iterator) and all references to the elements ar
|
|||||||
: JSON object to read values from
|
: JSON object to read values from
|
||||||
|
|
||||||
`merge_objects` (in)
|
`merge_objects` (in)
|
||||||
: when `#!c true`, existing keys are not overwritten, but contents of objects are merged recursively (default:
|
: when `#!c true`, keys that exist in both objects and whose value in the source is itself an object are merged
|
||||||
`#!c false`)
|
recursively; all other values are overwritten as usual (default: `#!c false`)
|
||||||
|
|
||||||
`first` (in)
|
`first` (in)
|
||||||
: the beginning of the range of elements to insert
|
: the beginning of the range of elements to insert
|
||||||
@@ -37,6 +39,10 @@ iterators (including the `end()` iterator) and all references to the elements ar
|
|||||||
`last` (in)
|
`last` (in)
|
||||||
: the end of the range of elements to insert
|
: the end of the range of elements to insert
|
||||||
|
|
||||||
|
## Exception safety
|
||||||
|
|
||||||
|
Basic guarantee: if an exception is thrown during the operation, the JSON value may be partially modified.
|
||||||
|
|
||||||
## Exceptions
|
## Exceptions
|
||||||
|
|
||||||
1. The function can throw the following exceptions:
|
1. The function can throw the following exceptions:
|
||||||
@@ -45,8 +51,6 @@ iterators (including the `end()` iterator) and all references to the elements ar
|
|||||||
2. The function can throw the following exceptions:
|
2. The function can throw the following exceptions:
|
||||||
- Throws [`type_error.312`](../../home/exceptions.md#jsonexceptiontype_error312) if called on JSON values other than
|
- Throws [`type_error.312`](../../home/exceptions.md#jsonexceptiontype_error312) if called on JSON values other than
|
||||||
objects; example: `"cannot use update() with string"`
|
objects; example: `"cannot use update() with string"`
|
||||||
- Throws [`invalid_iterator.202`](../../home/exceptions.md#jsonexceptioninvalid_iterator202) if called on an
|
|
||||||
iterator which does not belong to the current JSON value; example: `"iterator does not fit current value"`
|
|
||||||
- Throws [`invalid_iterator.210`](../../home/exceptions.md#jsonexceptioninvalid_iterator210) if `first` and `last`
|
- Throws [`invalid_iterator.210`](../../home/exceptions.md#jsonexceptioninvalid_iterator210) if `first` and `last`
|
||||||
do not belong to the same JSON value; example: `"iterators do not fit"`
|
do not belong to the same JSON value; example: `"iterators do not fit"`
|
||||||
|
|
||||||
@@ -141,6 +145,12 @@ iterators (including the `end()` iterator) and all references to the elements ar
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [insert](insert.md) add values to an array/object
|
||||||
|
- [merge_patch](merge_patch.md) applies a JSON Merge Patch
|
||||||
|
- [Modifying values](../../features/modifying_values.md) - the article on modifying values
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 3.0.0.
|
- Added in version 3.0.0.
|
||||||
|
|||||||
Loaded 100 of 252 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user