Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
379756e92e |
No files matched your search
+1
-1
@@ -66,7 +66,7 @@ labels:
|
|||||||
- "tests/src/fuzzer-(parse_json_view|json_view_image)\\.cpp"
|
- "tests/src/fuzzer-(parse_json_view|json_view_image)\\.cpp"
|
||||||
- "tests/benchmarks/json_view/.*"
|
- "tests/benchmarks/json_view/.*"
|
||||||
- "tools/amalgamate/config_json_view\\.json"
|
- "tools/amalgamate/config_json_view\\.json"
|
||||||
- "docs/mkdocs/docs/features/json_view/.*"
|
- "docs/mkdocs/docs/features/json_view\\.md"
|
||||||
- "docs/mkdocs/docs/api/basic_json_(document|view)/.*"
|
- "docs/mkdocs/docs/api/basic_json_(document|view)/.*"
|
||||||
- "docs/mkdocs/docs/api/(ordered_)?json_(editable_)?(document|view)\\.md"
|
- "docs/mkdocs/docs/api/(ordered_)?json_(editable_)?(document|view)\\.md"
|
||||||
- "docs/mkdocs/docs/examples/(basic_json_(document|view)__|(ordered_)?json_(editable_)?(document|view)).*"
|
- "docs/mkdocs/docs/examples/(basic_json_(document|view)__|(ordered_)?json_(editable_)?(document|view)).*"
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
|
uses: step-security/harden-runner@dc2769abcc0fcfbadfc1df54081c1608579ef6b2 # v2.22.2
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ jobs:
|
|||||||
runs-on: ubuntu-26.04
|
runs-on: ubuntu-26.04
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
|
uses: step-security/harden-runner@dc2769abcc0fcfbadfc1df54081c1608579ef6b2 # v2.22.2
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
|
uses: step-security/harden-runner@dc2769abcc0fcfbadfc1df54081c1608579ef6b2 # v2.22.2
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
@@ -67,10 +67,10 @@ jobs:
|
|||||||
- name: Install astyle
|
- name: Install astyle
|
||||||
run: |
|
run: |
|
||||||
python3 -mvenv venv
|
python3 -mvenv venv
|
||||||
venv/bin/pip3 install --require-hashes -r $MAIN_DIR/tools/astyle/requirements.txt
|
venv/bin/pip3 install -r $MAIN_DIR/tools/astyle/requirements.txt
|
||||||
|
|
||||||
- name: Install generate_natvis dependencies
|
- name: Install generate_natvis dependencies
|
||||||
run: pip3 install --require-hashes -r $NATVIS_TOOL_DIR/requirements.txt
|
run: pip3 install -r $NATVIS_TOOL_DIR/requirements.txt
|
||||||
|
|
||||||
- name: Regenerate the tools/macro_builder tables in macro_scope.hpp
|
- name: Regenerate the tools/macro_builder tables in macro_scope.hpp
|
||||||
run: |
|
run: |
|
||||||
@@ -115,7 +115,9 @@ jobs:
|
|||||||
|
|
||||||
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 .
|
||||||
python3 $TOOL_DIR/amalgamate.py -c $TOOL_DIR/config_json_view.json -s .
|
# the configuration of json_view.hpp comes with the pull request until
|
||||||
|
# it is on develop; the tool itself is still develop's
|
||||||
|
python3 $TOOL_DIR/amalgamate.py -c $MAIN_DIR/tools/amalgamate/config_json_view.json -s .
|
||||||
|
|
||||||
# the header list of the Bazel "json" target must match the files in include/
|
# the header list of the Bazel "json" target must match the files in include/
|
||||||
cmake -P cmake/scripts/gen_bazel_build_file.cmake
|
cmake -P cmake/scripts/gen_bazel_build_file.cmake
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ jobs:
|
|||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
|
uses: step-security/harden-runner@dc2769abcc0fcfbadfc1df54081c1608579ef6b2 # v2.22.2
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ jobs:
|
|||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
|
uses: step-security/harden-runner@dc2769abcc0fcfbadfc1df54081c1608579ef6b2 # v2.22.2
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
|
uses: step-security/harden-runner@dc2769abcc0fcfbadfc1df54081c1608579ef6b2 # v2.22.2
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
@@ -38,13 +38,14 @@ jobs:
|
|||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3
|
uses: github/codeql-action/init@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1
|
||||||
with:
|
with:
|
||||||
languages: c-cpp
|
languages: c-cpp
|
||||||
# Analyze the sources without compiling them. Autobuild compiled the
|
|
||||||
# whole test suite and the resulting database was so large that the
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
# runner often lost communication with the server while importing it.
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
build-mode: none
|
- name: Autobuild
|
||||||
|
uses: github/codeql-action/autobuild@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3
|
uses: github/codeql-action/analyze@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1
|
||||||
@@ -20,7 +20,7 @@ jobs:
|
|||||||
pull-requests: write
|
pull-requests: write
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
|
uses: step-security/harden-runner@dc2769abcc0fcfbadfc1df54081c1608579ef6b2 # v2.22.2
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ jobs:
|
|||||||
runs-on: ubuntu-26.04
|
runs-on: ubuntu-26.04
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
|
uses: step-security/harden-runner@dc2769abcc0fcfbadfc1df54081c1608579ef6b2 # v2.22.2
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ jobs:
|
|||||||
security-events: write
|
security-events: write
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
|
uses: step-security/harden-runner@dc2769abcc0fcfbadfc1df54081c1608579ef6b2 # v2.22.2
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
@@ -48,6 +48,6 @@ jobs:
|
|||||||
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@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3
|
uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1
|
||||||
with:
|
with:
|
||||||
sarif_file: ${{github.workspace}}/flawfinder_results.sarif
|
sarif_file: ${{github.workspace}}/flawfinder_results.sarif
|
||||||
@@ -54,7 +54,7 @@ jobs:
|
|||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
|
uses: step-security/harden-runner@dc2769abcc0fcfbadfc1df54081c1608579ef6b2 # v2.22.2
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
|
uses: step-security/harden-runner@dc2769abcc0fcfbadfc1df54081c1608579ef6b2 # v2.22.2
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ jobs:
|
|||||||
runs-on: ubuntu-26.04
|
runs-on: ubuntu-26.04
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
|
uses: step-security/harden-runner@dc2769abcc0fcfbadfc1df54081c1608579ef6b2 # v2.22.2
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
|
uses: step-security/harden-runner@dc2769abcc0fcfbadfc1df54081c1608579ef6b2 # v2.22.2
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
@@ -80,6 +80,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@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3
|
uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1
|
||||||
with:
|
with:
|
||||||
sarif_file: results.sarif
|
sarif_file: results.sarif
|
||||||
@@ -36,7 +36,7 @@ jobs:
|
|||||||
runs-on: ubuntu-26.04
|
runs-on: ubuntu-26.04
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
|
uses: step-security/harden-runner@dc2769abcc0fcfbadfc1df54081c1608579ef6b2 # v2.22.2
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
@@ -52,12 +52,8 @@ jobs:
|
|||||||
# the old action fell back to, running community rules with no token.
|
# 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
|
# SEMGREP_APP_TOKEN is still passed through so registry auth works if a
|
||||||
# token is ever added.
|
# token is ever added.
|
||||||
# The version is pinned, but not by hash: Semgrep pins its own dependencies
|
|
||||||
# to exact or compatible-release versions, so a hash-pinned lock file broke
|
|
||||||
# on almost every Dependabot bump of a transitive dependency. Dependabot
|
|
||||||
# only bumps the semgrep line; pip resolves the rest.
|
|
||||||
- name: Install Semgrep
|
- name: Install Semgrep
|
||||||
run: python3 -m pip install --user -r cmake/requirements/requirements-semgrep.txt
|
run: python3 -m pip install --user semgrep==1.168.0
|
||||||
|
|
||||||
# `semgrep scan --sarif` always exits 0 even with findings; continue-on-error
|
# `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.
|
# is a safety net so the SARIF upload still runs if the scan itself errors.
|
||||||
@@ -69,7 +65,7 @@ jobs:
|
|||||||
|
|
||||||
# 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@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3
|
uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1
|
||||||
with:
|
with:
|
||||||
sarif_file: semgrep.sarif
|
sarif_file: semgrep.sarif
|
||||||
if: always()
|
if: always()
|
||||||
@@ -16,7 +16,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
|
uses: step-security/harden-runner@dc2769abcc0fcfbadfc1df54081c1608579ef6b2 # v2.22.2
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0
|
uses: lukka/get-cmake@a89e43e22a96abafcd7a62db652a65ecd33052c9 # v4.4.4
|
||||||
- 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
|
||||||
@@ -38,11 +38,11 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0
|
uses: lukka/get-cmake@a89e43e22a96abafcd7a62db652a65ecd33052c9 # v4.4.4
|
||||||
- name: Check that Meson and pkg-config offer the CMake options
|
- name: Check that Meson and pkg-config offer the CMake options
|
||||||
run: make check_build_options
|
run: make check_build_options
|
||||||
- name: Install Meson
|
- name: Install Meson
|
||||||
run: pip install --require-hashes -r cmake/requirements/requirements-meson.txt
|
run: pip install meson
|
||||||
- name: Install with Meson
|
- name: Install with Meson
|
||||||
run: |
|
run: |
|
||||||
meson setup build-meson --prefix=${{ github.workspace }}/install
|
meson setup build-meson --prefix=${{ github.workspace }}/install
|
||||||
@@ -80,7 +80,7 @@ jobs:
|
|||||||
runs-on: ubuntu-26.04
|
runs-on: ubuntu-26.04
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
|
uses: step-security/harden-runner@dc2769abcc0fcfbadfc1df54081c1608579ef6b2 # v2.22.2
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0
|
uses: lukka/get-cmake@a89e43e22a96abafcd7a62db652a65ecd33052c9 # v4.4.4
|
||||||
- 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
|
||||||
@@ -112,7 +112,7 @@ jobs:
|
|||||||
target: [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_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@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
|
uses: step-security/harden-runner@dc2769abcc0fcfbadfc1df54081c1608579ef6b2 # v2.22.2
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0
|
uses: lukka/get-cmake@a89e43e22a96abafcd7a62db652a65ecd33052c9 # v4.4.4
|
||||||
- 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
|
||||||
@@ -142,7 +142,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0
|
uses: lukka/get-cmake@a89e43e22a96abafcd7a62db652a65ecd33052c9 # v4.4.4
|
||||||
- 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
|
||||||
@@ -153,7 +153,7 @@ jobs:
|
|||||||
container: ubuntu:24.04
|
container: ubuntu:24.04
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
target: [ci_cmake_flags, ci_test_diagnostics, ci_test_diagnostic_positions, ci_test_noexceptions, ci_test_noimplicitconversions, ci_test_legacycomparison, ci_test_noglobaludls, ci_test_disableenumserialization, ci_test_disabletuplereferenceconversion, ci_test_skiplibraryversioncheck, ci_test_simdutf, ci_test_strict_nul_handling, ci_test_delete_deprecated_functions, ci_test_no_thread_local, ci_test_recursion_depth_limit_0]
|
target: [ci_cmake_flags, ci_test_diagnostics, ci_test_diagnostic_positions, ci_test_noexceptions, ci_test_noimplicitconversions, ci_test_legacycomparison, ci_test_noglobaludls, ci_test_disableenumserialization, ci_test_disabletuplereferenceconversion, ci_test_skiplibraryversioncheck, ci_test_simdutf, ci_test_strict_nul_handling, ci_test_delete_deprecated_functions, ci_test_no_thread_local]
|
||||||
steps:
|
steps:
|
||||||
- name: Install build-essential
|
- name: Install build-essential
|
||||||
run: apt-get update ; apt-get install -y build-essential unzip wget git
|
run: apt-get update ; apt-get install -y build-essential unzip wget git
|
||||||
@@ -168,7 +168,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0
|
uses: lukka/get-cmake@a89e43e22a96abafcd7a62db652a65ecd33052c9 # v4.4.4
|
||||||
- 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
|
||||||
@@ -178,7 +178,7 @@ jobs:
|
|||||||
runs-on: ubuntu-26.04
|
runs-on: ubuntu-26.04
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
|
uses: step-security/harden-runner@dc2769abcc0fcfbadfc1df54081c1608579ef6b2 # v2.22.2
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
@@ -244,7 +244,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0
|
uses: lukka/get-cmake@a89e43e22a96abafcd7a62db652a65ecd33052c9 # v4.4.4
|
||||||
- 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
|
||||||
@@ -262,7 +262,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0
|
uses: lukka/get-cmake@a89e43e22a96abafcd7a62db652a65ecd33052c9 # v4.4.4
|
||||||
- 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
|
||||||
@@ -279,7 +279,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0
|
uses: lukka/get-cmake@a89e43e22a96abafcd7a62db652a65ecd33052c9 # v4.4.4
|
||||||
- name: Disable filesystem support (std::filesystem is unusable) for clang 7 / 8 / 9 / 10
|
- name: Disable filesystem support (std::filesystem is unusable) 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' }}
|
||||||
@@ -299,7 +299,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0
|
uses: lukka/get-cmake@a89e43e22a96abafcd7a62db652a65ecd33052c9 # v4.4.4
|
||||||
- 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
|
||||||
@@ -319,7 +319,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0
|
uses: lukka/get-cmake@a89e43e22a96abafcd7a62db652a65ecd33052c9 # v4.4.4
|
||||||
- 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++
|
||||||
@@ -346,7 +346,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0
|
uses: lukka/get-cmake@a89e43e22a96abafcd7a62db652a65ecd33052c9 # v4.4.4
|
||||||
- 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
|
||||||
@@ -362,16 +362,13 @@ jobs:
|
|||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
# get-cmake extracts the Ninja zip with the system unzip, which the Clang
|
# The module test uses `import std;`, which needs CMake's experimental
|
||||||
# image lacks; other Clang jobs get away with it by hitting the cache.
|
# import-std support. Its opt-in token is CMake-version-specific, so pin
|
||||||
- name: Install unzip (Clang)
|
# CMake to the version whose token is set in tests/module_cpp20/CMakeLists.txt.
|
||||||
if: matrix.container == 'silkeh/clang:latest'
|
- name: Get pinned CMake and ninja
|
||||||
run: apt-get update ; apt-get install -y unzip
|
uses: lukka/get-cmake@a89e43e22a96abafcd7a62db652a65ecd33052c9 # v4.4.4
|
||||||
# The module test uses `import std;`, which needs CMake 4.5 or newer.
|
|
||||||
- name: Get CMake 4.5+ and ninja
|
|
||||||
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0
|
|
||||||
with:
|
with:
|
||||||
cmakeVersion: '^4.5.0'
|
cmakeVersion: 4.3.4
|
||||||
# Clang: the std library module is provided by libc++ (the image's libstdc++
|
# 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
|
# ships none), and the image's libc++ module manifest has a broken relative
|
||||||
# path — repoint it at the real module sources.
|
# path — repoint it at the real module sources.
|
||||||
@@ -395,7 +392,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0
|
uses: lukka/get-cmake@a89e43e22a96abafcd7a62db652a65ecd33052c9 # v4.4.4
|
||||||
- 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
|
||||||
@@ -412,7 +409,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0
|
uses: lukka/get-cmake@a89e43e22a96abafcd7a62db652a65ecd33052c9 # v4.4.4
|
||||||
- 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
|
||||||
@@ -426,7 +423,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0
|
uses: lukka/get-cmake@a89e43e22a96abafcd7a62db652a65ecd33052c9 # v4.4.4
|
||||||
- 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
|
||||||
@@ -436,7 +433,7 @@ jobs:
|
|||||||
runs-on: ubuntu-26.04
|
runs-on: ubuntu-26.04
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
|
uses: step-security/harden-runner@dc2769abcc0fcfbadfc1df54081c1608579ef6b2 # v2.22.2
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
@@ -446,7 +443,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0
|
uses: lukka/get-cmake@a89e43e22a96abafcd7a62db652a65ecd33052c9 # v4.4.4
|
||||||
- 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
|
||||||
@@ -459,7 +456,7 @@ jobs:
|
|||||||
target: [ci_test_examples, ci_test_build_documentation, ci_test_documentation_mermaid]
|
target: [ci_test_examples, ci_test_build_documentation, ci_test_documentation_mermaid]
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
|
uses: step-security/harden-runner@dc2769abcc0fcfbadfc1df54081c1608579ef6b2 # v2.22.2
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
@@ -487,7 +484,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0
|
uses: lukka/get-cmake@a89e43e22a96abafcd7a62db652a65ecd33052c9 # v4.4.4
|
||||||
- name: Check that the job runs natively on arm64
|
- name: Check that the job runs natively on arm64
|
||||||
run: uname -m && test "$(uname -m)" = aarch64
|
run: uname -m && test "$(uname -m)" = aarch64
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0
|
uses: lukka/get-cmake@a89e43e22a96abafcd7a62db652a65ecd33052c9 # v4.4.4
|
||||||
- name: Set extra CXX_FLAGS for latest std_version
|
- name: Set extra CXX_FLAGS for latest std_version
|
||||||
# /wd5285 silences C5285 emitted by the bundled third-party doctest.h, which
|
# /wd5285 silences C5285 emitted by the bundled third-party doctest.h, which
|
||||||
# specializes std::tuple (newly diagnosed by the VS2026 v145 toolset)
|
# specializes std::tuple (newly diagnosed by the VS2026 v145 toolset)
|
||||||
@@ -212,11 +212,13 @@ jobs:
|
|||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
# The module test uses `import std;`, which needs CMake 4.5 or newer.
|
# The module test uses `import std;`, which needs CMake's experimental
|
||||||
- name: Get CMake 4.5+ and ninja
|
# import-std support. Its opt-in token is CMake-version-specific, so pin
|
||||||
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0
|
# CMake to the version whose token is set in tests/module_cpp20/CMakeLists.txt.
|
||||||
|
- name: Get pinned CMake and ninja
|
||||||
|
uses: lukka/get-cmake@a89e43e22a96abafcd7a62db652a65ecd33052c9 # v4.4.4
|
||||||
with:
|
with:
|
||||||
cmakeVersion: '^4.5.0'
|
cmakeVersion: 4.3.4
|
||||||
# CMAKE_CXX_FLAGS replaces CMake's MSVC defaults (which include /EHsc), and
|
# CMAKE_CXX_FLAGS replaces CMake's MSVC defaults (which include /EHsc), and
|
||||||
# ci_module_cpp20 forwards it to the module build, so list /EHsc explicitly
|
# ci_module_cpp20 forwards it to the module build, so list /EHsc explicitly
|
||||||
- name: Run CMake (Debug)
|
- name: Run CMake (Debug)
|
||||||
|
|||||||
+3
-2
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
# fuzzers
|
# fuzzers
|
||||||
/tests/corpus_*
|
/tests/corpus_*
|
||||||
/tests/*_fuzzer
|
/tests/parse_*_fuzzer
|
||||||
|
|
||||||
# documentation
|
# documentation
|
||||||
/docs/docset/JSON_for_Modern_C++.docset/
|
/docs/docset/JSON_for_Modern_C++.docset/
|
||||||
@@ -47,10 +47,11 @@ nlohmann_json.spdx
|
|||||||
# Bazel-related
|
# Bazel-related
|
||||||
MODULE.bazel.lock
|
MODULE.bazel.lock
|
||||||
|
|
||||||
# backups left by `make check-amalgamation` if it is interrupted
|
# backups left by `make check-amalgamation` or the ci_test_amalgamation target if they are interrupted
|
||||||
/BUILD.bazel~
|
/BUILD.bazel~
|
||||||
/nlohmann_json.natvis~
|
/nlohmann_json.natvis~
|
||||||
/single_include/nlohmann/*.hpp~
|
/single_include/nlohmann/*.hpp~
|
||||||
|
/venv_astyle/
|
||||||
|
|
||||||
# release outputs of `make release`
|
# release outputs of `make release`
|
||||||
/include.zip
|
/include.zip
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ cc_library(
|
|||||||
"include/nlohmann/detail/exceptions.hpp",
|
"include/nlohmann/detail/exceptions.hpp",
|
||||||
"include/nlohmann/detail/hash.hpp",
|
"include/nlohmann/detail/hash.hpp",
|
||||||
"include/nlohmann/detail/input/binary_reader.hpp",
|
"include/nlohmann/detail/input/binary_reader.hpp",
|
||||||
"include/nlohmann/detail/input/contiguous_parser.hpp",
|
|
||||||
"include/nlohmann/detail/input/input_adapters.hpp",
|
"include/nlohmann/detail/input/input_adapters.hpp",
|
||||||
"include/nlohmann/detail/input/json_sax.hpp",
|
"include/nlohmann/detail/input/json_sax.hpp",
|
||||||
"include/nlohmann/detail/input/lexer.hpp",
|
"include/nlohmann/detail/input/lexer.hpp",
|
||||||
|
|||||||
+3272
File diff suppressed because it is too large.
Load diff
@@ -28,7 +28,6 @@ The [GitHub Actions](https://docs.github.com/en/actions) workflows that build, t
|
|||||||
- `publish_documentation.yml` — build and publish the documentation on pushes to the `develop` branch that touch the documentation sources (or the files it embeds).
|
- `publish_documentation.yml` — build and publish the documentation on pushes to the `develop` branch that touch the documentation sources (or the files it embeds).
|
||||||
- `check_docs_links.yml` — check the links of the documentation weekly, as external links can break without any change in this repository.
|
- `check_docs_links.yml` — check the links of the documentation weekly, as external links can break without any change in this repository.
|
||||||
- `cancel_closed_pr_runs.yml` — cancel unfinished workflow runs of a pull request once it is closed or merged.
|
- `cancel_closed_pr_runs.yml` — cancel unfinished workflow runs of a pull request once it is closed or merged.
|
||||||
- `json_view_benchmarks.yml` — compare the performance of `json_view` with other JSON libraries on GitHub-hosted x86-64 and AArch64 Linux runners, on demand or when a pull request gets the label "benchmark".
|
|
||||||
|
|
||||||
Further documentation:
|
Further documentation:
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
.PHONY: all amalgamate check-amalgamation check_build_options pretty install_astyle clean release update_hedley update_hedley_undef BUILD.bazel natvis macro_builder_check run_benchmarks pvs_studio serve_header reuse spdx
|
.PHONY: all amalgamate check-amalgamation check_build_options pretty install_astyle clean ChangeLog.md release update_hedley update_hedley_undef BUILD.bazel natvis macro_builder_check run_benchmarks pvs_studio serve_header reuse spdx
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# configuration
|
# configuration
|
||||||
@@ -40,6 +40,7 @@ MACRO_SCOPE_HPP=include/nlohmann/detail/macro_scope.hpp
|
|||||||
all:
|
all:
|
||||||
@echo "amalgamate - amalgamate files single_include/nlohmann/json{,_fwd,_literals,_view}.hpp from the include/nlohmann sources"
|
@echo "amalgamate - amalgamate files single_include/nlohmann/json{,_fwd,_literals,_view}.hpp from the include/nlohmann sources"
|
||||||
@echo "BUILD.bazel - regenerate the Bazel BUILD file from the include/nlohmann sources"
|
@echo "BUILD.bazel - regenerate the Bazel BUILD file from the include/nlohmann sources"
|
||||||
|
@echo "ChangeLog.md - generate ChangeLog file"
|
||||||
@echo "check-amalgamation - check whether sources have been amalgamated and BUILD.bazel is up to date"
|
@echo "check-amalgamation - check whether sources have been amalgamated and BUILD.bazel is up to date"
|
||||||
@echo "check_build_options - check that the Meson build and the pkg-config files offer the options of the CMake target"
|
@echo "check_build_options - check that the Meson build and the pkg-config files offer the options of the CMake target"
|
||||||
@echo "clean - remove built files"
|
@echo "clean - remove built files"
|
||||||
@@ -174,6 +175,22 @@ check-amalgamation:
|
|||||||
BUILD.bazel:
|
BUILD.bazel:
|
||||||
cmake -P cmake/scripts/gen_bazel_build_file.cmake
|
cmake -P cmake/scripts/gen_bazel_build_file.cmake
|
||||||
|
|
||||||
|
##########################################################################
|
||||||
|
# ChangeLog
|
||||||
|
##########################################################################
|
||||||
|
|
||||||
|
# Create a ChangeLog based on the git log using the GitHub Changelog Generator
|
||||||
|
# (<https://github.com/github-changelog-generator/github-changelog-generator>).
|
||||||
|
|
||||||
|
# variable to control the diffs between the last released version and the current repository state
|
||||||
|
NEXT_VERSION ?= "unreleased"
|
||||||
|
|
||||||
|
ChangeLog.md:
|
||||||
|
github_changelog_generator -o ChangeLog.md --user nlohmann --project json --simple-list --release-url https://github.com/nlohmann/json/releases/tag/%s --future-release $(NEXT_VERSION)
|
||||||
|
$(SED) -i 's|https://github.com/nlohmann/json/releases/tag/HEAD|https://github.com/nlohmann/json/tree/HEAD|' ChangeLog.md
|
||||||
|
$(SED) -i '2i All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).' ChangeLog.md
|
||||||
|
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# Release files
|
# Release files
|
||||||
##########################################################################
|
##########################################################################
|
||||||
@@ -215,7 +232,7 @@ release: include.zip json.tar.xz
|
|||||||
|
|
||||||
# clean up
|
# clean up
|
||||||
clean:
|
clean:
|
||||||
rm -fr *.dSYM tests/*.dSYM tests/*_fuzzer
|
rm -fr *.dSYM tests/*.dSYM tests/parse_*_fuzzer
|
||||||
rm -fr cmake-build-benchmarks cmake-build-pvs-studio release_files
|
rm -fr cmake-build-benchmarks cmake-build-pvs-studio release_files
|
||||||
$(MAKE) clean -Cdocs
|
$(MAKE) clean -Cdocs
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
<a href="https://github.com/nlohmann/json/releases">
|
[](https://github.com/nlohmann/json/releases)
|
||||||
<picture>
|
|
||||||
<source media="(prefers-color-scheme: dark)" srcset="docs/mkdocs/docs/images/json-dark.svg">
|
|
||||||
<img src="docs/mkdocs/docs/images/json-light.svg" alt="JSON for Modern C++: animated feature slideshow">
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
[](https://ci.appveyor.com/project/nlohmann/json)
|
[](https://ci.appveyor.com/project/nlohmann/json)
|
||||||
[](https://github.com/nlohmann/json/actions?query=workflow%3AUbuntu)
|
[](https://github.com/nlohmann/json/actions?query=workflow%3AUbuntu)
|
||||||
@@ -44,7 +39,6 @@
|
|||||||
- [Conversions to/from arbitrary types](#arbitrary-types-conversions)
|
- [Conversions to/from arbitrary types](#arbitrary-types-conversions)
|
||||||
- [Specializing enum conversion](#specializing-enum-conversion)
|
- [Specializing enum conversion](#specializing-enum-conversion)
|
||||||
- [Binary formats (BSON, CBOR, MessagePack, UBJSON, BJData, and BON8)](#binary-formats-bson-cbor-messagepack-ubjson-bjdata-and-bon8)
|
- [Binary formats (BSON, CBOR, MessagePack, UBJSON, BJData, and BON8)](#binary-formats-bson-cbor-messagepack-ubjson-bjdata-and-bon8)
|
||||||
- [Zero-copy views](#zero-copy-views)
|
|
||||||
- [Customers](#customers)
|
- [Customers](#customers)
|
||||||
- [Ecosystem](#ecosystem)
|
- [Ecosystem](#ecosystem)
|
||||||
- [Supported compilers](#supported-compilers)
|
- [Supported compilers](#supported-compilers)
|
||||||
@@ -74,7 +68,7 @@ Other aspects were not so important to us:
|
|||||||
|
|
||||||
- **Memory efficiency**. Each JSON object has an overhead of one pointer (the maximal size of a union) and one enumeration element (1 byte). The default generalization uses the following C++ data types: `std::string` for strings, `int64_t`, `uint64_t` or `double` for numbers, `std::map` for objects, `std::vector` for arrays, and `bool` for Booleans. However, you can template the generalized class `basic_json` to your needs.
|
- **Memory efficiency**. Each JSON object has an overhead of one pointer (the maximal size of a union) and one enumeration element (1 byte). The default generalization uses the following C++ data types: `std::string` for strings, `int64_t`, `uint64_t` or `double` for numbers, `std::map` for objects, `std::vector` for arrays, and `bool` for Booleans. However, you can template the generalized class `basic_json` to your needs.
|
||||||
|
|
||||||
- **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. The [performance](https://json.nlohmann.me/features/performance/) page shows how to get the most out of the library.
|
- **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/develop/.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.
|
||||||
|
|
||||||
@@ -165,8 +159,7 @@ std::ifstream f("example.json");
|
|||||||
json data = json::parse(f);
|
json data = json::parse(f);
|
||||||
```
|
```
|
||||||
|
|
||||||
If using modules (enabled with `NLOHMANN_JSON_BUILD_MODULES`; `import std;` needs CMake 4.5 or newer, see the
|
If using modules (enabled with `NLOHMANN_JSON_BUILD_MODULES`), this example becomes:
|
||||||
[modules documentation](https://json.nlohmann.me/features/modules/)), this example becomes:
|
|
||||||
```cpp
|
```cpp
|
||||||
import std;
|
import std;
|
||||||
import nlohmann.json;
|
import nlohmann.json;
|
||||||
@@ -1059,7 +1052,7 @@ struct less_than_32_serializer {
|
|||||||
Be **very** careful when reimplementing your serializer, you can stack overflow if you don't pay attention:
|
Be **very** careful when reimplementing your serializer, you can stack overflow if you don't pay attention:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
template <typename T, typename = void>
|
template <typename T, void>
|
||||||
struct bad_serializer
|
struct bad_serializer
|
||||||
{
|
{
|
||||||
template <typename BasicJsonType>
|
template <typename BasicJsonType>
|
||||||
@@ -1070,10 +1063,10 @@ struct bad_serializer
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename BasicJsonType>
|
template <typename BasicJsonType>
|
||||||
static void from_json(const BasicJsonType& j, T& value) {
|
static void to_json(const BasicJsonType& j, T& value) {
|
||||||
// this calls BasicJsonType::json_serializer<T>::from_json(j, value)
|
// this calls BasicJsonType::json_serializer<T>::from_json(j, value)
|
||||||
// if BasicJsonType::json_serializer == bad_serializer ... oops!
|
// if BasicJsonType::json_serializer == bad_serializer ... oops!
|
||||||
value = j.template get<T>(); // oops!
|
value = j.get<T>(); // oops!
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
@@ -1776,7 +1769,7 @@ I deeply appreciate the help of the following people.
|
|||||||
330. [AniketDhemare](https://github.com/AniketDhemare) fixed a version in the documentation.
|
330. [AniketDhemare](https://github.com/AniketDhemare) fixed a version in the documentation.
|
||||||
331. [Philip Müller](https://github.com/philip-paul-mueller) fixed an example.
|
331. [Philip Müller](https://github.com/philip-paul-mueller) fixed an example.
|
||||||
332. [Leila Shcheglova](https://github.com/LeilaShcheglova) fixed a warning in a test.
|
332. [Leila Shcheglova](https://github.com/LeilaShcheglova) fixed a warning in a test.
|
||||||
333. [Alex Prabhat Bara](https://github.com/alexprabhat99) fixed a function name in the documentation and avoided temporary `basic_json` values for CBOR and MessagePack object keys.
|
333. [Alex Prabhat Bara](https://github.com/alexprabhat99) fixed a function name in the documentation.
|
||||||
334. [laterlaugh](https://github.com/laterlaugh) fixed some typos.
|
334. [laterlaugh](https://github.com/laterlaugh) fixed some typos.
|
||||||
335. [Yuanhao Jia](https://github.com/MrJia1997) fixed the GDB pretty printer.
|
335. [Yuanhao Jia](https://github.com/MrJia1997) fixed the GDB pretty printer.
|
||||||
336. [Fallen_Breath](https://github.com/Fallen-Breath) fixed an example for JSON Pointer.
|
336. [Fallen_Breath](https://github.com/Fallen-Breath) fixed an example for JSON Pointer.
|
||||||
@@ -1854,7 +1847,7 @@ I deeply appreciate the help of the following people.
|
|||||||
408. [Luke Banicevic](https://github.com/banaboi) fixed corrupt BSON output for lengths exceeding `INT32_MAX`, cleaned up the BSON writer, and improved the documentation.
|
408. [Luke Banicevic](https://github.com/banaboi) fixed corrupt BSON output for lengths exceeding `INT32_MAX`, cleaned up the BSON writer, and improved the documentation.
|
||||||
409. [Patrick Armstrong](https://github.com/Patrick10199) updated the CBOR references and the half-precision float assertions.
|
409. [Patrick Armstrong](https://github.com/Patrick10199) updated the CBOR references and the half-precision float assertions.
|
||||||
410. [Yash Bavadiya](https://github.com/xevrion) added checks to all BSON reads.
|
410. [Yash Bavadiya](https://github.com/xevrion) added checks to all BSON reads.
|
||||||
411. [hum4nBeing](https://github.com/hum4nBeing) and [AJ369ninja](https://github.com/AJ369ninja) fixed the overflow handling of high-precision numbers in UBJSON.
|
411. [hum4nBeing](https://github.com/hum4nBeing) fixed the overflow handling of high-precision numbers in UBJSON.
|
||||||
412. [tomatotomata](https://github.com/tomatotomata) added checks for reading CBOR tagged subtypes.
|
412. [tomatotomata](https://github.com/tomatotomata) added checks for reading CBOR tagged subtypes.
|
||||||
413. [YingqiDuan](https://github.com/YingqiDuan) documented the BSON interoperability.
|
413. [YingqiDuan](https://github.com/YingqiDuan) documented the BSON interoperability.
|
||||||
414. [KBS](https://github.com/youdie006) documented the standards compliance and the strictness of `parse()` and `operator>>`.
|
414. [KBS](https://github.com/youdie006) documented the standards compliance and the strictness of `parse()` and `operator>>`.
|
||||||
@@ -1868,26 +1861,6 @@ I deeply appreciate the help of the following people.
|
|||||||
422. [Avionic Harshit](https://github.com/avionicharshit-byte) made `diff()` linear when an array shrinks.
|
422. [Avionic Harshit](https://github.com/avionicharshit-byte) made `diff()` linear when an array shrinks.
|
||||||
423. [Qatadaha Bin Matloob](https://github.com/qatcod) fixed comparisons between integers and floats and fixed unparsable BJData output.
|
423. [Qatadaha Bin Matloob](https://github.com/qatcod) fixed comparisons between integers and floats and fixed unparsable BJData output.
|
||||||
424. [Wu Shuwen](https://github.com/dajiaohuang) removed an unused include.
|
424. [Wu Shuwen](https://github.com/dajiaohuang) removed an unused include.
|
||||||
425. [Alexander Lanin](https://github.com/AlexanderLanin) improved the error message of `get_to()` for `const` arguments.
|
|
||||||
426. [satelliteprogrammer](https://github.com/satelliteprogrammer) added `merge_diff()` to create JSON Merge Patches (RFC 7396).
|
|
||||||
427. [Jeremy Nimmer](https://github.com/jwnimmer-tri) removed `alwayslink` from the Bazel build.
|
|
||||||
428. [Dadi Reddy Sai Praneeth Reddy](https://github.com/dsp0redy) made `to_msgpack()` throw when a size exceeds the MessagePack limit.
|
|
||||||
429. [ayush-singh-0601](https://github.com/ayush-singh-0601) reduced the runtime of the test suite.
|
|
||||||
430. [Kartikey Negi](https://github.com/ReturnKartikey) fixed the CBOR tag handling of tagged values that are not byte strings.
|
|
||||||
431. [Michiel van Slobbe](https://github.com/mvanslobbe) sped up the parser by checking for the expected separator first.
|
|
||||||
432. [Mohd Quamar Tyagi](https://github.com/Tyagiquamar) allowed SAX parsing of tagged CBOR.
|
|
||||||
433. [fhgffy](https://github.com/fhgffy) rejected NUL bytes in UBJSON and BJData high-precision numbers and fixed a `-Wswitch-enum` warning.
|
|
||||||
434. [Suyog Verma](https://github.com/commit-msuyog) used MSVC intrinsics for the 128-bit multiplication in the floating-point serialization.
|
|
||||||
435. [Bas van Dijk](https://github.com/basdedas) fixed a TU-local exposure of `UTF8_ACCEPT` and `UTF8_REJECT` in C++20 modules.
|
|
||||||
436. [Christoph Grüninger](https://github.com/gruenich) fixed a leak and a crash when an allocation throws during parsing.
|
|
||||||
437. [Amelia Barnaby](https://github.com/ameliabarnabyhub) made serializing discarded values to binary formats throw instead of writing corrupt output.
|
|
||||||
438. [Vesko Karaganev](https://github.com/veselink1) made the destructor use the provided allocator.
|
|
||||||
439. [Michael Sam](https://github.com/michaelsam94) kept allocation failures from escaping the `noexcept` destructor.
|
|
||||||
440. [Mihnea Magheru](https://github.com/sakuntalle) added a natvis visualizer for `detail::json_default_base`.
|
|
||||||
441. [Joseph Demarest](https://github.com/JosephDemarest) rejected nested indefinite-length CBOR strings.
|
|
||||||
442. [Afonso Januário](https://github.com/afonsojanu) made `std::hash<basic_json>` consistent with `operator==` for numbers.
|
|
||||||
443. [Kartik Gupta](https://github.com/KartikeyG-world) limited the natvis namespace variants to two ABI tags.
|
|
||||||
444. [manop55555](https://github.com/manop55555) reported a buffer over-read in `dump()` with large indentation values.
|
|
||||||
|
|
||||||
Thanks a lot for helping out! Please [let me know](mailto:mail@nlohmann.me) if I forgot someone.
|
Thanks a lot for helping out! Please [let me know](mailto:mail@nlohmann.me) if I forgot someone.
|
||||||
|
|
||||||
@@ -1910,6 +1883,7 @@ The library itself consists of a single header file licensed under the MIT licen
|
|||||||
- [**cpplint**](https://github.com/cpplint/cpplint) for style checks
|
- [**cpplint**](https://github.com/cpplint/cpplint) for style checks
|
||||||
- [**doctest**](https://github.com/doctest/doctest) for the unit tests
|
- [**doctest**](https://github.com/doctest/doctest) for the unit tests
|
||||||
- [**Flawfinder**](https://dwheeler.com/flawfinder/) for static analysis
|
- [**Flawfinder**](https://dwheeler.com/flawfinder/) for static analysis
|
||||||
|
- [**GitHub Changelog Generator**](https://github.com/github-changelog-generator/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
|
||||||
- [**Hedley**](https://nemequ.github.io/hedley/) to avoid re-inventing several compiler-agnostic feature macros
|
- [**Hedley**](https://nemequ.github.io/hedley/) to avoid re-inventing several compiler-agnostic feature macros
|
||||||
- [**include-what-you-use**](https://include-what-you-use.org) to check the included headers
|
- [**include-what-you-use**](https://include-what-you-use.org) to check the included headers
|
||||||
@@ -1976,7 +1950,7 @@ For more information, see [JSON With Commas and Comments (JWCC)](https://nigelta
|
|||||||
|
|
||||||
By default, the library does not preserve the **insertion order of object elements**. This is standards-compliant, as the [JSON standard](https://tools.ietf.org/html/rfc8259.html) defines objects as "an unordered collection of zero or more name/value pairs".
|
By default, the library does not preserve the **insertion order of object elements**. This is standards-compliant, as the [JSON standard](https://tools.ietf.org/html/rfc8259.html) defines objects as "an unordered collection of zero or more name/value pairs".
|
||||||
|
|
||||||
If you do want to preserve the insertion order, you can try the type [`nlohmann::ordered_json`](https://json.nlohmann.me/api/ordered_json/). Alternatively, you can use a more sophisticated ordered map like [`tsl::ordered_map`](https://github.com/Tessil/ordered-map) ([integration](https://github.com/nlohmann/json/issues/546#issuecomment-304447518)) or [`nlohmann::fifo_map`](https://github.com/nlohmann/fifo_map) ([integration](https://github.com/nlohmann/json/issues/485#issuecomment-333652309)).
|
If you do want to preserve the insertion order, you can try the type [`nlohmann::ordered_json`](https://github.com/nlohmann/json/issues/2179). Alternatively, you can use a more sophisticated ordered map like [`tsl::ordered_map`](https://github.com/Tessil/ordered-map) ([integration](https://github.com/nlohmann/json/issues/546#issuecomment-304447518)) or [`nlohmann::fifo_map`](https://github.com/nlohmann/fifo_map) ([integration](https://github.com/nlohmann/json/issues/485#issuecomment-333652309)).
|
||||||
|
|
||||||
See the [**documentation on object order**](https://json.nlohmann.me/features/object_order/) for more information.
|
See the [**documentation on object order**](https://json.nlohmann.me/features/object_order/) for more information.
|
||||||
|
|
||||||
|
|||||||
+77
-21
@@ -342,27 +342,6 @@ add_custom_target(ci_test_no_thread_local
|
|||||||
COMMENT "Compile and test without thread-local storage"
|
COMMENT "Compile and test without thread-local storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
# Change the number of levels the walks over a value recurse into.
|
|
||||||
###############################################################################
|
|
||||||
|
|
||||||
# JSON_RECURSION_DEPTH_LIMIT is 128 by default, which is what the whole test
|
|
||||||
# suite otherwise runs with. 0 sends every walk to its explicit stack at once,
|
|
||||||
# so this target runs the whole suite through the walks that the default only
|
|
||||||
# uses for values nested more deeply than 128 levels: results must not depend on
|
|
||||||
# the limit. The largest limit, 254, is covered by a build of
|
|
||||||
# tests/src/unit-recursion_depth_limit.cpp (see tests/CMakeLists.txt).
|
|
||||||
add_custom_target(ci_test_recursion_depth_limit_0
|
|
||||||
COMMAND ${CMAKE_COMMAND}
|
|
||||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
|
||||||
-DJSON_BuildTests=ON -DJSON_FastTests=ON
|
|
||||||
-DCMAKE_CXX_FLAGS=-DJSON_RECURSION_DEPTH_LIMIT=0
|
|
||||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_recursion_depth_limit_0
|
|
||||||
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_recursion_depth_limit_0
|
|
||||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_recursion_depth_limit_0 && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
|
|
||||||
COMMENT "Compile and test with JSON_RECURSION_DEPTH_LIMIT=0"
|
|
||||||
)
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Coverage.
|
# Coverage.
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@@ -406,6 +385,61 @@ add_custom_target(ci_test_clang_sanitizer
|
|||||||
COMMENT "Compile and test with sanitizers"
|
COMMENT "Compile and test with sanitizers"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Check if header is amalgamated and sources are properly indented.
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
# Same file set as .github/workflows/check_amalgamation.yml, so this CMake target (which can be run locally) is held
|
||||||
|
# to the same standard as the workflow (which runs for pull requests and for pushes to develop/master/release/*).
|
||||||
|
file(GLOB_RECURSE INDENT_FILES
|
||||||
|
${PROJECT_SOURCE_DIR}/docs/mkdocs/docs/examples/*.hpp
|
||||||
|
${PROJECT_SOURCE_DIR}/docs/mkdocs/docs/examples/*.cpp
|
||||||
|
${PROJECT_SOURCE_DIR}/docs/mkdocs/docs/examples/*.cu
|
||||||
|
${PROJECT_SOURCE_DIR}/include/*.hpp
|
||||||
|
${PROJECT_SOURCE_DIR}/include/*.cpp
|
||||||
|
${PROJECT_SOURCE_DIR}/include/*.cu
|
||||||
|
${PROJECT_SOURCE_DIR}/tests/*.hpp
|
||||||
|
${PROJECT_SOURCE_DIR}/tests/*.cpp
|
||||||
|
${PROJECT_SOURCE_DIR}/tests/*.cu
|
||||||
|
)
|
||||||
|
list(FILTER INDENT_FILES EXCLUDE REGEX "/tests/thirdparty/|/tests/abi/include/nlohmann/")
|
||||||
|
|
||||||
|
set(include_dir ${PROJECT_SOURCE_DIR}/single_include/nlohmann)
|
||||||
|
set(tool_dir ${PROJECT_SOURCE_DIR}/tools/amalgamate)
|
||||||
|
add_custom_target(ci_test_amalgamation
|
||||||
|
COMMAND rm -fr ${include_dir}/json.hpp~ ${include_dir}/json_fwd.hpp~ ${include_dir}/json_literals.hpp~ ${include_dir}/json_view.hpp~
|
||||||
|
COMMAND cp ${include_dir}/json.hpp ${include_dir}/json.hpp~
|
||||||
|
COMMAND cp ${include_dir}/json_fwd.hpp ${include_dir}/json_fwd.hpp~
|
||||||
|
COMMAND cp ${include_dir}/json_literals.hpp ${include_dir}/json_literals.hpp~
|
||||||
|
COMMAND cp ${include_dir}/json_view.hpp ${include_dir}/json_view.hpp~
|
||||||
|
COMMAND cp ${PROJECT_SOURCE_DIR}/BUILD.bazel ${PROJECT_SOURCE_DIR}/BUILD.bazel~
|
||||||
|
|
||||||
|
COMMAND ${Python3_EXECUTABLE} -mvenv venv_astyle
|
||||||
|
COMMAND venv_astyle/bin/pip3 --quiet install -r ${CMAKE_SOURCE_DIR}/tools/astyle/requirements.txt
|
||||||
|
COMMAND venv_astyle/bin/astyle --version
|
||||||
|
|
||||||
|
COMMAND ${Python3_EXECUTABLE} ${tool_dir}/amalgamate.py -c ${tool_dir}/config_json.json -s .
|
||||||
|
COMMAND ${Python3_EXECUTABLE} ${tool_dir}/amalgamate.py -c ${tool_dir}/config_json_fwd.json -s .
|
||||||
|
COMMAND cp ${PROJECT_SOURCE_DIR}/include/nlohmann/json_literals.hpp ${include_dir}/json_literals.hpp
|
||||||
|
COMMAND ${Python3_EXECUTABLE} ${tool_dir}/amalgamate.py -c ${tool_dir}/config_json_view.json -s .
|
||||||
|
COMMAND venv_astyle/bin/astyle --project=tools/astyle/.astylerc --suffix=none ${include_dir}/json.hpp ${include_dir}/json_fwd.hpp ${include_dir}/json_literals.hpp ${include_dir}/json_view.hpp
|
||||||
|
COMMAND ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/cmake/scripts/gen_bazel_build_file.cmake
|
||||||
|
|
||||||
|
COMMAND diff ${include_dir}/json.hpp~ ${include_dir}/json.hpp
|
||||||
|
COMMAND diff ${include_dir}/json_fwd.hpp~ ${include_dir}/json_fwd.hpp
|
||||||
|
COMMAND diff ${include_dir}/json_literals.hpp~ ${include_dir}/json_literals.hpp
|
||||||
|
COMMAND diff ${include_dir}/json_view.hpp~ ${include_dir}/json_view.hpp
|
||||||
|
COMMAND diff ${PROJECT_SOURCE_DIR}/BUILD.bazel~ ${PROJECT_SOURCE_DIR}/BUILD.bazel
|
||||||
|
|
||||||
|
COMMAND venv_astyle/bin/astyle --project=tools/astyle/.astylerc --suffix=orig ${INDENT_FILES}
|
||||||
|
COMMAND for FILE in `find . -name '*.orig'`\; do false \; done
|
||||||
|
|
||||||
|
COMMAND rm -f ${include_dir}/json.hpp~ ${include_dir}/json_fwd.hpp~ ${include_dir}/json_literals.hpp~ ${include_dir}/json_view.hpp~ ${PROJECT_SOURCE_DIR}/BUILD.bazel~
|
||||||
|
|
||||||
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||||
|
COMMENT "Check amalgamation, formatting, and BUILD.bazel"
|
||||||
|
)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Build and test using the amalgamated header
|
# Build and test using the amalgamated header
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@@ -637,6 +671,19 @@ else()
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Benchmarks
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
add_custom_target(ci_benchmarks
|
||||||
|
COMMAND ${CMAKE_COMMAND}
|
||||||
|
-DCMAKE_BUILD_TYPE=Release -GNinja
|
||||||
|
-S${PROJECT_SOURCE_DIR}/tests/benchmarks -B${PROJECT_BINARY_DIR}/build_benchmarks
|
||||||
|
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_benchmarks --target json_benchmarks
|
||||||
|
COMMAND cd ${PROJECT_BINARY_DIR}/build_benchmarks && ./json_benchmarks
|
||||||
|
COMMENT "Run benchmarks"
|
||||||
|
)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# CMake flags
|
# CMake flags
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@@ -897,3 +944,12 @@ add_custom_target(ci_test_documentation_mermaid
|
|||||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/docs/mkdocs
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/docs/mkdocs
|
||||||
COMMENT "Check the Mermaid diagrams of the documentation"
|
COMMENT "Check the Mermaid diagrams of the documentation"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Clean up all generated files.
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
add_custom_target(ci_clean
|
||||||
|
COMMAND rm -fr ${PROJECT_BINARY_DIR}/build_* ${PROJECT_BINARY_DIR}/cmake-3.5.0 ${PROJECT_BINARY_DIR}/cmake-3.31.6 ${PROJECT_BINARY_DIR}/cmake-4.0.0 ${JSON_CMAKE_FLAG_BUILD_DIRS} ${single_binaries}
|
||||||
|
COMMENT "Clean generated directories"
|
||||||
|
)
|
||||||
@@ -9,11 +9,6 @@
|
|||||||
# __n2)`, which stores `__n1 - __n2` in a signed difference_type and clamps it to int. Any comparison with a shorter
|
# __n2)`, which stores `__n1 - __n2` in a signed difference_type and clamps it to int. Any comparison with a shorter
|
||||||
# view wraps that subtraction on purpose, and -fsanitize=integer reports it as implicit-integer-sign-change. json_view
|
# view wraps that subtraction on purpose, and -fsanitize=integer reports it as implicit-integer-sign-change. json_view
|
||||||
# compares keys as string views, so the same check is excluded for <string_view> as well.
|
# compares keys as string views, so the same check is excluded for <string_view> as well.
|
||||||
# std::filesystem::path::u8string() in libstdc++ 14 builds a std::u8string from the native char sequence, so
|
|
||||||
# basic_string's range copy (_S_copy_chars) converts every char >= 0x80 to char8_t, which -fsanitize=integer reports as
|
|
||||||
# implicit-integer-sign-change (test-conversions2_cpp20/cpp23, non-ASCII path). The conversion is intended and happens
|
|
||||||
# inside the standard library, not in this library.
|
|
||||||
[implicit-integer-sign-change]
|
[implicit-integer-sign-change]
|
||||||
src:*/include/c++/*/format
|
src:*/include/c++/*/format
|
||||||
src:*/include/c++/*/string_view
|
src:*/include/c++/*/string_view
|
||||||
src:*/include/c++/*/bits/basic_string.h
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
meson==1.12.1 \
|
|
||||||
--hash=sha256:930bc7542cbd9f57009e182fd014eba48cf1a0180a7b9006d2d32d8f168d8b02 \
|
|
||||||
--hash=sha256:ab0a6ca09f8ef70c564c8241fb5a23957886a0b53fb58412b5e07eaf07dba743
|
|
||||||
@@ -1 +1 @@
|
|||||||
reuse==6.3.0
|
reuse==6.2.0
|
||||||
@@ -1 +0,0 @@
|
|||||||
semgrep==1.184.0
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.6 MiB |
@@ -67,11 +67,7 @@ basic_json(basic_json&& other) noexcept;
|
|||||||
- **objects**: [`object_t`](object_t.md) and all kinds of compatible associative containers such as `std::map`,
|
- **objects**: [`object_t`](object_t.md) and all kinds of compatible associative containers such as `std::map`,
|
||||||
`std::unordered_map`, `std::multimap`, and `std::unordered_multimap` with a `key_type` compatible to `string_t`
|
`std::unordered_map`, `std::multimap`, and `std::unordered_multimap` with a `key_type` compatible to `string_t`
|
||||||
and a `value_type` from which a `basic_json` value can be constructed.
|
and a `value_type` from which a `basic_json` value can be constructed.
|
||||||
- **strings**: `string_t`, string literals, and all compatible string containers can be used. Since version 3.13.0,
|
- **strings**: `string_t`, string literals, and all compatible string containers can be used.
|
||||||
this includes `#!cpp std::u8string` (C++20): its code units are stored as a JSON string and
|
|
||||||
[`get<std::u8string>()`](get.md) reads it back (in version 3.12.0, a `#!cpp std::u8string` was stored as an array
|
|
||||||
of numbers; `get<std::u8string>()` still accepts such an array). `#!cpp std::u8string_view` and `#!cpp char8_t`
|
|
||||||
arrays are not strings; they are stored as arrays of code units.
|
|
||||||
|
|
||||||
!!! note "Rvalue containers are moved from"
|
!!! note "Rvalue containers are moved from"
|
||||||
|
|
||||||
@@ -97,18 +93,10 @@ basic_json(basic_json&& other) noexcept;
|
|||||||
The constructor tries to convert the internal `m_value` of the parameter. Each member value (object, array, string,
|
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
|
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
|
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 result
|
*source* type's corresponding member type via `is_constructible`. If this requirement is not met, the conversion
|
||||||
depends on the *source* string type:
|
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
|
||||||
- If it is a range of characters (it has `begin()` and `end()`, as `std::string` does), the conversion falls back to
|
[issue #3425](https://github.com/nlohmann/json/issues/3425).
|
||||||
the array-conversion path, which represents objects as arrays of `[key, value]` pairs and strings as arrays of
|
|
||||||
character codes. This result has a different type than the source value, so the constructor's
|
|
||||||
[`JSON_ASSERT`](../macros/json_assert.md) fails; with its default definition, `assert`, the program aborts unless
|
|
||||||
`NDEBUG` is defined, in which case the array is returned.
|
|
||||||
- Otherwise, the conversion does not compile, even though `#!cpp std::is_constructible` reports `#!cpp true`; for
|
|
||||||
example, when converting a `basic_json` whose `string_t` is the `alt_string` of the unit tests to `json`.
|
|
||||||
|
|
||||||
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`
|
||||||
|
|||||||
@@ -58,9 +58,7 @@ is not UTF-8 encoded and `error_handler` is set to `strict`
|
|||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
Linear in the size of the result. With an `indent`, every line starts with up to `indent` characters per nesting level,
|
Linear.
|
||||||
so the result can be larger than the value by a factor of its nesting depth (see
|
|
||||||
[Parsing untrusted input](../../features/parsing/untrusted_input.md#nesting-depth)).
|
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,7 @@ Strong exception safety: if an exception occurs, the original value stays intact
|
|||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
Linear in the size of the result. Every key repeats the path of its value, so the keys can be larger than the value by a
|
Linear in the size of the JSON value.
|
||||||
factor of its nesting depth (see [Parsing untrusted input](../../features/parsing/untrusted_input.md#nesting-depth)).
|
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
|
|||||||
@@ -69,10 +69,8 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
|
|||||||
|
|
||||||
## Exceptions
|
## Exceptions
|
||||||
|
|
||||||
- Throws [parse_error.110](../../home/exceptions.md#jsonexceptionparse_error110) if the given input ends prematurely,
|
- Throws [parse_error.110](../../home/exceptions.md#jsonexceptionparse_error110) if the given input ends prematurely or
|
||||||
if the end of the file was not reached when `strict` was set to true, or if a string at the end of the value is not
|
the end of the file was not reached when `strict` was set to true
|
||||||
terminated by 0xFF although a byte follows it (also when `strict` is false: the byte that ends the string is
|
|
||||||
taken from the input, so the next value would be lost)
|
|
||||||
- Throws [parse_error.112](../../home/exceptions.md#jsonexceptionparse_error112) if a parse error occurs, for instance
|
- Throws [parse_error.112](../../home/exceptions.md#jsonexceptionparse_error112) if a parse error occurs, for instance
|
||||||
an invalid byte, a string that is not valid UTF-8, or an object key that is not a string
|
an invalid byte, a string that is not valid UTF-8, or an object key that is not a string
|
||||||
|
|
||||||
|
|||||||
@@ -89,11 +89,8 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
|
|||||||
- Throws [out_of_range.406](../../home/exceptions.md#jsonexceptionout_of_range406) if a high-precision number, or a
|
- Throws [out_of_range.406](../../home/exceptions.md#jsonexceptionout_of_range406) if a high-precision number, or a
|
||||||
float64 when `number_float_t` is `float`, does not fit into `number_float_t`
|
float64 when `number_float_t` is `float`, does not fit into `number_float_t`
|
||||||
- Throws [out_of_range.408](../../home/exceptions.md#jsonexceptionout_of_range408) if the count of an optimized
|
- Throws [out_of_range.408](../../home/exceptions.md#jsonexceptionout_of_range408) if the count of an optimized
|
||||||
container exceeds the capacity of the container (or of `std::size_t`; an array of type `N` is empty, so only the
|
container exceeds the capacity of the container (or of `std::size_t`), or if an optimized array of `Z`, `T`, or `F` has
|
||||||
latter applies to it), if an optimized array of `Z`, `T`, or `F` has more than 1,048,576 elements, or if the
|
more than 1,048,576 elements
|
||||||
optimized arrays of `Z`, `T`, and `F` in the input together have more than 1,048,576 elements plus
|
|
||||||
[`JSON_UBJSON_VALUELESS_ELEMENTS_PER_BYTE`](../macros/json_ubjson_valueless_elements_per_byte.md) (4 by default) for
|
|
||||||
every byte read so far
|
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
@@ -122,8 +119,6 @@ Linear in the size of the input.
|
|||||||
- [Parsing untrusted input](../../features/parsing/untrusted_input.md) - limits and safe handling of hostile data
|
- [Parsing untrusted input](../../features/parsing/untrusted_input.md) - limits and safe handling of hostile data
|
||||||
- [Binary values](../../features/binary_values.md) - how binary values and subtypes are handled
|
- [Binary values](../../features/binary_values.md) - how binary values and subtypes are handled
|
||||||
- [`to_ubjson`](to_ubjson.md) - create a UBJSON serialization of a JSON value
|
- [`to_ubjson`](to_ubjson.md) - create a UBJSON serialization of a JSON value
|
||||||
- [`JSON_UBJSON_VALUELESS_ELEMENTS_PER_BYTE`](../macros/json_ubjson_valueless_elements_per_byte.md) -
|
|
||||||
set how many elements of arrays of `null`, `true`, or `false` the input may announce per byte
|
|
||||||
- [`from_cbor`](from_cbor.md) - create a JSON value from an input in CBOR format
|
- [`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_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_bson`](from_bson.md) - create a JSON value from an input in BSON format
|
||||||
@@ -137,12 +132,6 @@ Linear in the size of the input.
|
|||||||
- 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 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.
|
- Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0.
|
||||||
- Added `error_handler` parameter in version 3.13.0.
|
- Added `error_handler` parameter in version 3.13.0.
|
||||||
- Report `start_array(0)` to a SAX handler for an optimized array of type `N` (`[$N#n`), whatever its count, in version
|
|
||||||
3.13.0.
|
|
||||||
- Limited the total number of elements of optimized arrays of `Z`, `T`, and `F` in one input in version 3.13.0; the
|
|
||||||
number of elements per byte can be set with
|
|
||||||
[`JSON_UBJSON_VALUELESS_ELEMENTS_PER_BYTE`](../macros/json_ubjson_valueless_elements_per_byte.md), for example to read
|
|
||||||
files written by version 3.12.0 and earlier that exceed the default.
|
|
||||||
|
|
||||||
!!! warning "Deprecation"
|
!!! warning "Deprecation"
|
||||||
|
|
||||||
|
|||||||
@@ -130,12 +130,6 @@ overload (3).
|
|||||||
`#!cpp json(true).get<double>()` throw. This is the behavior of all 3.x versions;
|
`#!cpp json(true).get<double>()` throw. This is the behavior of all 3.x versions;
|
||||||
[`basic_json_view::get<T>()`](../basic_json_view/get.md) behaves the same.
|
[`basic_json_view::get<T>()`](../basic_json_view/get.md) behaves the same.
|
||||||
|
|
||||||
!!! note "`std::u8string` conversions"
|
|
||||||
|
|
||||||
Since version 3.13.0, `#!cpp get<std::u8string>()` (C++20) reads a JSON string; it also accepts an array of numbers,
|
|
||||||
the form in which version 3.12.0 stored a `#!cpp std::u8string`. Any other JSON type throws
|
|
||||||
[`type_error.302`](../../home/exceptions.md#jsonexceptiontype_error302) ("type must be string or array").
|
|
||||||
|
|
||||||
!!! note "`std::optional` conversions"
|
!!! note "`std::optional` conversions"
|
||||||
|
|
||||||
Prior to version 3.13.0, `#!cpp get<std::optional<T>>()` (and other conversions to `std::optional<T>`) failed to
|
Prior to version 3.13.0, `#!cpp get<std::optional<T>>()` (and other conversions to `std::optional<T>`) failed to
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ Besides `basic_json`, the library offers a second way to hold a parsed JSON text
|
|||||||
[`basic_json_document`](../basic_json_document/index.md), which owns or borrows the text and holds a flat index of the
|
[`basic_json_document`](../basic_json_document/index.md), which owns or borrows the text and holds a flat index of the
|
||||||
values in it, and a [`basic_json_view`](../basic_json_view/index.md), a read-only handle to one value of such a document.
|
values in it, and a [`basic_json_view`](../basic_json_view/index.md), a read-only handle to one value of such a document.
|
||||||
Both are defined in the header `<nlohmann/json_view.hpp>`; see
|
Both are defined in the header `<nlohmann/json_view.hpp>`; see
|
||||||
[Zero-copy JSON views](../../features/json_view/index.md) for the concept and the trade-offs.
|
[Zero-copy JSON views](../../features/json_view.md) for the concept and the trade-offs.
|
||||||
|
|
||||||
- [**json_document**](../json_document.md) / [**ordered_json_document**](../ordered_json_document.md) - read-only
|
- [**json_document**](../json_document.md) / [**ordered_json_document**](../ordered_json_document.md) - read-only
|
||||||
documents of the `basic_json` specialization they belong to
|
documents of the `basic_json` specialization they belong to
|
||||||
@@ -363,7 +363,7 @@ Access to the JSON value
|
|||||||
specification of the JSON data interchange format
|
specification of the JSON data interchange format
|
||||||
- [`basic_json_document`](../basic_json_document/index.md) - / [`basic_json_view`](../basic_json_view/index.md) - parse a JSON
|
- [`basic_json_document`](../basic_json_document/index.md) - / [`basic_json_view`](../basic_json_view/index.md) - parse a JSON
|
||||||
text into a flat index and read it through a view
|
text into a flat index and read it through a view
|
||||||
- [Zero-copy JSON views](../../features/json_view/index.md) - when to use a document and a view instead of a `basic_json`
|
- [Zero-copy JSON views](../../features/json_view.md) - when to use a document and a view instead of a `basic_json`
|
||||||
- [Types](../../features/types/index.md) - how JSON values are stored and which types exist
|
- [Types](../../features/types/index.md) - how JSON values are stored and which types exist
|
||||||
- [Converting values](../../features/conversions.md) - get values out of a JSON value and put values in
|
- [Converting values](../../features/conversions.md) - get values out of a JSON value and put values in
|
||||||
- [Creating JSON values](../../features/creating_values.md) - all the ways to build a JSON value
|
- [Creating JSON values](../../features/creating_values.md) - all the ways to build a JSON value
|
||||||
|
|||||||
@@ -102,12 +102,9 @@ objects.
|
|||||||
|
|
||||||
When converting an object from one `basic_json` specialization to another via the
|
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
|
[converting constructor](basic_json.md) (overload 4), the target `object_t`'s `key_type` must be
|
||||||
directly constructible from the source object's key type (with the default `std::map`, the source `basic_json`'s
|
directly constructible from the source `basic_json`'s `string_t` type (or more generally, from the
|
||||||
`string_t`). If this requirement is not met and the source string type is a range of characters, the
|
source object's key type). If this requirement is not met, the conversion does not fail; instead,
|
||||||
object is converted as an array of key-value pairs, which is incorrect: the converting constructor's
|
the object is silently converted as an array of key-value pairs, which is incorrect. See
|
||||||
[`JSON_ASSERT`](../macros/json_assert.md) fails; with its default definition, `assert`, the program aborts unless
|
|
||||||
`NDEBUG` is defined, in which case the array is returned. If the source string type is not a range of characters, the
|
|
||||||
conversion does not compile at all. See [`basic_json`](basic_json.md) and
|
|
||||||
[issue #3425](https://github.com/nlohmann/json/issues/3425) for details and an example.
|
[issue #3425](https://github.com/nlohmann/json/issues/3425) for details and an example.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|||||||
@@ -27,16 +27,6 @@ reference operator+=(initializer_list_t init);
|
|||||||
`init` is converted into an object element and added using `operator+=(const typename object_t::value_type&)`.
|
`init` is converted into an object element and added using `operator+=(const typename object_t::value_type&)`.
|
||||||
Otherwise, `init` is converted to a JSON value and added using `operator+=(basic_json&&)`.
|
Otherwise, `init` is converted to a JSON value and added using `operator+=(basic_json&&)`.
|
||||||
|
|
||||||
!!! note "Single braced JSON value"
|
|
||||||
|
|
||||||
For a call such as `#!cpp arr += {obj}`, where the initializer list contains a single JSON value `obj`,
|
|
||||||
compilers may disagree unless
|
|
||||||
[`JSON_BRACE_INIT_COPY_SEMANTICS`](../macros/json_brace_init_copy_semantics.md) is defined to `1`: GCC, for
|
|
||||||
example, selects this overload and appends a single-element array `[obj]`, whereas Clang selects the
|
|
||||||
`basic_json` overload and appends a copy of `obj`. With the macro, GCC and Clang both append a copy of `obj`.
|
|
||||||
To get a portable result without the macro, write `#!cpp arr += obj` to append a copy, or
|
|
||||||
`#!cpp arr += json::array({obj})` to append a single-element array.
|
|
||||||
|
|
||||||
## Iterator invalidation
|
## Iterator invalidation
|
||||||
|
|
||||||
For all cases where an element is added to an **array**, a reallocation can happen, in which case all iterators (including
|
For all cases where an element is added to an **array**, a reallocation can happen, in which case all iterators (including
|
||||||
|
|||||||
@@ -60,14 +60,6 @@ Linear.
|
|||||||
2. Comparing a `NaN` with another `NaN`.
|
2. Comparing a `NaN` with another `NaN`.
|
||||||
3. Comparing a `NaN` and any other number.
|
3. Comparing a `NaN` and any other number.
|
||||||
|
|
||||||
For arrays and objects, the elements are compared in order. If the comparison reaches a `NaN` and a number (or
|
|
||||||
another `NaN`) before any other difference, the result depends on the language standard. Before C++20, the pair
|
|
||||||
counts as equivalent and the following elements (or the sizes) decide: for instance, `[NaN] < [1, NaN]` and
|
|
||||||
`[1] <= [NaN]` are `#!cpp true`. Since C++20, the whole comparison is unordered, and `<`, `<=`, `>`, and `>=` all
|
|
||||||
yield `#!cpp false`. Otherwise (for example `[1, NaN] < [2, NaN]`, or objects whose keys differ), the result is the
|
|
||||||
same for all language standards. The same program can therefore order such values differently when it is compiled
|
|
||||||
with a different language standard.
|
|
||||||
|
|
||||||
!!! note "Operator overload resolution"
|
!!! note "Operator overload resolution"
|
||||||
|
|
||||||
Since C++20 overload resolution will consider the _rewritten candidate_ generated from
|
Since C++20 overload resolution will consider the _rewritten candidate_ generated from
|
||||||
|
|||||||
@@ -60,14 +60,6 @@ Linear.
|
|||||||
2. Comparing a `NaN` with another `NaN`.
|
2. Comparing a `NaN` with another `NaN`.
|
||||||
3. Comparing a `NaN` and any other number.
|
3. Comparing a `NaN` and any other number.
|
||||||
|
|
||||||
For arrays and objects, the elements are compared in order. If the comparison reaches a `NaN` and a number (or
|
|
||||||
another `NaN`) before any other difference, the result depends on the language standard. Before C++20, the pair
|
|
||||||
counts as equivalent and the following elements (or the sizes) decide: for instance, `[NaN] < [1, NaN]` and
|
|
||||||
`[1] <= [NaN]` are `#!cpp true`. Since C++20, the whole comparison is unordered, and `<`, `<=`, `>`, and `>=` all
|
|
||||||
yield `#!cpp false`. Otherwise (for example `[1, NaN] < [2, NaN]`, or objects whose keys differ), the result is the
|
|
||||||
same for all language standards. The same program can therefore order such values differently when it is compiled
|
|
||||||
with a different language standard.
|
|
||||||
|
|
||||||
!!! note "Operator overload resolution"
|
!!! note "Operator overload resolution"
|
||||||
|
|
||||||
Since C++20 overload resolution will consider the _rewritten candidate_ generated from
|
Since C++20 overload resolution will consider the _rewritten candidate_ generated from
|
||||||
|
|||||||
@@ -61,14 +61,6 @@ Linear.
|
|||||||
2. Comparing a `NaN` with another `NaN`.
|
2. Comparing a `NaN` with another `NaN`.
|
||||||
3. Comparing a `NaN` and any other number.
|
3. Comparing a `NaN` and any other number.
|
||||||
|
|
||||||
For arrays and objects, the elements are compared in order. If the comparison reaches a `NaN` and a number (or
|
|
||||||
another `NaN`) before any other difference, the result depends on the language standard. Before C++20, the pair
|
|
||||||
counts as equivalent and the following elements (or the sizes) decide: for instance, `[NaN] < [1, NaN]` and
|
|
||||||
`[1] <= [NaN]` are `#!cpp true`. Since C++20, the whole comparison is unordered, and `<`, `<=`, `>`, and `>=` all
|
|
||||||
yield `#!cpp false`. Otherwise (for example `[1, NaN] < [2, NaN]`, or objects whose keys differ), the result is the
|
|
||||||
same for all language standards. The same program can therefore order such values differently when it is compiled
|
|
||||||
with a different language standard.
|
|
||||||
|
|
||||||
!!! note "Operator overload resolution"
|
!!! note "Operator overload resolution"
|
||||||
|
|
||||||
Since C++20 overload resolution will consider the _rewritten candidate_ generated from
|
Since C++20 overload resolution will consider the _rewritten candidate_ generated from
|
||||||
|
|||||||
@@ -71,14 +71,6 @@ Linear.
|
|||||||
2. Comparing a `NaN` with another `NaN`.
|
2. Comparing a `NaN` with another `NaN`.
|
||||||
3. Comparing a `NaN` and any other number.
|
3. Comparing a `NaN` and any other number.
|
||||||
|
|
||||||
For arrays and objects, the elements are compared in order. If the comparison reaches a `NaN` and a number (or
|
|
||||||
another `NaN`) before any other difference, the result depends on the language standard. Before C++20, the pair
|
|
||||||
counts as equivalent and the following elements (or the sizes) decide: for instance, `[NaN] < [1, NaN]` and
|
|
||||||
`[1] <= [NaN]` are `#!cpp true`. Since C++20, the whole comparison is unordered, and `<`, `<=`, `>`, and `>=` all
|
|
||||||
yield `#!cpp false`. Otherwise (for example `[1, NaN] < [2, NaN]`, or objects whose keys differ), the result is the
|
|
||||||
same for all language standards. The same program can therefore order such values differently when it is compiled
|
|
||||||
with a different language standard.
|
|
||||||
|
|
||||||
!!! note "Operator overload resolution"
|
!!! note "Operator overload resolution"
|
||||||
|
|
||||||
Since C++20 overload resolution will consider the _rewritten candidate_ generated from
|
Since C++20 overload resolution will consider the _rewritten candidate_ generated from
|
||||||
|
|||||||
@@ -55,10 +55,6 @@ Linear.
|
|||||||
1. Comparing a `NaN` with itself.
|
1. Comparing a `NaN` with itself.
|
||||||
2. Comparing a `NaN` with another `NaN`.
|
2. Comparing a `NaN` with another `NaN`.
|
||||||
3. Comparing a `NaN` and any other number.
|
3. Comparing a `NaN` and any other number.
|
||||||
- For arrays and objects, the elements are compared in order. If the comparison reaches a `NaN` and a number (or
|
|
||||||
another `NaN`) before any other difference, the result is `std::partial_ordering::unordered`. (Without C++20, the
|
|
||||||
comparison operators `<`, `<=`, `>`, and `>=` use the comparison of the containers, which treats such a pair as
|
|
||||||
equivalent; see [**operator<**](operator_lt.md).)
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
|||||||
@@ -124,19 +124,17 @@ outside of a string, invalid) byte; see the [FAQ entry](../../home/faq.md#nul-by
|
|||||||
[`basic_json_document::parse`](../basic_json_document/parse.md) accepts the same inputs and the same options, but
|
[`basic_json_document::parse`](../basic_json_document/parse.md) accepts the same inputs and the same options, but
|
||||||
keeps the result as a flat index of the parsed values instead of a tree of `basic_json` values. It is faster and uses
|
keeps the result as a flat index of the parsed values instead of a tree of `basic_json` values. It is faster and uses
|
||||||
less memory when only parts of the document are read, and it also accepts a pointer to a null-terminated wide string,
|
less memory when only parts of the document are read, and it also accepts a pointer to a null-terminated wide string,
|
||||||
which `parse()` does not. See [Zero-copy JSON views](../../features/json_view/index.md).
|
which `parse()` does not. See [Zero-copy JSON views](../../features/json_view.md).
|
||||||
|
|
||||||
!!! tip "Performance"
|
!!! tip "Performance"
|
||||||
|
|
||||||
Contiguous inputs (strings, string views, vectors, arrays, pointer ranges) are the fastest to parse. A
|
Contiguous inputs (strings, string views, vectors, arrays, pointer ranges) are the fastest to parse. A
|
||||||
`#!cpp std::istream` comes close: the parser scans the characters its stream buffer holds in bulk, without reading
|
`#!cpp std::istream` comes close: the parser scans the characters its stream buffer holds in bulk, without reading
|
||||||
ahead, so the stream is left exactly where it would be after reading one character at a time. With glibc
|
ahead, so the stream is left exactly where it would be after reading one character at a time. A `#!cpp FILE*` is
|
||||||
and the Apple C library, the characters the `#!cpp FILE` holds in its buffer are scanned in bulk like a stream's;
|
read one character at a time, but the file is locked only once, so other threads that use the same `FILE` object
|
||||||
elsewhere a `#!cpp FILE*` is read one character at a time. Where the C library has unlocked stdio functions, the
|
wait until parsing is done. See [input sources and performance](../../features/parsing/index.md#input-sources-and-performance),
|
||||||
file is locked only once, so other threads that use the same `FILE` object wait until parsing is done, unless
|
[`JSON_DISABLE_STREAM_BULK_SCAN`](../macros/json_disable_stream_bulk_scan.md), and
|
||||||
[`JSON_DISABLE_UNLOCKED_FILE_IO`](../macros/json_disable_unlocked_file_io.md) is defined to `1`. See
|
[`JSON_DISABLE_UNLOCKED_FILE_IO`](../macros/json_disable_unlocked_file_io.md).
|
||||||
[input sources and performance](../../features/parsing/index.md#input-sources-and-performance) and
|
|
||||||
[`JSON_DISABLE_STREAM_BULK_SCAN`](../macros/json_disable_stream_bulk_scan.md).
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
@@ -313,10 +311,6 @@ outside of a string, invalid) byte; see the [FAQ entry](../../home/faq.md#nul-by
|
|||||||
it as end of input; planned to become the default in version 4.0.0.
|
it as end of input; planned to become the default in version 4.0.0.
|
||||||
- Extended empty-input detection to also cover an `std::istream` without a stream buffer, and fixed a crash
|
- Extended empty-input detection to also cover an `std::istream` without a stream buffer, and fixed a crash
|
||||||
(`std::terminate`) when parsing from an `std::istream` with `eofbit` in its exception mask, in version 3.13.0.
|
(`std::terminate`) when parsing from an `std::istream` with `eofbit` in its exception mask, in version 3.13.0.
|
||||||
- Fixed the position that a [`parse_error.101`](../../home/exceptions.md#jsonexceptionparse_error101) reports for an
|
|
||||||
unexpected number that is followed by a line feed in version 3.13.0: for the input `1`, line feed, `2`, line feed,
|
|
||||||
version 3.12.0 reported "line 2, column 0" and version 3.13.0 reports "line 2, column 1"; for `1 2` and a line feed,
|
|
||||||
the report was "line 1, column 0" and is now "line 1, column 3".
|
|
||||||
- Parsing from an `std::istream` scans the characters in its stream buffer in bulk in version 3.13.0
|
- Parsing from an `std::istream` scans the characters in its stream buffer in bulk in version 3.13.0
|
||||||
([`JSON_DISABLE_STREAM_BULK_SCAN`](../macros/json_disable_stream_bulk_scan.md) restores reading one character at a
|
([`JSON_DISABLE_STREAM_BULK_SCAN`](../macros/json_disable_stream_bulk_scan.md) restores reading one character at a
|
||||||
time).
|
time).
|
||||||
|
|||||||
@@ -15,9 +15,7 @@ the patch. This function applies a JSON patch in place and returns void.
|
|||||||
|
|
||||||
## Exception safety
|
## Exception safety
|
||||||
|
|
||||||
No guarantees: if an operation fails, the operations before it stay applied, and a failing `move` operation may already
|
No guarantees, value may be corrupted by an unsuccessful patch operation.
|
||||||
have removed the value at its "from" location. Use [`patch`](patch.md) if the value must be unchanged after a failed
|
|
||||||
patch.
|
|
||||||
|
|
||||||
## Exceptions
|
## Exceptions
|
||||||
|
|
||||||
@@ -64,19 +62,8 @@ the JSON value, the complexity can usually be neglected.
|
|||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
Unlike [`patch`](patch.md), `patch_inplace` applies the operation "in place" and no copy of the JSON value is created.
|
Unlike [`patch`](patch.md), `patch_inplace` applies the operation "in place" and no copy of the JSON value is created.
|
||||||
That makes it faster for large documents by avoiding the copy.
|
That makes it faster for large documents by avoiding the copy. However, the JSON value might be corrupted if the
|
||||||
|
function throws an exception.
|
||||||
!!! warning "Not atomic"
|
|
||||||
|
|
||||||
`patch_inplace` applies the operations one after the other and does not undo them when one fails. After an
|
|
||||||
exception, the value holds the result of the operations before the failing one, and a failing `move` operation
|
|
||||||
(a "remove" followed by an "add") may already have removed the value at its "from" location; see the second example
|
|
||||||
below. [RFC 6902](https://tools.ietf.org/html/rfc6902#section-5) requires that a patch with a failing operation is
|
|
||||||
not deemed successful, but leaves open what happens to the document.
|
|
||||||
|
|
||||||
If the value must stay unchanged when the patch fails, use [`patch`](patch.md), which applies the patch to a copy:
|
|
||||||
`#!cpp j = j.patch(json_patch);`. Validating the patch beforehand is not enough, as "test" operations and missing
|
|
||||||
paths are only detected while the patch is applied.
|
|
||||||
|
|
||||||
Duplicate member names inside an operation object are resolved by the parser before the patch is applied (the last one
|
Duplicate member names inside an operation object are resolved by the parser before the patch is applied (the last one
|
||||||
is kept, see [`object_t`](object_t.md#behavior)), so `#!json {"op": "add", "op": "remove", "path": "/a"}` is a
|
is kept, see [`object_t`](object_t.md#behavior)), so `#!json {"op": "add", "op": "remove", "path": "/a"}` is a
|
||||||
|
|||||||
@@ -27,16 +27,6 @@ void push_back(initializer_list_t init);
|
|||||||
`init` is converted into an object element and added using `push_back(const typename object_t::value_type&)`.
|
`init` is converted into an object element and added using `push_back(const typename object_t::value_type&)`.
|
||||||
Otherwise, `init` is converted to a JSON value and added using `push_back(basic_json&&)`.
|
Otherwise, `init` is converted to a JSON value and added using `push_back(basic_json&&)`.
|
||||||
|
|
||||||
!!! note "Single braced JSON value"
|
|
||||||
|
|
||||||
For a call such as `#!cpp arr.push_back({obj})`, where the initializer list contains a single JSON value `obj`,
|
|
||||||
compilers may disagree unless
|
|
||||||
[`JSON_BRACE_INIT_COPY_SEMANTICS`](../macros/json_brace_init_copy_semantics.md) is defined to `1`: GCC, for
|
|
||||||
example, selects this overload and appends a single-element array `[obj]`, whereas Clang selects the
|
|
||||||
`basic_json` overload and appends a copy of `obj`. With the macro, GCC and Clang both append a copy of `obj`.
|
|
||||||
To get a portable result without the macro, write `#!cpp arr.push_back(obj)` to append a copy, or
|
|
||||||
`#!cpp arr.push_back(json::array({obj}))` to append a single-element array.
|
|
||||||
|
|
||||||
## Iterator invalidation
|
## Iterator invalidation
|
||||||
|
|
||||||
For all cases where an element is added to an **array**, a reallocation can happen, in which case all iterators (including
|
For all cases where an element is added to an **array**, a reallocation can happen, in which case all iterators (including
|
||||||
|
|||||||
@@ -124,10 +124,9 @@ consumer `sax` has a super-linear complexity.
|
|||||||
|
|
||||||
A UTF-8 byte order mark is silently ignored.
|
A UTF-8 byte order mark is silently ignored.
|
||||||
|
|
||||||
When reading from a `#!c FILE*` where the C library has unlocked stdio functions, the file is locked while it is parsed,
|
When reading from a `#!c FILE*`, the file is locked while it is parsed. The lock is recursive, so the SAX handler may
|
||||||
unless [`JSON_DISABLE_UNLOCKED_FILE_IO`](../macros/json_disable_unlocked_file_io.md) is defined to `1`.
|
use the same file with stdio functions, but it must not wait for another thread that uses the same `FILE` object; see
|
||||||
The lock is recursive, so the SAX handler may use the same file with stdio functions, but it must not wait for another
|
[`JSON_DISABLE_UNLOCKED_FILE_IO`](../macros/json_disable_unlocked_file_io.md).
|
||||||
thread that uses the same `FILE` object.
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,3 @@ Constant.
|
|||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 3.12.0.
|
- Added in version 3.12.0.
|
||||||
- Fixed in version 3.13.0: in version 3.12.0, the start position of a string that contains escape sequences (for
|
|
||||||
example `#!cpp "\n"` or `#!cpp "\u00e4"`) was too large, by the number of bytes the escape sequences add to the
|
|
||||||
source text. The position is now always that of the opening `"`. The "(bytes a-b)" range in the messages of
|
|
||||||
[`JSON_DIAGNOSTICS`](../macros/json_diagnostics.md) was wrong in the same way.
|
|
||||||
@@ -2,21 +2,12 @@
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
namespace std {
|
namespace std {
|
||||||
void swap(nlohmann::basic_json& j1, nlohmann::basic_json& j2) noexcept(
|
void swap(nlohmann::basic_json& j1, nlohmann::basic_json& j2);
|
||||||
is_nothrow_move_constructible<nlohmann::basic_json>::value &&
|
|
||||||
is_nothrow_move_assignable<nlohmann::basic_json>::value
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Exchanges the values of two JSON objects.
|
Exchanges the values of two JSON objects.
|
||||||
|
|
||||||
This specialization is only provided before C++20, which no longer allows specializing function templates in
|
|
||||||
namespace `std`. With C++20 (and in generic code with any standard), use the idiom `#!cpp using std::swap; swap(j1, j2);`: it finds
|
|
||||||
the [`swap`](swap.md) friend function (overload 2) by argument-dependent lookup. A qualified `#!cpp std::swap(j1, j2)`
|
|
||||||
still compiles with C++20, but uses the generic `std::swap`, which swaps by three moves instead of exchanging the
|
|
||||||
contents.
|
|
||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
`j1` (in, out)
|
`j1` (in, out)
|
||||||
@@ -27,9 +18,7 @@ contents.
|
|||||||
|
|
||||||
## Exception safety
|
## Exception safety
|
||||||
|
|
||||||
No-throw guarantee if the `noexcept` condition above holds: it holds unless moving the
|
No-throw guarantee: this function never throws exceptions.
|
||||||
[`json_base_class_t`](json_base_class_t.md) can throw. With the default base class, this function never throws
|
|
||||||
exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
@@ -68,4 +57,3 @@ void swap(nlohmann::basic_json& j1, nlohmann::basic_json& j2)
|
|||||||
|
|
||||||
- Added in version 1.0.0.
|
- Added in version 1.0.0.
|
||||||
- Extended for arbitrary basic_json types in version 3.10.5.
|
- Extended for arbitrary basic_json types in version 3.10.5.
|
||||||
- Not provided with C++20 since version 3.9.0.
|
|
||||||
@@ -60,11 +60,9 @@ String values are stored as pointers in a `basic_json` type. That is, for any ac
|
|||||||
When converting a string value from one `basic_json` specialization to another via the
|
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
|
[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
|
constructible from the source `basic_json`'s `string_t` type. If this requirement is not met, the
|
||||||
conversion depends on the source string type. If it is a range of characters, the string is converted as an array of
|
conversion does not fail; instead, the string is silently converted as an array of character codes,
|
||||||
character codes, which is incorrect: the converting constructor's [`JSON_ASSERT`](../macros/json_assert.md) fails; with
|
which is incorrect. See [issue #3425](https://github.com/nlohmann/json/issues/3425) for details
|
||||||
its default definition, `assert`, the program aborts unless `NDEBUG` is defined, in which case the array is returned.
|
and an example.
|
||||||
If the source string type is not a range of characters, the conversion does not compile at all. See
|
|
||||||
[issue #3425](https://github.com/nlohmann/json/issues/3425) for details and an example.
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
|||||||
@@ -75,12 +75,8 @@ void swap(typename binary_t::container_type& other);
|
|||||||
|
|
||||||
## Exception safety
|
## Exception safety
|
||||||
|
|
||||||
1. No-throw guarantee if the `noexcept` condition above holds: it holds unless moving the
|
1. No-throw guarantee: this function never throws exceptions.
|
||||||
[`json_base_class_t`](json_base_class_t.md) can throw (moving the type tag and the stored value never throws).
|
2. No-throw guarantee: this function never throws exceptions.
|
||||||
With the default base class, this function never throws exceptions.
|
|
||||||
2. No-throw guarantee if the `noexcept` condition above holds: it holds unless moving the
|
|
||||||
[`json_base_class_t`](json_base_class_t.md) can throw (moving the type tag and the stored value never throws).
|
|
||||||
With the default base class, this function never throws exceptions.
|
|
||||||
3. Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
|
3. Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
|
||||||
4. Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
|
4. Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
|
||||||
5. Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
|
5. Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
|
||||||
@@ -89,8 +85,8 @@ void swap(typename binary_t::container_type& other);
|
|||||||
|
|
||||||
## Exceptions
|
## Exceptions
|
||||||
|
|
||||||
1. Throws only what moving the [`json_base_class_t`](json_base_class_t.md) throws; nothing with the default base class.
|
1. No-throw guarantee: this function never throws exceptions.
|
||||||
2. Throws only what moving the [`json_base_class_t`](json_base_class_t.md) throws; nothing with the default base class.
|
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(array_t&) 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
|
||||||
|
|||||||
@@ -57,8 +57,7 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
|
|||||||
## Exceptions
|
## Exceptions
|
||||||
|
|
||||||
- Throws [`other_error.502`](../../home/exceptions.md#jsonexceptionother_error502) if `use_type` is true and `use_size`
|
- Throws [`other_error.502`](../../home/exceptions.md#jsonexceptionother_error502) if `use_type` is true and `use_size`
|
||||||
is false, and `j` contains a non-empty array, object, or binary value. Scalars and empty arrays, objects, or binary
|
is false, and `j` contains a non-empty array, object, or binary value.
|
||||||
values do not throw.
|
|
||||||
- Throws [type_error.316](../../home/exceptions.md#jsonexceptiontype_error316) if a string or object key in `j` is
|
- Throws [type_error.316](../../home/exceptions.md#jsonexceptiontype_error316) if a string or object key in `j` is
|
||||||
not valid UTF-8 and `error_handler` is `strict` (the default only if
|
not valid UTF-8 and `error_handler` is `strict` (the default only if
|
||||||
[`JSON_STRICT_BINARY_UTF8`](../macros/json_strict_binary_utf8.md) is enabled)
|
[`JSON_STRICT_BINARY_UTF8`](../macros/json_strict_binary_utf8.md) is enabled)
|
||||||
@@ -106,8 +105,6 @@ Linear in the size of the JSON value `j`.
|
|||||||
- [Binary formats](../../features/binary_formats/index.md) - overview and comparison of the supported binary formats
|
- [Binary formats](../../features/binary_formats/index.md) - overview and comparison of the supported binary formats
|
||||||
- [Binary values](../../features/binary_values.md) - how binary values and subtypes are handled
|
- [Binary values](../../features/binary_values.md) - how binary values and subtypes are handled
|
||||||
- [`from_ubjson`](from_ubjson.md) - create a JSON value from an input in UBJSON format
|
- [`from_ubjson`](from_ubjson.md) - create a JSON value from an input in UBJSON format
|
||||||
- [`JSON_UBJSON_VALUELESS_ELEMENTS_PER_BYTE`](../macros/json_ubjson_valueless_elements_per_byte.md) -
|
|
||||||
set how many elements of arrays of `null`, `true`, or `false` a reader accepts per byte of input
|
|
||||||
- [`to_cbor`](to_cbor.md) - create a CBOR serialization of a JSON value
|
- [`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_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_bson`](to_bson.md) - create a BSON serialization of a JSON value
|
||||||
@@ -120,10 +117,5 @@ Linear in the size of the JSON value `j`.
|
|||||||
- Added `error_handler` parameter in version 3.13.0. Its default, `keep`, writes the bytes of a string or object key
|
- Added `error_handler` parameter in version 3.13.0. Its default, `keep`, writes the bytes of a string or object key
|
||||||
that is not valid UTF-8 unchanged, as before; `strict` (the default if
|
that is not valid UTF-8 unchanged, as before; `strict` (the default if
|
||||||
[`JSON_STRICT_BINARY_UTF8`](../macros/json_strict_binary_utf8.md) is enabled) throws `type_error.316`.
|
[`JSON_STRICT_BINARY_UTF8`](../macros/json_strict_binary_utf8.md) is enabled) throws `type_error.316`.
|
||||||
- Writes arrays of `Z`, `T`, or `F` without the `$` type annotation (`[#n Z Z ...`) once their elements in one call
|
|
||||||
add up to more than 1,048,576, in version 3.13.0, so that `from_ubjson` can read the output back. Such output is
|
|
||||||
larger: 270,000 rows of 100 `null` values take 26.8 MB instead of 1.35 MB. The limit does not depend on
|
|
||||||
[`JSON_UBJSON_VALUELESS_ELEMENTS_PER_BYTE`](../macros/json_ubjson_valueless_elements_per_byte.md): a reader accepts at
|
|
||||||
least 1,048,576 elements whatever it is set to, so the writer follows that base only.
|
|
||||||
- Throws `type_error.321` for a discarded value since version 3.13.0; previously, a discarded value nested in an
|
- Throws `type_error.321` for a discarded value since version 3.13.0; previously, a discarded value nested in an
|
||||||
array or object was silently skipped, producing invalid UBJSON.
|
array or object was silently skipped, producing invalid UBJSON.
|
||||||
@@ -26,8 +26,7 @@ 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
|
- Throws [`type_error.313`](../../home/exceptions.md#jsonexceptiontype_error313) if a key (JSON pointer) leads to a
|
||||||
conflicting nesting, for example if a key with a value other than `#!json null` is a prefix of another key (as `/a`
|
conflicting nesting; example: `"invalid value to unflatten"`
|
||||||
and `/a/b`), in whichever order the keys come; example: `"invalid value to unflatten"`
|
|
||||||
- Throws [`parse_error.106`](../../home/exceptions.md#jsonexceptionparse_error106) if an array index in a key begins
|
- Throws [`parse_error.106`](../../home/exceptions.md#jsonexceptionparse_error106) if an array index in a key begins
|
||||||
with '0'; example: `"array index '01' must not begin with '0'"`
|
with '0'; example: `"array index '01' must not begin with '0'"`
|
||||||
- Throws [`parse_error.107`](../../home/exceptions.md#jsonexceptionparse_error107) if a key is not empty and does not
|
- Throws [`parse_error.107`](../../home/exceptions.md#jsonexceptionparse_error107) if a key is not empty and does not
|
||||||
@@ -91,6 +90,3 @@ Apart from these three cases, for a JSON value `j`, the following is always true
|
|||||||
- Throws [`parse_error.109`](../../home/exceptions.md#jsonexceptionparse_error109) instead of
|
- Throws [`parse_error.109`](../../home/exceptions.md#jsonexceptionparse_error109) instead of
|
||||||
[`out_of_range.404`](../../home/exceptions.md#jsonexceptionout_of_range404) for a one-character array index that is
|
[`out_of_range.404`](../../home/exceptions.md#jsonexceptionout_of_range404) for a one-character array index that is
|
||||||
not a digit (e.g., `/x`) in version 3.13.0, as it already did for longer ones.
|
not a digit (e.g., `/x`) in version 3.13.0, as it already did for longer ones.
|
||||||
- Throws [`type_error.313`](../../home/exceptions.md#jsonexceptiontype_error313) for a key that is a prefix of an
|
|
||||||
earlier key in version 3.13.0; before, an object type that keeps the insertion order (such as
|
|
||||||
[`ordered_json`](../ordered_json.md)) silently replaced the nested value.
|
|
||||||
@@ -77,7 +77,7 @@ compile; see [`parse`](parse.md#notes).
|
|||||||
|
|
||||||
- [`parse`](parse.md) - deserialize from a compatible input
|
- [`parse`](parse.md) - deserialize from a compatible input
|
||||||
- [`BasicJsonType::accept`](../basic_json/accept.md) - the corresponding function of `basic_json`
|
- [`BasicJsonType::accept`](../basic_json/accept.md) - the corresponding function of `basic_json`
|
||||||
- [Zero-copy JSON views](../../features/json_view/differences.md#what-is-the-same) - how parsing a document differs from, and matches, basic_json::parse
|
- [Zero-copy JSON views](../../features/json_view.md#what-is-the-same-as-parse) - how parsing a document differs from, and matches, basic_json::parse
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ Constant.
|
|||||||
|
|
||||||
- [`parse`](parse.md) - deserialize from a compatible input
|
- [`parse`](parse.md) - deserialize from a compatible input
|
||||||
- [`is_discarded`](is_discarded.md) - return whether the last parse failed
|
- [`is_discarded`](is_discarded.md) - return whether the last parse failed
|
||||||
- [Zero-copy JSON views](../../features/json_view/lifetime.md) - who owns the source text and for how long
|
- [Zero-copy JSON views](../../features/json_view.md#ownership-and-lifetime) - who owns the source text and for how long
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -66,8 +66,7 @@ has `erase`; calling it on a read-only `basic_json_document` fails to compile (`
|
|||||||
[`parse_error.106`](../../home/exceptions.md#jsonexceptionparse_error106) (a leading `#!cpp '0'`),
|
[`parse_error.106`](../../home/exceptions.md#jsonexceptionparse_error106) (a leading `#!cpp '0'`),
|
||||||
[`parse_error.109`](../../home/exceptions.md#jsonexceptionparse_error109) (not a number),
|
[`parse_error.109`](../../home/exceptions.md#jsonexceptionparse_error109) (not a number),
|
||||||
[`out_of_range.410`](../../home/exceptions.md#jsonexceptionout_of_range410) (too large for `size_type`), or
|
[`out_of_range.410`](../../home/exceptions.md#jsonexceptionout_of_range410) (too large for `size_type`), or
|
||||||
[`out_of_range.404`](../../home/exceptions.md#jsonexceptionout_of_range404) (an empty token, or the token
|
[`out_of_range.404`](../../home/exceptions.md#jsonexceptionout_of_range404) (an empty token); otherwise (an
|
||||||
`#!cpp "-"`, which never names an existing element); otherwise (an
|
|
||||||
object, or a primitive value the pointer's parent resolves to) throws what 1. throws.
|
object, or a primitive value the pointer's parent resolves to) throws what 1. throws.
|
||||||
|
|
||||||
Overloads 1. and 2. also throw [`invalid_iterator.202`](../../home/exceptions.md#jsonexceptioninvalid_iterator202)
|
Overloads 1. and 2. also throw [`invalid_iterator.202`](../../home/exceptions.md#jsonexceptioninvalid_iterator202)
|
||||||
@@ -124,7 +123,7 @@ by an erase, not only those at or after the removed element, since the container
|
|||||||
- [`root`](root.md) - the view of the root value, the starting point of overload 3
|
- [`root`](root.md) - the view of the root value, the starting point of overload 3
|
||||||
- [`BasicJsonType::erase`](../basic_json/erase.md) - the corresponding function of `basic_json`
|
- [`BasicJsonType::erase`](../basic_json/erase.md) - the corresponding function of `basic_json`
|
||||||
- [Edits](index.md#edits) - what an edit guarantees, for every overload
|
- [Edits](index.md#edits) - what an edit guarantees, for every overload
|
||||||
- [Zero-copy JSON views](../../features/json_view/editing.md) - what an edit guarantees and costs
|
- [Zero-copy JSON views](../../features/json_view.md#editing-a-document) - what an edit guarantees and costs
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -109,17 +109,16 @@ points apply to every edit:
|
|||||||
anything `BasicJsonType` can be constructed from (numbers, strings, `#!cpp bool`, `#!cpp nullptr`, containers, ...).
|
anything `BasicJsonType` can be constructed from (numbers, strings, `#!cpp bool`, `#!cpp nullptr`, containers, ...).
|
||||||
- [`dump()`](../basic_json_view/dump.md) writes an edited document with members in document order, new members at
|
- [`dump()`](../basic_json_view/dump.md) writes an edited document with members in document order, new members at
|
||||||
the end, and, with [`number_format::source`](../basic_json_view/number_format.md), keeps the spelling of every
|
the end, and, with [`number_format::source`](../basic_json_view/number_format.md), keeps the spelling of every
|
||||||
number that was not itself edited — see [Editing a document](../../features/json_view/editing.md) for
|
number that was not itself edited — see [Editing a document](../../features/json_view.md#editing-a-document) for
|
||||||
why this matters.
|
why this matters.
|
||||||
- [`read()`](read.md) discards all edits (so its `input` must not be a string obtained from this document),
|
- [`read()`](read.md) discards all edits, [`shrink_to_fit()`](shrink_to_fit.md) does not move the node index once
|
||||||
[`shrink_to_fit()`](shrink_to_fit.md) does not move the node index once there are edits, and
|
there are edits, and [`memory_usage()`](memory_usage.md) includes the memory edits use.
|
||||||
[`memory_usage()`](memory_usage.md) includes the memory edits use.
|
|
||||||
[`source_offset()`](../basic_json_view/source_offset.md) of a value introduced by an edit is
|
[`source_offset()`](../basic_json_view/source_offset.md) of a value introduced by an edit is
|
||||||
`#!cpp static_cast<std::size_t>(-1)`, the same value it reports for a decoded string.
|
`#!cpp static_cast<std::size_t>(-1)`, the same value it reports for a decoded string.
|
||||||
|
|
||||||
## See also
|
## See also
|
||||||
|
|
||||||
- [Zero-copy JSON views](../../features/json_view/index.md) - guide to documents and views
|
- [Zero-copy JSON views](../../features/json_view.md) - guide to documents and views
|
||||||
- [`basic_json_view`](../basic_json_view/index.md) - the non-owning handle to a value in a document
|
- [`basic_json_view`](../basic_json_view/index.md) - the non-owning handle to a value in a document
|
||||||
- [`json_document`](../json_document.md) - and [`json_editable_document`](../json_editable_document.md) - the default specializations
|
- [`json_document`](../json_document.md) - and [`json_editable_document`](../json_editable_document.md) - the default specializations
|
||||||
- [`materialize`](../basic_json_view/materialize.md) - build a `basic_json` value from a view
|
- [`materialize`](../basic_json_view/materialize.md) - build a `basic_json` value from a view
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ an edit in general.
|
|||||||
- [`set`](set.md) - replace a value, or set an object member, an array element, or the value a JSON pointer refers to
|
- [`set`](set.md) - replace a value, or set an object member, an array element, or the value a JSON pointer refers to
|
||||||
- [`BasicJsonType::insert`](../basic_json/insert.md) - the corresponding function of `basic_json`
|
- [`BasicJsonType::insert`](../basic_json/insert.md) - the corresponding function of `basic_json`
|
||||||
- [Edits](index.md#edits) - what an edit guarantees, for every overload
|
- [Edits](index.md#edits) - what an edit guarantees, for every overload
|
||||||
- [Zero-copy JSON views](../../features/json_view/editing.md) - what an edit guarantees and costs
|
- [Zero-copy JSON views](../../features/json_view.md#editing-a-document) - what an edit guarantees and costs
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ When the document is discarded, [`root()`](root.md) returns a discarded view (it
|
|||||||
|
|
||||||
- [`parse`](parse.md) - deserialize from a compatible input
|
- [`parse`](parse.md) - deserialize from a compatible input
|
||||||
- [`basic_json_view::is_discarded`](../basic_json_view/is_discarded.md) - return whether a view is invalid
|
- [`basic_json_view::is_discarded`](../basic_json_view/is_discarded.md) - return whether a view is invalid
|
||||||
- [Zero-copy JSON views](../../features/json_view/differences.md#what-is-the-same) - how a discarded document arises
|
- [Zero-copy JSON views](../../features/json_view.md#what-is-the-same-as-parse) - how a discarded document arises
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ static basic_json_document load(std::vector<std::uint8_t>&& image,
|
|||||||
|
|
||||||
In every overload, the node index is copied into storage the document itself owns — so that it is properly aligned,
|
In every overload, the node index is copied into storage the document itself owns — so that it is properly aligned,
|
||||||
and, for an [editable](index.md#edits) document, can be edited — while the text and the decoded strings stay in
|
and, for an [editable](index.md#edits) document, can be edited — while the text and the decoded strings stay in
|
||||||
`image`. The hash indexes [large objects](../../features/json_view/index.md) use for lookup are rebuilt, exactly as after
|
`image`. The hash indexes [large objects](../../features/json_view.md) use for lookup are rebuilt, exactly as after
|
||||||
parsing.
|
parsing.
|
||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
@@ -113,12 +113,11 @@ How thoroughly `load()` validates `image` before trusting it.
|
|||||||
`full` (the default)
|
`full` (the default)
|
||||||
: Checks everything the parser itself guarantees: structure and bounds; that every string is valid UTF-8 (and, for a
|
: Checks everything the parser itself guarantees: structure and bounds; that every string is valid UTF-8 (and, for a
|
||||||
string still in the source text, that it contains no quote, backslash, or control character); and that every number
|
string still in the source text, that it contains no quote, backslash, or control character); and that every number
|
||||||
token is well-formed and matches the value stored for it, and has the type the parser gives it (a float node only
|
token is well-formed and matches the value stored for it. Strings and float tokens may share a range only if the
|
||||||
for a token with a fraction or an exponent, or an integer that does not fit 64 bits). Strings and float tokens may
|
ranges are identical (as nodes that share a value do), and never overlap otherwise. Reading and serializing a
|
||||||
share a range only if the ranges are identical (as nodes that share a value do), and never overlap otherwise.
|
checked image is safe and always produces valid JSON, exactly as for a parsed document. This is the right choice for
|
||||||
Reading and serializing a checked image is safe and always produces valid JSON, exactly as for a parsed document.
|
an image from anything you do not fully control — a file, a cache shared with other processes, a peer on the
|
||||||
This is the right choice for an image from anything you do not fully control — a file, a cache shared with other
|
network.
|
||||||
processes, a peer on the network.
|
|
||||||
|
|
||||||
`bounds`
|
`bounds`
|
||||||
: Checks structure and bounds only: that every offset and count in the node index stays inside the image. So
|
: Checks structure and bounds only: that every offset and count in the node index stays inside the image. So
|
||||||
@@ -173,7 +172,7 @@ returned document, and any [view](../basic_json_view/index.md) taken from it, is
|
|||||||
- [`save`](save.md) - write the document as an image
|
- [`save`](save.md) - write the document as an image
|
||||||
- [`owns_source`](owns_source.md) - return whether the document holds its own copy of the text
|
- [`owns_source`](owns_source.md) - return whether the document holds its own copy of the text
|
||||||
- [`parse`](parse.md) - deserialize from JSON text instead of an image
|
- [`parse`](parse.md) - deserialize from JSON text instead of an image
|
||||||
- [Images](../../features/json_view/images.md) - why and when to use images
|
- [Images](../../features/json_view.md#images) - why and when to use images
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ to observe the effect of [`shrink_to_fit()`](shrink_to_fit.md).
|
|||||||
|
|
||||||
- [`node_count`](node_count.md) - the number of index entries
|
- [`node_count`](node_count.md) - the number of index entries
|
||||||
- [`shrink_to_fit`](shrink_to_fit.md) - release unused index capacity
|
- [`shrink_to_fit`](shrink_to_fit.md) - release unused index capacity
|
||||||
- [Zero-copy JSON views](../../features/json_view/index.md#the-idea) - the flat node index and its memory
|
- [Zero-copy JSON views](../../features/json_view.md#the-idea) - the flat node index and its memory
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ strings and, for an owned document, the text).
|
|||||||
|
|
||||||
- [`memory_usage`](memory_usage.md) - the number of bytes held by the document
|
- [`memory_usage`](memory_usage.md) - the number of bytes held by the document
|
||||||
- [`shrink_to_fit`](shrink_to_fit.md) - release unused index capacity
|
- [`shrink_to_fit`](shrink_to_fit.md) - release unused index capacity
|
||||||
- [Zero-copy JSON views](../../features/json_view/index.md#the-idea) - the flat node index and its memory
|
- [Zero-copy JSON views](../../features/json_view.md#the-idea) - the flat node index and its memory
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ document (`#!cpp owns_source() == false`) is only valid while the buffer it was
|
|||||||
- [`parse`](parse.md) - deserialize from a compatible input
|
- [`parse`](parse.md) - deserialize from a compatible input
|
||||||
- [`parse_copy`](parse_copy.md) - deserialize a copy of a compatible input, always owned
|
- [`parse_copy`](parse_copy.md) - deserialize a copy of a compatible input, always owned
|
||||||
- [`source`](source.md) - the parsed text
|
- [`source`](source.md) - the parsed text
|
||||||
- [Zero-copy JSON views](../../features/json_view/lifetime.md) - who owns the source text and for how long
|
- [Zero-copy JSON views](../../features/json_view.md#ownership-and-lifetime) - who owns the source text and for how long
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ told apart from other class-type iterators, so their range is read into an owned
|
|||||||
range (e.g. of a `#!cpp std::list<char>`).
|
range (e.g. of a `#!cpp std::list<char>`).
|
||||||
|
|
||||||
See [`owns_source`](owns_source.md) to check which happened after a call, and the
|
See [`owns_source`](owns_source.md) to check which happened after a call, and the
|
||||||
[feature page](../../features/json_view/index.md) for the reasoning.
|
[feature page](../../features/json_view.md) for the reasoning.
|
||||||
|
|
||||||
**Numbers.** As for [`BasicJsonType::parse()`](../basic_json/parse.md), an integer literal too large for the 64-bit
|
**Numbers.** As for [`BasicJsonType::parse()`](../basic_json/parse.md), an integer literal too large for the 64-bit
|
||||||
integer type becomes a floating-point value.
|
integer type becomes a floating-point value.
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ compile; see [`parse`](parse.md#notes).
|
|||||||
|
|
||||||
- [`parse`](parse.md) - deserialize from a compatible input, borrowing it where possible
|
- [`parse`](parse.md) - deserialize from a compatible input, borrowing it where possible
|
||||||
- [`owns_source`](owns_source.md) - return whether the document holds its own copy of the text
|
- [`owns_source`](owns_source.md) - return whether the document holds its own copy of the text
|
||||||
- [Zero-copy JSON views](../../features/json_view/lifetime.md) - borrowing or copying the source text
|
- [Zero-copy JSON views](../../features/json_view.md#ownership-and-lifetime) - borrowing or copying the source text
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ Like [`set`](set.md) on a member or an element, `push_back` never moves an exist
|
|||||||
- [`root`](root.md) - the view of the root value
|
- [`root`](root.md) - the view of the root value
|
||||||
- [`BasicJsonType::push_back`](../basic_json/push_back.md) - the corresponding function of `basic_json`
|
- [`BasicJsonType::push_back`](../basic_json/push_back.md) - the corresponding function of `basic_json`
|
||||||
- [Edits](index.md#edits) - what an edit guarantees, for every overload
|
- [Edits](index.md#edits) - what an edit guarantees, for every overload
|
||||||
- [Zero-copy JSON views](../../features/json_view/editing.md) - what an edit guarantees and costs
|
- [Zero-copy JSON views](../../features/json_view.md#editing-a-document) - what an edit guarantees and costs
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -46,34 +46,6 @@ Linear in the length of the input.
|
|||||||
Every view taken from `#!cpp *this` before the call — including the previous [`root()`](root.md) — is invalidated,
|
Every view taken from `#!cpp *this` before the call — including the previous [`root()`](root.md) — is invalidated,
|
||||||
whether or not the new parse succeeds; take fresh views from [`root()`](root.md) afterward.
|
whether or not the new parse succeeds; take fresh views from [`root()`](root.md) afterward.
|
||||||
|
|
||||||
!!! warning "`input` must not point into the document itself"
|
|
||||||
|
|
||||||
`read()` releases the document's previous text, its decoded strings, and (for an editable document) its edits
|
|
||||||
*before* it parses `input`. An `input` that is, or points into, any of them violates a precondition: it may seem to
|
|
||||||
work, parse empty or garbled text, be reported by a sanitizer, or read freed memory (undefined behavior).
|
|
||||||
|
|
||||||
This applies to every `string_view` obtained from the document whose characters live in memory that `read()`
|
|
||||||
releases:
|
|
||||||
|
|
||||||
- [`source()`](source.md) of a document that owns its text;
|
|
||||||
- [`get_string()`](../basic_json_view/get_string.md) (also as `get<string_view_t>()` or a `string_view` member of a
|
|
||||||
decoded struct) of a string with escapes, of a string of a document that owns its text, and of an edited string;
|
|
||||||
- [`number_token()`](../basic_json_view/number_token.md) of a number of a document that owns its text, and of a
|
|
||||||
number written by an edit;
|
|
||||||
- the key of an object member (`key()`) if it has escapes, was written by an edit, or the document owns its text.
|
|
||||||
|
|
||||||
It does not apply to a text that the caller owns and the document borrows, nor to the strings, keys, and tokens that
|
|
||||||
are read from such a text unchanged, nor to the decoded strings of a borrowed [image](load.md), which live in the
|
|
||||||
caller's image: `read()` never touches them. To parse JSON that a document holds in a string of its own (for
|
|
||||||
example, JSON embedded in a string value), copy the string first, for example with
|
|
||||||
`#!cpp std::string inner(doc.root()["payload"].get_string()); doc.read(inner);`.
|
|
||||||
|
|
||||||
A debug build (one without `NDEBUG`) checks this with `assert()`: an `input` in the document's text, decoded
|
|
||||||
strings, or image, or in the most recent buffer of strings written by edits, ends the program. (Strings written
|
|
||||||
by earlier edits are not covered.) A release build does not check, to keep the cost of reusing a document at a
|
|
||||||
minimum. The check uses `assert()` directly, not [`JSON_ASSERT`](../macros/json_assert.md), which `json.hpp`
|
|
||||||
undefines at its end.
|
|
||||||
|
|
||||||
`input` is borrowed or owned by the same rules as [`parse()`](parse.md#notes); a document can borrow on one call and
|
`input` is borrowed or owned by the same rules as [`parse()`](parse.md#notes); a document can borrow on one call and
|
||||||
own on the next, since ownership is decided freshly each time. An input that is copied (see the table in
|
own on the next, since ownership is decided freshly each time. An input that is copied (see the table in
|
||||||
[`parse()`](parse.md#notes)) is written into the document's previous owned copy, reusing its memory; a moved-in
|
[`parse()`](parse.md#notes)) is written into the document's previous owned copy, reusing its memory; a moved-in
|
||||||
@@ -109,7 +81,7 @@ compile; see [`parse`](parse.md#notes).
|
|||||||
- [`parse`](parse.md) - deserialize from a compatible input
|
- [`parse`](parse.md) - deserialize from a compatible input
|
||||||
- [`root`](root.md) - the view of the root value
|
- [`root`](root.md) - the view of the root value
|
||||||
- [`load`](load.md) - read a document from an image instead of parsing JSON text
|
- [`load`](load.md) - read a document from an image instead of parsing JSON text
|
||||||
- [Zero-copy JSON views](../../features/json_view/lifetime.md) - reusing a document and what it invalidates
|
- [Zero-copy JSON views](../../features/json_view.md#ownership-and-lifetime) - reusing a document and what it invalidates
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ auto v = doc.root();
|
|||||||
returned view is valid under the same conditions as any other view of the document — see
|
returned view is valid under the same conditions as any other view of the document — see
|
||||||
[Object inspection](../basic_json_view/index.md) — in particular, it is invalidated by the next
|
[Object inspection](../basic_json_view/index.md) — in particular, it is invalidated by the next
|
||||||
[`read()`](read.md) or [`shrink_to_fit()`](shrink_to_fit.md) on this document. A view can dangle, like a
|
[`read()`](read.md) or [`shrink_to_fit()`](shrink_to_fit.md) on this document. A view can dangle, like a
|
||||||
`#!cpp std::string_view`; see [Ownership and lifetime](../../features/json_view/lifetime.md).
|
`#!cpp std::string_view`; see [Ownership and lifetime](../../features/json_view.md#ownership-and-lifetime).
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ big-endian reader could not interpret correctly.
|
|||||||
- [`load`](load.md) - read an image written by `save()`
|
- [`load`](load.md) - read an image written by `save()`
|
||||||
- [`owns_source`](owns_source.md) - return whether the document holds its own copy of the text
|
- [`owns_source`](owns_source.md) - return whether the document holds its own copy of the text
|
||||||
- [`basic_json_view::dump`](../basic_json_view/dump.md) - serialize the document to JSON text instead of an image
|
- [`basic_json_view::dump`](../basic_json_view/dump.md) - serialize the document to JSON text instead of an image
|
||||||
- [Images](../../features/json_view/images.md) - why and when to use images
|
- [Images](../../features/json_view.md#images) - why and when to use images
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ one-node scalar.
|
|||||||
- [`basic_json_view::dump`](../basic_json_view/dump.md) - serialize the document, keeping an untouched number's
|
- [`basic_json_view::dump`](../basic_json_view/dump.md) - serialize the document, keeping an untouched number's
|
||||||
spelling with `#!cpp number_format::source`
|
spelling with `#!cpp number_format::source`
|
||||||
- [Edits](index.md#edits) - what an edit guarantees, for every overload
|
- [Edits](index.md#edits) - what an edit guarantees, for every overload
|
||||||
- [Editing a document](../../features/json_view/editing.md) - why editable documents keep the source
|
- [Editing a document](../../features/json_view.md#editing-a-document) - why editable documents keep the source
|
||||||
text's order and number spelling
|
text's order and number spelling
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ possible would be an internal optimization only, not a guarantee to rely on.
|
|||||||
- [`node_count`](node_count.md) - the number of index entries
|
- [`node_count`](node_count.md) - the number of index entries
|
||||||
- [`memory_usage`](memory_usage.md) - the number of bytes held by the document
|
- [`memory_usage`](memory_usage.md) - the number of bytes held by the document
|
||||||
- [`root`](root.md) - the view of the root value
|
- [`root`](root.md) - the view of the root value
|
||||||
- [Zero-copy JSON views](../../features/json_view/lifetime.md) - what releasing memory invalidates
|
- [Zero-copy JSON views](../../features/json_view.md#ownership-and-lifetime) - what releasing memory invalidates
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -24,9 +24,6 @@ Constant.
|
|||||||
For a borrowed document, `source()` points directly into the caller's buffer, so it is only valid while that buffer
|
For a borrowed document, `source()` points directly into the caller's buffer, so it is only valid while that buffer
|
||||||
is; see [`owns_source`](owns_source.md).
|
is; see [`owns_source`](owns_source.md).
|
||||||
|
|
||||||
The text of a document that owns it must not be passed to [`read()`](read.md) of the same document: `read()` releases
|
|
||||||
an owned text before it parses its input. Copy it first. (A borrowed text belongs to the caller and is not affected.)
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
??? example
|
??? example
|
||||||
@@ -45,7 +42,7 @@ an owned text before it parses its input. Copy it first. (A borrowed text belong
|
|||||||
|
|
||||||
- [`owns_source`](owns_source.md) - return whether the document holds its own copy of the text
|
- [`owns_source`](owns_source.md) - return whether the document holds its own copy of the text
|
||||||
- [`source_offset`](../basic_json_view/source_offset.md) - byte offset of a value in the source text
|
- [`source_offset`](../basic_json_view/source_offset.md) - byte offset of a value in the source text
|
||||||
- [Zero-copy JSON views](../../features/json_view/lifetime.md) - who owns the source text and for how long
|
- [Zero-copy JSON views](../../features/json_view.md#ownership-and-lifetime) - who owns the source text and for how long
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ Pointer path of the value within the document, and with
|
|||||||
|
|
||||||
If the source text repeats a key, this resolves to the *first* member with it, not to the last one that
|
If the source text repeats a key, this resolves to the *first* member with it, not to the last one that
|
||||||
[`materialize()`](materialize.md) and `parse()` keep. See the [Notes on duplicate keys](operator[].md#notes) of
|
[`materialize()`](materialize.md) and `parse()` keep. See the [Notes on duplicate keys](operator[].md#notes) of
|
||||||
`operator[]` and [Duplicate keys](../../features/json_view/differences.md#duplicate-keys) for the reasons and for how to get
|
`operator[]` and [Duplicate keys](../../features/json_view.md#duplicate-keys) for the reasons and for how to get
|
||||||
the last value.
|
the last value.
|
||||||
|
|
||||||
Unlike [`operator[]`](operator[].md), which returns a [discarded](is_discarded.md) view for a missing key or an
|
Unlike [`operator[]`](operator[].md), which returns a [discarded](is_discarded.md) view for a missing key or an
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ placeholder for "no value yet" and later be assigned a real view.
|
|||||||
- [`is_discarded`](is_discarded.md) - return whether the view is invalid
|
- [`is_discarded`](is_discarded.md) - return whether the view is invalid
|
||||||
- [`root`](../basic_json_document/root.md) - the view of a document's root value
|
- [`root`](../basic_json_document/root.md) - the view of a document's root value
|
||||||
- [`view_mode`](../view_mode.md) - whether a document and its views can be edited
|
- [`view_mode`](../view_mode.md) - whether a document and its views can be edited
|
||||||
- [Zero-copy JSON views](../../features/json_view/lifetime.md) - how long a view stays valid
|
- [Zero-copy JSON views](../../features/json_view.md#ownership-and-lifetime) - how long a view stays valid
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ No-throw guarantee: this function never throws exceptions.
|
|||||||
|
|
||||||
If the source text repeats a key, this resolves to the *first* member with it, not to the last one that
|
If the source text repeats a key, this resolves to the *first* member with it, not to the last one that
|
||||||
[`materialize()`](materialize.md) and `parse()` keep. See the [Notes on duplicate keys](operator[].md#notes) of
|
[`materialize()`](materialize.md) and `parse()` keep. See the [Notes on duplicate keys](operator[].md#notes) of
|
||||||
`operator[]` and [Duplicate keys](../../features/json_view/differences.md#duplicate-keys) for the reasons and for how to get
|
`operator[]` and [Duplicate keys](../../features/json_view.md#duplicate-keys) for the reasons and for how to get
|
||||||
the last value.
|
the last value.
|
||||||
|
|
||||||
Overload 1 always returns `#!cpp false` when the value is not an object — including a [discarded](is_discarded.md)
|
Overload 1 always returns `#!cpp false` when the value is not an object — including a [discarded](is_discarded.md)
|
||||||
@@ -62,9 +62,10 @@ view.
|
|||||||
|
|
||||||
!!! info "Overload 2 never throws"
|
!!! info "Overload 2 never throws"
|
||||||
|
|
||||||
Like [`BasicJsonType::contains(const json_pointer&)`](../basic_json/contains.md), overload 2 never throws: a
|
Unlike [`BasicJsonType::contains(const json_pointer&)`](../basic_json/contains.md), which can throw for certain
|
||||||
missing key, an out-of-range or malformed array index, a `#!cpp "-"` index, or a reference token used on a
|
malformed pointers (for instance an empty array-index reference token), overload 2 never throws: a missing key,
|
||||||
primitive all simply make it return `#!cpp false`.
|
an out-of-range or malformed array index, a `#!cpp "-"` index, or a reference token used on a primitive all
|
||||||
|
simply make it return `#!cpp false`.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
|||||||
@@ -48,11 +48,8 @@ Strong exception safety: if an exception is thrown, there are no changes to the
|
|||||||
|
|
||||||
May throw `#!cpp std::bad_alloc` if allocating the output string fails. Unlike
|
May throw `#!cpp std::bad_alloc` if allocating the output string fails. Unlike
|
||||||
[`BasicJsonType::dump`](../basic_json/dump.md), there is no `error_handler` parameter and no
|
[`BasicJsonType::dump`](../basic_json/dump.md), there is no `error_handler` parameter and no
|
||||||
[`type_error.316`](../../home/exceptions.md#jsonexceptiontype_error316): the parser validated the text the view
|
[`type_error.316`](../../home/exceptions.md#jsonexceptiontype_error316): the view only ever holds text the parser
|
||||||
holds as UTF-8, so there is nothing to replace or ignore. Only a document loaded with
|
already validated as UTF-8, so there is nothing to replace or ignore.
|
||||||
[`image_check::bounds` or `image_check::none`](../basic_json_document/load.md#image_check) can still throw it: these do
|
|
||||||
not check the strings, so `dump()` writes such a string as it is, which can be invalid UTF-8 or invalid JSON, and
|
|
||||||
`dump()` with `ensure_ascii` set to `#!cpp true` throws `type_error.316` for invalid UTF-8.
|
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
@@ -73,7 +70,7 @@ except that `#!cpp -0` is written as `#!cpp 0`, the way [`BasicJsonType::parse()
|
|||||||
`#!cpp number_format::source` copies every number exactly as written in the source text instead, with no exception
|
`#!cpp number_format::source` copies every number exactly as written in the source text instead, with no exception
|
||||||
for `#!cpp -0` — `#!cpp 1.50`, `#!cpp 1E2`, `#!cpp -0.0`, `#!cpp -0`, or all digits of an integer literal with more
|
for `#!cpp -0` — `#!cpp 1.50`, `#!cpp 1E2`, `#!cpp -0.0`, `#!cpp -0`, or all digits of an integer literal with more
|
||||||
digits than any number type holds (such a literal is itself classified as a float, see
|
digits than any number type holds (such a literal is itself classified as a float, see
|
||||||
[What is different](../../features/json_view/differences.md)) — something `BasicJsonType` cannot do, since
|
[What is different](../../features/json_view.md#what-is-different)) — something `BasicJsonType` cannot do, since
|
||||||
parsing already reduces every number to its parsed value.
|
parsing already reduces every number to its parsed value.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
@@ -101,7 +98,7 @@ parsing already reduces every number to its parsed value.
|
|||||||
- [`operator<<`](operator_ltlt.md) - serialize this value to a stream
|
- [`operator<<`](operator_ltlt.md) - serialize this value to a stream
|
||||||
- [`materialize`](materialize.md) - build a `BasicJsonType` value, e.g. to use `BasicJsonType::dump`'s `error_handler`
|
- [`materialize`](materialize.md) - build a `BasicJsonType` value, e.g. to use `BasicJsonType::dump`'s `error_handler`
|
||||||
- [`BasicJsonType::dump`](../basic_json/dump.md) - the corresponding function of `basic_json`
|
- [`BasicJsonType::dump`](../basic_json/dump.md) - the corresponding function of `basic_json`
|
||||||
- [Zero-copy JSON views](../../features/json_view/reading.md#writing-a-view-back) - writing a view back without building a tree
|
- [Zero-copy JSON views](../../features/json_view.md#writing-a-view-back) - writing a view back without building a tree
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ constant time on average.
|
|||||||
|
|
||||||
If the source text repeats a key, this resolves to the *first* member with it, not to the last one that
|
If the source text repeats a key, this resolves to the *first* member with it, not to the last one that
|
||||||
[`materialize()`](materialize.md) and `parse()` keep. See the [Notes on duplicate keys](operator[].md#notes) of
|
[`materialize()`](materialize.md) and `parse()` keep. See the [Notes on duplicate keys](operator[].md#notes) of
|
||||||
`operator[]` and [Duplicate keys](../../features/json_view/differences.md#duplicate-keys) for the reasons and for how to get
|
`operator[]` and [Duplicate keys](../../features/json_view.md#duplicate-keys) for the reasons and for how to get
|
||||||
the last value.
|
the last value.
|
||||||
|
|
||||||
Unlike [`BasicJsonType::find`](../basic_json/find.md), which always returns `#!cpp end()` for a non-object type, this
|
Unlike [`BasicJsonType::find`](../basic_json/find.md), which always returns `#!cpp end()` for a non-object type, this
|
||||||
|
|||||||
@@ -39,14 +39,14 @@ as [`BasicJsonType::parse()`](../basic_json/parse.md) does), as well as the type
|
|||||||
accept views, e.g. with [`is_json_view`](../is_json_view.md). A `from_json()` that also accepts types that are no JSON
|
accept views, e.g. with [`is_json_view`](../is_json_view.md). A `from_json()` that also accepts types that are no JSON
|
||||||
values at all, such as the unconstrained `#!cpp template<typename BasicJsonType> void from_json(const BasicJsonType&,
|
values at all, such as the unconstrained `#!cpp template<typename BasicJsonType> void from_json(const BasicJsonType&,
|
||||||
T&)` of [arbitrary type conversions](../../features/arbitrary_types.md), is not called with a view: it may use
|
T&)` of [arbitrary type conversions](../../features/arbitrary_types.md), is not called with a view: it may use
|
||||||
`BasicJsonType` functions a view does not have. See [Writing generic code](../../features/json_view/generic_code.md).
|
`BasicJsonType` functions a view does not have. See [Writing generic code](../../features/json_view.md#writing-generic-code).
|
||||||
|
|
||||||
!!! warning "Duplicate keys"
|
!!! warning "Duplicate keys"
|
||||||
|
|
||||||
Such a `from_json()` looks members up in the view, where a repeated key finds the **first** member, while
|
Such a `from_json()` looks members up in the view, where a repeated key finds the **first** member, while
|
||||||
`#!cpp materialize().get<T>()` sees the **last** one, as [`BasicJsonType::parse()`](../basic_json/parse.md)
|
`#!cpp materialize().get<T>()` sees the **last** one, as [`BasicJsonType::parse()`](../basic_json/parse.md)
|
||||||
keeps it: for `#!cpp {"x":1,"x":2}`, `#!cpp get<point>()` reads `#!cpp x == 1`. See
|
keeps it: for `#!cpp {"x":1,"x":2}`, `#!cpp get<point>()` reads `#!cpp x == 1`. See
|
||||||
[Duplicate keys](../../features/json_view/differences.md#duplicate-keys).
|
[Duplicate keys](../../features/json_view.md#duplicate-keys).
|
||||||
|
|
||||||
Every other `T` — user types whose `from_json()` is written for `BasicJsonType` only, types without a default
|
Every other `T` — user types whose `from_json()` is written for `BasicJsonType` only, types without a default
|
||||||
constructor, `#!cpp std::tuple`s holding references, ... — is converted by `#!cpp materialize().get<T>()`: the subtree is built into a real `BasicJsonType`
|
constructor, `#!cpp std::tuple`s holding references, ... — is converted by `#!cpp materialize().get<T>()`: the subtree is built into a real `BasicJsonType`
|
||||||
@@ -152,7 +152,7 @@ instead: its path is relative to the root of the view's subtree, because `materi
|
|||||||
- [`number_token`](number_token.md) - a number's token text, without a copy
|
- [`number_token`](number_token.md) - a number's token text, without a copy
|
||||||
- [`materialize`](materialize.md) - build the `BasicJsonType` value of this subtree
|
- [`materialize`](materialize.md) - build the `BasicJsonType` value of this subtree
|
||||||
- [`BasicJsonType::get`](../basic_json/get.md) - the corresponding function of `basic_json`
|
- [`BasicJsonType::get`](../basic_json/get.md) - the corresponding function of `basic_json`
|
||||||
- [Zero-copy JSON views](../../features/json_view/reading.md#getting-values-out-without-copying) - which conversions avoid building a basic_json value
|
- [Zero-copy JSON views](../../features/json_view.md#getting-values-out-without-copying) - which conversions avoid building a basic_json value
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -46,10 +46,6 @@ The returned [`string_view_t`](index.md#member-types) is valid exactly as long a
|
|||||||
source text, which for a borrowed document must remain valid **and unmodified** for as long as the document exists,
|
source text, which for a borrowed document must remain valid **and unmodified** for as long as the document exists,
|
||||||
since floating-point values and unescaped strings are read from the source lazily.
|
since floating-point values and unescaped strings are read from the source lazily.
|
||||||
|
|
||||||
A string with escapes, a string of a document that owns its text, and an edited string must not be passed to
|
|
||||||
[`read()`](../basic_json_document/read.md) of the document it came from: `read()` releases them before it parses its
|
|
||||||
input. Copy the string first. (A string read unchanged from a borrowed text is not affected.)
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
??? example
|
??? example
|
||||||
@@ -74,7 +70,7 @@ input. Copy the string first. (A string read unchanged from a borrowed text is n
|
|||||||
- [`get`](get.md) - convert the value to a given type (`#!cpp get<string_view_t>()` is equivalent to this function)
|
- [`get`](get.md) - convert the value to a given type (`#!cpp get<string_view_t>()` is equivalent to this function)
|
||||||
- [`number_token`](number_token.md) - a number's token text, without a copy
|
- [`number_token`](number_token.md) - a number's token text, without a copy
|
||||||
- [`BasicJsonType::get_ref`](../basic_json/get_ref.md) - the closest counterpart of `basic_json`
|
- [`BasicJsonType::get_ref`](../basic_json/get_ref.md) - the closest counterpart of `basic_json`
|
||||||
- [Zero-copy JSON views](../../features/json_view/reading.md#getting-values-out-without-copying) - borrowing strings instead of copying them
|
- [Zero-copy JSON views](../../features/json_view.md#getting-values-out-without-copying) - borrowing strings instead of copying them
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ them with those of a default-constructed `T`.
|
|||||||
|
|
||||||
- [`get`](get.md) - convert the value to a given type
|
- [`get`](get.md) - convert the value to a given type
|
||||||
- [`BasicJsonType::get_to`](../basic_json/get_to.md) - the corresponding function of `basic_json`
|
- [`BasicJsonType::get_to`](../basic_json/get_to.md) - the corresponding function of `basic_json`
|
||||||
- [Zero-copy JSON views](../../features/json_view/reading.md#getting-values-out-without-copying) - which conversions avoid building a basic_json value
|
- [Zero-copy JSON views](../../features/json_view.md#getting-values-out-without-copying) - which conversions avoid building a basic_json value
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ still refers to it — including ones taken before the change — reads the new
|
|||||||
|
|
||||||
## See also
|
## See also
|
||||||
|
|
||||||
- [Zero-copy JSON views](../../features/json_view/index.md) - guide to documents and views
|
- [Zero-copy JSON views](../../features/json_view.md) - guide to documents and views
|
||||||
- [`basic_json_document`](../basic_json_document/index.md) - the document that owns the parsed data
|
- [`basic_json_document`](../basic_json_document/index.md) - the document that owns the parsed data
|
||||||
- [`json_view`](../json_view.md) - and [`json_editable_view`](../json_editable_view.md) - the default specializations
|
- [`json_view`](../json_view.md) - and [`json_editable_view`](../json_editable_view.md) - the default specializations
|
||||||
- [`materialize`](materialize.md) - build a `basic_json` value from a view
|
- [`materialize`](materialize.md) - build a `basic_json` value from a view
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ A `basic_json_view` is not convertible to `#!cpp bool`: such a conversion would
|
|||||||
- [`(constructor)`](basic_json_view.md) - the default constructor creates a discarded view
|
- [`(constructor)`](basic_json_view.md) - the default constructor creates a discarded view
|
||||||
- [`basic_json_document::is_discarded`](../basic_json_document/is_discarded.md) - return whether the last parse failed
|
- [`basic_json_document::is_discarded`](../basic_json_document/is_discarded.md) - return whether the last parse failed
|
||||||
- [`BasicJsonType::is_discarded`](../basic_json/is_discarded.md) - the corresponding function of `basic_json`
|
- [`BasicJsonType::is_discarded`](../basic_json/is_discarded.md) - the corresponding function of `basic_json`
|
||||||
- [Zero-copy JSON views](../../features/json_view/differences.md) - how views differ from basic_json
|
- [Zero-copy JSON views](../../features/json_view.md#what-is-different) - how views differ from basic_json
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -27,10 +27,9 @@ for (const auto [key, value] : v.items())
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Taking `item` by value (`#!cpp const auto`) is recommended: unlike `BasicJsonType::items()`, whose elements are
|
Note the `#!cpp const auto` (by value), not `#!cpp const auto&`: unlike `BasicJsonType::items()`, whose elements are
|
||||||
references into an existing object, a view's `item` is produced on the fly for each step of the iteration and is
|
references into an existing object, a view's `item` is produced on the fly for each step of the iteration, so there
|
||||||
cheap to copy. A `#!cpp const auto&` (as in the first snippet) also works, as it binds to that temporary, but a
|
is nothing for a reference to bind to.
|
||||||
non-const `#!cpp auto&` does not compile.
|
|
||||||
|
|
||||||
## Return value
|
## Return value
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ never caches the result.
|
|||||||
- [`root`](../basic_json_document/root.md) - the view of a document's root value
|
- [`root`](../basic_json_document/root.md) - the view of a document's root value
|
||||||
- [`BasicJsonType::parse`](../basic_json/parse.md) - build a `BasicJsonType` value directly from a JSON text
|
- [`BasicJsonType::parse`](../basic_json/parse.md) - build a `BasicJsonType` value directly from a JSON text
|
||||||
- [`JSON_DIAGNOSTIC_POSITIONS`](../macros/json_diagnostic_positions.md) - source positions on parsed values
|
- [`JSON_DIAGNOSTIC_POSITIONS`](../macros/json_diagnostic_positions.md) - source positions on parsed values
|
||||||
- [Zero-copy JSON views](../../features/json_view/reading.md#getting-values-out-without-copying) - when to build a basic_json value from a view
|
- [Zero-copy JSON views](../../features/json_view.md#getting-values-out-without-copying) - when to build a basic_json value from a view
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ source
|
|||||||
- [`number_token`](number_token.md) - get a single number's token text without dumping the whole value
|
- [`number_token`](number_token.md) - get a single number's token text without dumping the whole value
|
||||||
- [`BasicJsonType::error_handler_t`](../basic_json/error_handler_t.md) - the analogous enumeration for
|
- [`BasicJsonType::error_handler_t`](../basic_json/error_handler_t.md) - the analogous enumeration for
|
||||||
`BasicJsonType::dump`'s decoding-error behavior
|
`BasicJsonType::dump`'s decoding-error behavior
|
||||||
- [Zero-copy JSON views](../../features/json_view/reading.md#writing-a-view-back) - writing numbers as they appeared in the source
|
- [Zero-copy JSON views](../../features/json_view.md#writing-a-view-back) - writing numbers as they appeared in the source
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -38,14 +38,9 @@ by the grammar; trailing zeros in the fraction; the case and sign of the exponen
|
|||||||
useful precisely where that form must survive — a price or an identifier that must be reproduced exactly, or a
|
useful precisely where that form must survive — a price or an identifier that must be reproduced exactly, or a
|
||||||
number too large for any of `BasicJsonType`'s number types to hold without loss.
|
number too large for any of `BasicJsonType`'s number types to hold without loss.
|
||||||
|
|
||||||
The returned [`string_view_t`](index.md#member-types) points into the document's
|
The returned [`string_view_t`](index.md#member-types) always points into the document's
|
||||||
[`source()`](../basic_json_document/source.md) text or, for a number written by an
|
[`source()`](../basic_json_document/source.md) text — numbers are never decoded into the document's separate string
|
||||||
[edit](../basic_json_document/index.md#edits), into storage owned by the document (the token of an edited `NaN` is
|
buffer — and is valid exactly as long as that text is, see the [validity rules](index.md) of `basic_json_view`.
|
||||||
`nan`). It is valid exactly as long as that text or storage is, see the [validity rules](index.md) of
|
|
||||||
`basic_json_view`. Numbers are never decoded into the document's separate string buffer.
|
|
||||||
|
|
||||||
For the same reason, the token must not be passed to [`read()`](../basic_json_document/read.md) of the document it came
|
|
||||||
from if that document owns its text or the number was written by an edit: `read()` releases both before it parses.
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
@@ -73,7 +68,7 @@ from if that document owns its text or the number was written by an edit: `read(
|
|||||||
- [`BasicJsonType::number_integer_t`](../basic_json/number_integer_t.md),
|
- [`BasicJsonType::number_integer_t`](../basic_json/number_integer_t.md),
|
||||||
[`number_unsigned_t`](../basic_json/number_unsigned_t.md), [`number_float_t`](../basic_json/number_float_t.md) - the
|
[`number_unsigned_t`](../basic_json/number_unsigned_t.md), [`number_float_t`](../basic_json/number_float_t.md) - the
|
||||||
number types `#!cpp get<T>()` and `materialize()` convert into
|
number types `#!cpp get<T>()` and `materialize()` convert into
|
||||||
- [Zero-copy JSON views](../../features/json_view/reading.md#getting-values-out-without-copying) - reading a number exactly as written
|
- [Zero-copy JSON views](../../features/json_view.md#getting-values-out-without-copying) - reading a number exactly as written
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ document.
|
|||||||
[`materialize()`](materialize.md) or iterate the members with [`items()`](items.md) and keep the last match.
|
[`materialize()`](materialize.md) or iterate the members with [`items()`](items.md) and keep the last match.
|
||||||
The key hash index of a larger object (128 members or more) leads to the first member of a key as well.
|
The key hash index of a larger object (128 members or more) leads to the first member of a key as well.
|
||||||
[`begin()`](begin.md)/[`end()`](end.md) and [`items()`](items.md) iterate over *all* members, including
|
[`begin()`](begin.md)/[`end()`](end.md) and [`items()`](items.md) iterate over *all* members, including
|
||||||
duplicates, in document order. See [Duplicate keys](../../features/json_view/differences.md#duplicate-keys) and
|
duplicates, in document order. See [Duplicate keys](../../features/json_view.md#duplicate-keys) and
|
||||||
[`size()`](size.md#notes).
|
[`size()`](size.md#notes).
|
||||||
|
|
||||||
!!! info "JSON pointer resolution"
|
!!! info "JSON pointer resolution"
|
||||||
|
|||||||
@@ -7,10 +7,6 @@ bool operator==(const basic_json_view& lhs, const basic_json_view& rhs);
|
|||||||
// (2)
|
// (2)
|
||||||
bool operator==(const basic_json_view& lhs, const BasicJsonType& rhs);
|
bool operator==(const basic_json_view& lhs, const BasicJsonType& rhs);
|
||||||
bool operator==(const BasicJsonType& lhs, const basic_json_view& rhs);
|
bool operator==(const BasicJsonType& lhs, const basic_json_view& rhs);
|
||||||
|
|
||||||
// (3)
|
|
||||||
template<view_mode M>
|
|
||||||
bool operator==(const basic_json_view& lhs, const basic_json_view<BasicJsonType, M>& rhs);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Compares two views for equality: whether the values [`BasicJsonType::parse()`](../basic_json/parse.md) would
|
1. Compares two views for equality: whether the values [`BasicJsonType::parse()`](../basic_json/parse.md) would
|
||||||
@@ -18,16 +14,12 @@ bool operator==(const basic_json_view& lhs, const basic_json_view<BasicJsonType,
|
|||||||
2. Compares a view and a `BasicJsonType` value for equality, in either order: whether the value `parse()` would
|
2. Compares a view and a `BasicJsonType` value for equality, in either order: whether the value `parse()` would
|
||||||
produce for the view and the other operand are equal, according to `BasicJsonType`'s
|
produce for the view and the other operand are equal, according to `BasicJsonType`'s
|
||||||
[`operator==`](../basic_json/operator_eq.md).
|
[`operator==`](../basic_json/operator_eq.md).
|
||||||
3. Like overload 1, for two views of the same `BasicJsonType` but of different [view modes](../view_mode.md), in
|
|
||||||
either order: a view of a read-only document (such as a [`json_view`](../json_view.md)) and a view of an editable
|
|
||||||
document (such as a [`json_editable_view`](../json_editable_view.md)). This overload only takes part in overload
|
|
||||||
resolution if `M` is not the mode of `lhs`.
|
|
||||||
|
|
||||||
No overload builds a `BasicJsonType` value for a view to do the comparison (see [Notes](#notes) below). Numbers
|
Neither overload builds a `BasicJsonType` value for a view to do the comparison (see [Notes](#notes) below). Numbers
|
||||||
compare by value across their types (`#!cpp 1 == 1.0`), and an object compares by its members, with duplicate keys
|
compare by value across their types (`#!cpp 1 == 1.0`), and an object compares by its members, with duplicate keys
|
||||||
resolved exactly as `parse()` resolves them — the last value, at the position of the first occurrence of the key.
|
resolved exactly as `parse()` resolves them — the last value, at the position of the first occurrence of the key.
|
||||||
This is not what [`operator[]`](operator[].md) and the other lookups return for a duplicate key: they find the *first*
|
This is not what [`operator[]`](operator[].md) and the other lookups return for a duplicate key: they find the *first*
|
||||||
member (see [Duplicate keys](../../features/json_view/differences.md#duplicate-keys)).
|
member (see [Duplicate keys](../../features/json_view.md#duplicate-keys)).
|
||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
@@ -65,9 +57,7 @@ compared. Two arrays of different [`size()`](size.md) are rejected without visit
|
|||||||
Only a single number, boolean, or `#!cpp null` value is ever materialized into a `BasicJsonType`, to reuse its
|
Only a single number, boolean, or `#!cpp null` value is ever materialized into a `BasicJsonType`, to reuse its
|
||||||
`operator==` — for numbers, so that values written differently in the source text but equal in value (e.g. an
|
`operator==` — for numbers, so that values written differently in the source text but equal in value (e.g. an
|
||||||
integer and a floating-point literal) still compare equal, following the same rules `BasicJsonType` does for special
|
integer and a floating-point literal) still compare equal, following the same rules `BasicJsonType` does for special
|
||||||
values such as `#!cpp NaN`: a `#!cpp NaN` that an [edit](../basic_json_document/set.md) wrote is not equal to itself, so
|
values such as `#!cpp NaN`. Constructing one of these scalars never allocates. Strings are compared directly, without
|
||||||
a view of it is not equal to itself either, nor is a view of an array or object that contains one, as for
|
|
||||||
`BasicJsonType`. Constructing one of these scalars never allocates. Strings are compared directly, without
|
|
||||||
allocating, either from the source text on both sides or, for overload 2, against `BasicJsonType`'s own string.
|
allocating, either from the source text on both sides or, for overload 2, against `BasicJsonType`'s own string.
|
||||||
Arrays and objects are never materialized at all; only their elements or members are visited, one pair at a time.
|
Arrays and objects are never materialized at all; only their elements or members are visited, one pair at a time.
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ Linear, as [`dump`](dump.md#complexity).
|
|||||||
- [`dump`](dump.md) - serialize to a JSON-formatted string
|
- [`dump`](dump.md) - serialize to a JSON-formatted string
|
||||||
- [`operator<<(std::ostream&)`](../operator_ltlt.md) - the corresponding operator for `basic_json`
|
- [`operator<<(std::ostream&)`](../operator_ltlt.md) - the corresponding operator for `basic_json`
|
||||||
- [`JSON_NO_IO`](../macros/json_no_io.md) - switch off functions relying on certain C++ I/O headers
|
- [`JSON_NO_IO`](../macros/json_no_io.md) - switch off functions relying on certain C++ I/O headers
|
||||||
- [Zero-copy JSON views](../../features/json_view/reading.md#writing-a-view-back) - writing a view back without building a tree
|
- [Zero-copy JSON views](../../features/json_view.md#writing-a-view-back) - writing a view back without building a tree
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -7,17 +7,11 @@ bool operator!=(const basic_json_view& lhs, const basic_json_view& rhs);
|
|||||||
// (2)
|
// (2)
|
||||||
bool operator!=(const basic_json_view& lhs, const BasicJsonType& rhs);
|
bool operator!=(const basic_json_view& lhs, const BasicJsonType& rhs);
|
||||||
bool operator!=(const BasicJsonType& lhs, const basic_json_view& rhs);
|
bool operator!=(const BasicJsonType& lhs, const basic_json_view& rhs);
|
||||||
|
|
||||||
// (3)
|
|
||||||
template<view_mode M>
|
|
||||||
bool operator!=(const basic_json_view& lhs, const basic_json_view<BasicJsonType, M>& rhs);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Compares two views for inequality. Returns `#!cpp !(lhs == rhs)`, see [operator==](operator_eq.md).
|
1. Compares two views for inequality. Returns `#!cpp !(lhs == rhs)`, see [operator==](operator_eq.md).
|
||||||
2. Compares a view and a `BasicJsonType` value for inequality, in either order. Returns `#!cpp !(lhs == rhs)` (or,
|
2. Compares a view and a `BasicJsonType` value for inequality, in either order. Returns `#!cpp !(lhs == rhs)` (or,
|
||||||
for the reversed order, `#!cpp !(rhs == lhs)`), see [operator==](operator_eq.md).
|
for the reversed order, `#!cpp !(rhs == lhs)`), see [operator==](operator_eq.md).
|
||||||
3. Compares a read-only and an editable view of the same `BasicJsonType` for inequality, in either order. Returns
|
|
||||||
`#!cpp !(lhs == rhs)`, see [operator==](operator_eq.md).
|
|
||||||
|
|
||||||
Since `operator!=` is defined as the negation of [`operator==`](operator_eq.md), it follows the same rules for
|
Since `operator!=` is defined as the negation of [`operator==`](operator_eq.md), it follows the same rules for
|
||||||
special cases: for instance, since a [discarded](is_discarded.md) view is never equal to anything by default (see
|
special cases: for instance, since a [discarded](is_discarded.md) view is never equal to anything by default (see
|
||||||
|
|||||||
@@ -15,10 +15,6 @@ materializing anything.
|
|||||||
- `#!cpp static_cast<std::size_t>(-1)` for a [discarded](is_discarded.md) view, and for a string that contains
|
- `#!cpp static_cast<std::size_t>(-1)` for a [discarded](is_discarded.md) view, and for a string that contains
|
||||||
escapes — such a string was decoded once into the document's own buffer, so there is no single byte range in
|
escapes — such a string was decoded once into the document's own buffer, so there is no single byte range in
|
||||||
`source()` left to point at.
|
`source()` left to point at.
|
||||||
- `#!cpp static_cast<std::size_t>(-1)` in an [editable document](../json_editable_document.md) for a value written
|
|
||||||
by an edit ([`set`](../basic_json_document/set.md), [`push_back`](../basic_json_document/push_back.md),
|
|
||||||
[`insert`](../basic_json_document/insert.md)), and for an array or object whose elements an edit added or removed.
|
|
||||||
The values an edit did not touch keep their offsets.
|
|
||||||
|
|
||||||
## Exception safety
|
## Exception safety
|
||||||
|
|
||||||
@@ -53,7 +49,7 @@ string, whose token length is not the same as its decoded [`size()`](size.md).
|
|||||||
|
|
||||||
- [`source`](../basic_json_document/source.md) - the parsed text
|
- [`source`](../basic_json_document/source.md) - the parsed text
|
||||||
- [`is_string`](is_string.md) - return whether the value is a string
|
- [`is_string`](is_string.md) - return whether the value is a string
|
||||||
- [Zero-copy JSON views](../../features/json_view/images.md) - images and the source text
|
- [Zero-copy JSON views](../../features/json_view.md#images) - images and the source text
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ Pointer path of the value within the document, and with
|
|||||||
|
|
||||||
If the source text repeats a key, this resolves to the *first* member with it, not to the last one that
|
If the source text repeats a key, this resolves to the *first* member with it, not to the last one that
|
||||||
[`materialize()`](materialize.md) and `parse()` keep. See the [Notes on duplicate keys](operator[].md#notes) of
|
[`materialize()`](materialize.md) and `parse()` keep. See the [Notes on duplicate keys](operator[].md#notes) of
|
||||||
`operator[]` and [Duplicate keys](../../features/json_view/differences.md#duplicate-keys) for the reasons and for how to get
|
`operator[]` and [Duplicate keys](../../features/json_view.md#duplicate-keys) for the reasons and for how to get
|
||||||
the last value.
|
the last value.
|
||||||
|
|
||||||
!!! info "Differences to `at` and `operator[]`"
|
!!! info "Differences to `at` and `operator[]`"
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ view class.
|
|||||||
- [basic_json_view](basic_json_view/index.md) - a handle to one value of a document
|
- [basic_json_view](basic_json_view/index.md) - a handle to one value of a document
|
||||||
- [get](basic_json_view/get.md) - which conversions read the view directly
|
- [get](basic_json_view/get.md) - which conversions read the view directly
|
||||||
- [view_mode](view_mode.md) - read-only or editable
|
- [view_mode](view_mode.md) - read-only or editable
|
||||||
- [Writing generic code](../features/json_view/generic_code.md) - functions and `from_json()` for views
|
- [Writing generic code](../features/json_view.md#writing-generic-code) - functions and `from_json()` for views
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ specialization.
|
|||||||
|
|
||||||
- [`json_view`](json_view.md) - a view of a value of a `json_document`
|
- [`json_view`](json_view.md) - a view of a value of a `json_document`
|
||||||
- [`ordered_json_document`](ordered_json_document.md) - the corresponding document for `ordered_json`
|
- [`ordered_json_document`](ordered_json_document.md) - the corresponding document for `ordered_json`
|
||||||
- [Zero-copy JSON views](../features/json_view/index.md) - how to parse, inspect and edit a document without building a tree
|
- [Zero-copy JSON views](../features/json_view.md) - how to parse, inspect and edit a document without building a tree
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -8,10 +8,9 @@ using json_editable_document = basic_json_document<json, view_mode::editable>;
|
|||||||
|
|
||||||
This type is an **editable** [`basic_json_document`](basic_json_document/index.md) of the default
|
This type is an **editable** [`basic_json_document`](basic_json_document/index.md) of the default
|
||||||
[`json`](json.md) specialization: in addition to everything [`json_document`](json_document.md) offers,
|
[`json`](json.md) specialization: in addition to everything [`json_document`](json_document.md) offers,
|
||||||
[`set`](basic_json_document/set.md), [`push_back`](basic_json_document/push_back.md),
|
[`set`](basic_json_document/set.md) and [`push_back`](basic_json_document/push_back.md) change values after
|
||||||
[`insert`](basic_json_document/insert.md), and [`erase`](basic_json_document/erase.md) change values after parsing,
|
parsing, without ever rewriting the source text — see [Edits](basic_json_document/index.md#edits) and
|
||||||
without ever rewriting the source text — see [Edits](basic_json_document/index.md#edits) and
|
[Editing a document](../features/json_view.md#editing-a-document).
|
||||||
[Editing a document](../features/json_view/editing.md).
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ using json_editable_view = basic_json_view<json, view_mode::editable>;
|
|||||||
This type is a [`basic_json_view`](basic_json_view/index.md) of a value of a
|
This type is a [`basic_json_view`](basic_json_view/index.md) of a value of a
|
||||||
[`json_editable_document`](json_editable_document.md). It offers the same read-only interface as
|
[`json_editable_document`](json_editable_document.md). It offers the same read-only interface as
|
||||||
[`json_view`](json_view.md); what is different is what it can be a view *of* — a value that
|
[`json_view`](json_view.md); what is different is what it can be a view *of* — a value that
|
||||||
[`set`](basic_json_document/set.md), [`push_back`](basic_json_document/push_back.md),
|
[`set`](basic_json_document/set.md) and [`push_back`](basic_json_document/push_back.md) can change, with every view
|
||||||
[`insert`](basic_json_document/insert.md), and [`erase`](basic_json_document/erase.md) can change, with every view
|
|
||||||
still referring to it seeing the change, see [Edits](basic_json_document/index.md#edits).
|
still referring to it seeing the change, see [Edits](basic_json_document/index.md#edits).
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
@@ -36,7 +35,7 @@ still referring to it seeing the change, see [Edits](basic_json_document/index.m
|
|||||||
- [`json_view`](json_view.md) - the corresponding read-only view
|
- [`json_view`](json_view.md) - the corresponding read-only view
|
||||||
- [`ordered_json_editable_view`](ordered_json_editable_view.md) - the corresponding view for
|
- [`ordered_json_editable_view`](ordered_json_editable_view.md) - the corresponding view for
|
||||||
`ordered_json_editable_document`
|
`ordered_json_editable_document`
|
||||||
- [Zero-copy JSON views](../features/json_view/editing.md) - editing a document in place and writing it back
|
- [Zero-copy JSON views](../features/json_view.md#editing-a-document) - editing a document in place and writing it back
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ This type is a [`basic_json_view`](basic_json_view/index.md) of a value of a [`j
|
|||||||
|
|
||||||
- [`json_document`](json_document.md) - the document type this view refers into
|
- [`json_document`](json_document.md) - the document type this view refers into
|
||||||
- [`ordered_json_view`](ordered_json_view.md) - the corresponding view for `ordered_json_document`
|
- [`ordered_json_view`](ordered_json_view.md) - the corresponding view for `ordered_json_document`
|
||||||
- [Zero-copy JSON views](../features/json_view/index.md) - how to parse, inspect and edit a document without building a tree
|
- [Zero-copy JSON views](../features/json_view.md) - how to parse, inspect and edit a document without building a tree
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ header. See also the [macro overview page](../../features/macros.md).
|
|||||||
UBJSON, BJData, and BSON writers
|
UBJSON, BJData, and BSON writers
|
||||||
- [**JSON_STRICT_NUL_HANDLING**](json_strict_nul_handling.md) - opt in to rejecting a NUL byte in the input instead of
|
- [**JSON_STRICT_NUL_HANDLING**](json_strict_nul_handling.md) - opt in to rejecting a NUL byte in the input instead of
|
||||||
treating it as end of input
|
treating it as end of input
|
||||||
- [**JSON_UBJSON_VALUELESS_ELEMENTS_PER_BYTE**](json_ubjson_valueless_elements_per_byte.md) - set how many elements of
|
|
||||||
UBJSON arrays of `null`, `true`, or `false` an input may announce per byte it has
|
|
||||||
|
|
||||||
## Language support
|
## Language support
|
||||||
|
|
||||||
@@ -42,8 +40,6 @@ header. See also the [macro overview page](../../features/macros.md).
|
|||||||
- [**JSON_NO_IO**](json_no_io.md) - switch off functions relying on certain C++ I/O headers
|
- [**JSON_NO_IO**](json_no_io.md) - switch off functions relying on certain C++ I/O headers
|
||||||
- [**JSON_NO_SIMD**](json_no_simd.md) - use only portable code instead of vector instructions (SSE2, SSSE3, NEON)
|
- [**JSON_NO_SIMD**](json_no_simd.md) - use only portable code instead of vector instructions (SSE2, SSSE3, NEON)
|
||||||
- [**JSON_NO_THREAD_LOCAL**](json_no_thread_local.md) - switch off the use of `thread_local` storage
|
- [**JSON_NO_THREAD_LOCAL**](json_no_thread_local.md) - switch off the use of `thread_local` storage
|
||||||
- [**JSON_RECURSION_DEPTH_LIMIT**](json_recursion_depth_limit.md) - set how many nesting levels the operations on a value
|
|
||||||
recurse into on the call stack (default 128)
|
|
||||||
- [**JSON_SKIP_UNSUPPORTED_COMPILER_CHECK**](json_skip_unsupported_compiler_check.md) - do not warn about unsupported compilers
|
- [**JSON_SKIP_UNSUPPORTED_COMPILER_CHECK**](json_skip_unsupported_compiler_check.md) - do not warn about unsupported compilers
|
||||||
- [**JSON_USE_GLOBAL_UDLS**](json_use_global_udls.md) - place user-defined string literals (UDLs) into the global namespace
|
- [**JSON_USE_GLOBAL_UDLS**](json_use_global_udls.md) - place user-defined string literals (UDLs) into the global namespace
|
||||||
- [**JSON_USE_SIMDUTF**](json_use_simdutf.md) - use the simdutf library to accelerate UTF-8 validation
|
- [**JSON_USE_SIMDUTF**](json_use_simdutf.md) - use the simdutf library to accelerate UTF-8 validation
|
||||||
|
|||||||
@@ -27,13 +27,9 @@ The default value is `0` (disabled — existing behavior is preserved).
|
|||||||
json j{obj};
|
json j{obj};
|
||||||
```
|
```
|
||||||
|
|
||||||
creates a single-element **array** `[{"key":"value"}]` instead of a copy of `obj`. For this constructor, the
|
creates a single-element **array** `[{"key":"value"}]` instead of a copy of `obj`. This behavior is
|
||||||
behavior was compiler-dependent for older compilers (GCC wrapped, Clang did not), but starting from Clang 20, both
|
compiler-dependent for older compilers (GCC wrapped, Clang did not), but starting from Clang 20, both compilers
|
||||||
compilers behave the same way.
|
behave the same way.
|
||||||
|
|
||||||
The calls `#!cpp arr.push_back({obj})` and `#!cpp arr += {obj}` are still compiler-dependent without the macro,
|
|
||||||
even with Clang 20 and later: GCC converts `{obj}` to a single-element array and appends that array, whereas Clang
|
|
||||||
appends a copy of `obj`. With the macro defined to `1`, both compilers append a copy of `obj`.
|
|
||||||
|
|
||||||
Enabling this macro opts into copy/move semantics for this case
|
Enabling this macro opts into copy/move semantics for this case
|
||||||
(see [#5074](https://github.com/nlohmann/json/issues/5074)).
|
(see [#5074](https://github.com/nlohmann/json/issues/5074)).
|
||||||
|
|||||||
@@ -34,9 +34,6 @@ or quotes.
|
|||||||
Note that enabling this macro increases the size of every JSON value by two `std::size_t` fields and adds slight runtime
|
Note that enabling this macro increases the size of every JSON value by two `std::size_t` fields and adds slight runtime
|
||||||
overhead to parsing, copying JSON value objects, and the generation of error messages for exceptions. It also causes
|
overhead to parsing, copying JSON value objects, and the generation of error messages for exceptions. It also causes
|
||||||
these values to be reported in those error messages.
|
these values to be reported in those error messages.
|
||||||
In addition, `parse()`, `accept()`, and `sax_parse()` no longer use the
|
|
||||||
[faster path for input in one block of memory](../../features/parsing/index.md#input-sources-and-performance), so
|
|
||||||
parsing a string or a buffer is slower than without the macro.
|
|
||||||
|
|
||||||
If [`JSON_DIAGNOSTICS`](json_diagnostics.md) is also set, the message contains the path and the byte range, such as
|
If [`JSON_DIAGNOSTICS`](json_diagnostics.md) is also set, the message contains the path and the byte range, such as
|
||||||
`(/1) (bytes 4-8)`. An exception about the root value has no path and only the range, such as `(bytes 0-4)`.
|
`(/1) (bytes 4-8)`. An exception about the root value has no path and only the range, such as `(bytes 0-4)`.
|
||||||
@@ -125,5 +122,3 @@ When the macro is not defined, the library will define it to its default value.
|
|||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 3.12.0.
|
- Added in version 3.12.0.
|
||||||
- Fixed in version 3.13.0: in version 3.12.0, [`start_pos()`](../basic_json/start_pos.md) of a string that contains
|
|
||||||
escape sequences was too large; it is now the position of the opening `"`.
|
|
||||||
Loaded 100 of 299 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user