mirror of
https://github.com/nlohmann/json.git
synced 2026-06-18 18:34:17 +00:00
Compare commits
215 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 02dfbea39d | |||
| a5f8e230ac | |||
| d8ebaf61d7 | |||
| a39f33b951 | |||
| e4bdf1be72 | |||
| d10879bca8 | |||
| 484483acad | |||
| 584e6b1cfb | |||
| a69a42a930 | |||
| 77388b95fc | |||
| e054d4df94 | |||
| d96329f8d6 | |||
| 1d7688aef2 | |||
| 58cfecf7f7 | |||
| 47202c804a | |||
| 4e5fa3bdd2 | |||
| cba5dc0ed8 | |||
| e08b3cab68 | |||
| 65c52ae1c8 | |||
| b1bb9fce0c | |||
| bb5404bb86 | |||
| 630beaeb05 | |||
| 5a05627b1f | |||
| 85cb7ea9aa | |||
| 7192763f15 | |||
| 93e49decbd | |||
| a0a4e7cc0b | |||
| 216c50365e | |||
| f0bf4c731a | |||
| 4fad446897 | |||
| e0f8cdfb7f | |||
| 62f3b41b30 | |||
| fd17b0889e | |||
| a038cc4ef8 | |||
| 889dd78eb9 | |||
| a64fc21243 | |||
| 0b5010242c | |||
| bdbafc52c0 | |||
| 98386eb08b | |||
| 75498c1fbd | |||
| 8d849594f8 | |||
| 53e9b56ec3 | |||
| 94c73171b3 | |||
| 43c8ea198f | |||
| 342ebab83e | |||
| a5381281bf | |||
| a8e7442b29 | |||
| 05646c0db6 | |||
| 8f3d9a5e97 | |||
| 3946872265 | |||
| f36f976e73 | |||
| 9a737481ae | |||
| 2413fc0b1d | |||
| eba0a92bfb | |||
| 75ade57e9c | |||
| 707c012e9c | |||
| f534f4f75e | |||
| 7d0218f738 | |||
| 80af29a39a | |||
| 533228a88c | |||
| d293f604bf | |||
| 2a1a5a7b1a | |||
| aecccbf57e | |||
| ad12e0ebed | |||
| d9cffc35ad | |||
| 313b85d199 | |||
| 4b78c06368 | |||
| 4fd26a4ead | |||
| 95cfd7a3b5 | |||
| 8167d2f641 | |||
| e5e06e1a7b | |||
| 904592d2a8 | |||
| f8eee1bb79 | |||
| 21b53746c9 | |||
| 553c314fb8 | |||
| fa02f62316 | |||
| ae4c81858b | |||
| 5aef01cca1 | |||
| e313c6f6ba | |||
| 17d1dd9964 | |||
| 25f48639c7 | |||
| deb4c4f69f | |||
| 156ce8dcb4 | |||
| 5ed07097fa | |||
| e3014f162a | |||
| 2bb9d59fde | |||
| 457bc283ff | |||
| 8f75700141 | |||
| 515d994acb | |||
| 14374af9e5 | |||
| d6e6b21f16 | |||
| 30b28175e4 | |||
| 7c2b2ede37 | |||
| 8c7a7d474f | |||
| ae9c8d82ca | |||
| 6a4282395f | |||
| 9f35919110 | |||
| 75d9166a68 | |||
| ea3950e040 | |||
| 38819a9b04 | |||
| 02ac0d6525 | |||
| c89e8fac63 | |||
| b825d3dafb | |||
| baceef2286 | |||
| 0422165315 | |||
| 942d0225c5 | |||
| a0e9fb1e63 | |||
| d88916a04e | |||
| 2b40a69a25 | |||
| 8fb6fca692 | |||
| 682b14bb57 | |||
| d9878dff1c | |||
| 49026f7999 | |||
| 667c143262 | |||
| af524ab666 | |||
| 11627521ae | |||
| 63bc495cf8 | |||
| 9c38185167 | |||
| c8b66cf36e | |||
| 0c9b68e110 | |||
| 8deac49f50 | |||
| 8c5344eeb2 | |||
| 034f3ecdc6 | |||
| e137f2ac88 | |||
| 49d5c45767 | |||
| bccdfad507 | |||
| cda9c1e3bd | |||
| a6a92c19bf | |||
| 4f8ee1d5e0 | |||
| cddd4b831e | |||
| 3d8aa21d5f | |||
| 29913ca760 | |||
| df263544ed | |||
| 11cc676142 | |||
| 54be9b04f0 | |||
| 1cc56b2dcd | |||
| 22ac227155 | |||
| 80069a970f | |||
| 9f334eccf0 | |||
| d5d2f99a6d | |||
| 8ae9bb34f4 | |||
| 8499f4f00f | |||
| a63795caf1 | |||
| 0d69a72167 | |||
| 2eb21b0eb0 | |||
| 2566828ed5 | |||
| 3ed64e502a | |||
| 9810c39408 | |||
| 44bee1b138 | |||
| 60b39ce2d7 | |||
| 5b5729584c | |||
| f8913c7954 | |||
| 44b5a6d535 | |||
| df8605a4c1 | |||
| 867127c2f4 | |||
| 07babee604 | |||
| 87a3e4de99 | |||
| b74e119bc6 | |||
| 4bc4e37f4f | |||
| ec857100a5 | |||
| 22db828de4 | |||
| 000db7a6a2 | |||
| 1fd00198ec | |||
| 6131e52a5b | |||
| c711517c00 | |||
| cb13999032 | |||
| 4106af8d92 | |||
| 52d3f6e034 | |||
| cd783971aa | |||
| d275e706ca | |||
| 89f0225dc6 | |||
| bdc50d513f | |||
| 32771c5ea3 | |||
| e00484f866 | |||
| c5cc4face3 | |||
| a3211ab3ca | |||
| efcf9efb4f | |||
| 55abcb5c0f | |||
| c637a8b453 | |||
| 095d2b3a16 | |||
| 9d86144cc0 | |||
| f0aa454655 | |||
| 30d27df61c | |||
| d33ecd3f3b | |||
| d19060e6c7 | |||
| 98ac4d85be | |||
| b7f741165b | |||
| d70e46bc65 | |||
| b451735fe7 | |||
| 568b708fd4 | |||
| c633693d3e | |||
| cf16c5ab9f | |||
| b19f058465 | |||
| 5f77df4e22 | |||
| 64ebc6d511 | |||
| 82f4f70669 | |||
| 68c25aec60 | |||
| ac0133ea89 | |||
| 281d1e929b | |||
| 7421ac31a7 | |||
| 4b17f90f65 | |||
| 2d9a251266 | |||
| 3cca3ad210 | |||
| 828c891427 | |||
| 46e7cd3dc2 | |||
| 6f6be39332 | |||
| e02de2f971 | |||
| 410c96228c | |||
| 4e518d43d7 | |||
| 230bfd15a2 | |||
| e9391dc5bc | |||
| 697c7e557c | |||
| 9110918cf8 | |||
| 0a8b48ac6a | |||
| dff2b4756c |
+9
-1
@@ -1,4 +1,5 @@
|
|||||||
# TODO: The first three checks are only removed to get the CI going. They have to be addressed at some point.
|
# TODO: The first three checks are only removed to get the CI going. They have to be addressed at some point.
|
||||||
|
# TODO: portability-avoid-pragma-once: should be fixed eventually
|
||||||
|
|
||||||
Checks: '*,
|
Checks: '*,
|
||||||
|
|
||||||
@@ -21,6 +22,7 @@ Checks: '*,
|
|||||||
-cppcoreguidelines-avoid-magic-numbers,
|
-cppcoreguidelines-avoid-magic-numbers,
|
||||||
-cppcoreguidelines-avoid-non-const-global-variables,
|
-cppcoreguidelines-avoid-non-const-global-variables,
|
||||||
-cppcoreguidelines-macro-usage,
|
-cppcoreguidelines-macro-usage,
|
||||||
|
-cppcoreguidelines-pro-bounds-avoid-unchecked-container-access,
|
||||||
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
|
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
|
||||||
-cppcoreguidelines-pro-bounds-constant-array-index,
|
-cppcoreguidelines-pro-bounds-constant-array-index,
|
||||||
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
|
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
|
||||||
@@ -33,6 +35,7 @@ Checks: '*,
|
|||||||
-fuchsia-overloaded-operator,
|
-fuchsia-overloaded-operator,
|
||||||
-google-explicit-constructor,
|
-google-explicit-constructor,
|
||||||
-google-readability-function-size,
|
-google-readability-function-size,
|
||||||
|
-google-runtime-float,
|
||||||
-google-runtime-int,
|
-google-runtime-int,
|
||||||
-google-runtime-references,
|
-google-runtime-references,
|
||||||
-hicpp-avoid-goto,
|
-hicpp-avoid-goto,
|
||||||
@@ -44,6 +47,8 @@ Checks: '*,
|
|||||||
-hicpp-uppercase-literal-suffix,
|
-hicpp-uppercase-literal-suffix,
|
||||||
-llvm-header-guard,
|
-llvm-header-guard,
|
||||||
-llvm-include-order,
|
-llvm-include-order,
|
||||||
|
-llvm-prefer-static-over-anonymous-namespace,
|
||||||
|
-llvm-use-ranges,
|
||||||
-llvmlibc-*,
|
-llvmlibc-*,
|
||||||
-misc-use-anonymous-namespace,
|
-misc-use-anonymous-namespace,
|
||||||
-misc-confusable-identifiers,
|
-misc-confusable-identifiers,
|
||||||
@@ -59,13 +64,16 @@ Checks: '*,
|
|||||||
-modernize-use-std-numbers,
|
-modernize-use-std-numbers,
|
||||||
-modernize-use-trailing-return-type,
|
-modernize-use-trailing-return-type,
|
||||||
-performance-enum-size,
|
-performance-enum-size,
|
||||||
|
-portability-avoid-pragma-once,
|
||||||
-readability-function-cognitive-complexity,
|
-readability-function-cognitive-complexity,
|
||||||
-readability-function-size,
|
-readability-function-size,
|
||||||
-readability-identifier-length,
|
-readability-identifier-length,
|
||||||
-readability-magic-numbers,
|
-readability-magic-numbers,
|
||||||
-readability-redundant-access-specifiers,
|
-readability-redundant-access-specifiers,
|
||||||
|
-readability-redundant-parentheses,
|
||||||
-readability-simplify-boolean-expr,
|
-readability-simplify-boolean-expr,
|
||||||
-readability-uppercase-literal-suffix'
|
-readability-uppercase-literal-suffix,
|
||||||
|
-readability-use-concise-preprocessor-directives'
|
||||||
|
|
||||||
CheckOptions:
|
CheckOptions:
|
||||||
- key: hicpp-special-member-functions.AllowSoleDefaultDtor
|
- key: hicpp-special-member-functions.AllowSoleDefaultDtor
|
||||||
|
|||||||
+16
-13
@@ -1,7 +1,7 @@
|
|||||||
# Contribution Guidelines
|
# Contribution Guidelines
|
||||||
|
|
||||||
Thank you for your interest in contributing to this project! What began as an exercise to explore the exciting features
|
Thank you for your interest in contributing to this project! What began as an exercise to explore the exciting features
|
||||||
of C++11 has evolved into a [widely-used](https://json.nlohmann.me/home/customers/) JSON library. I truly appreciate all
|
of C++11 has evolved into a [widely used](https://json.nlohmann.me/home/customers/) JSON library. I truly appreciate all
|
||||||
the contributions from the community, whether it's proposing features, identifying bugs, or fixing mistakes! To ensure
|
the contributions from the community, whether it's proposing features, identifying bugs, or fixing mistakes! To ensure
|
||||||
that our collaboration is efficient and effective, please follow these guidelines.
|
that our collaboration is efficient and effective, please follow these guidelines.
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ Clearly describe the issue:
|
|||||||
|
|
||||||
- If it is a bug, please describe how to **reproduce** it. If possible, attach a _complete example_ which demonstrates
|
- If it is a bug, please describe how to **reproduce** it. If possible, attach a _complete example_ which demonstrates
|
||||||
the error. Please also state what you **expected** to happen instead of the error.
|
the error. Please also state what you **expected** to happen instead of the error.
|
||||||
- If you propose a change or addition, try to give an **example** how the improved code could look like or how to use
|
- If you propose a change or addition, try to give an **example** what the improved code could look like or how to use
|
||||||
it.
|
it.
|
||||||
- If you found a compilation error, please tell us which **compiler** (version and operating system) you used and paste
|
- If you found a compilation error, please tell us which **compiler** (version and operating system) you used and paste
|
||||||
the (relevant part of) the error messages to the ticket.
|
the (relevant part of) the error messages to the ticket.
|
||||||
@@ -66,21 +66,21 @@ certification that he or she has the right to submit the patch for inclusion int
|
|||||||
|
|
||||||
### Describe your changes
|
### Describe your changes
|
||||||
|
|
||||||
This library is primarily maintained as a spare-time project. As such, I can not make any guarantee how quickly changes
|
This library is primarily maintained as a spare-time project. As such, I cannot make any guarantee how quickly changes
|
||||||
are merged and released. Therefore, it is very important to make the review as smooth as possible by explaining not only
|
are merged and released. Therefore, it is very important to make the review as smooth as possible by explaining not only
|
||||||
_what_ you changed, but _why_. This rationale can be very valuable down the road when improvements or bugs are discussed
|
_what_ you changed, but _why_. This rationale can be very valuable down the road when improvements or bugs are discussed
|
||||||
years later.
|
years later.
|
||||||
|
|
||||||
### Reference existing issues
|
### Reference an existing issue
|
||||||
|
|
||||||
[Link a pull request to an issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/linking-a-pull-request-to-an-issue)
|
[Link a pull request to an issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/linking-a-pull-request-to-an-issue)
|
||||||
to clarify that a fix is forthcoming and which issue can be closed after merging. Only few cases (e.g., fixing typos)
|
to clarify that a fix is forthcoming and which issue can be closed after merging. Only a few cases (e.g., fixing typos)
|
||||||
don’t require prior discussions.
|
do not require prior discussions.
|
||||||
|
|
||||||
### Write tests
|
### Write tests
|
||||||
|
|
||||||
The library has an extensive test suite that currently covers [100 %](https://coveralls.io/github/nlohmann/json) of the
|
The library has an extensive test suite that currently covers [100 %](https://coveralls.io/github/nlohmann/json) of the
|
||||||
library's code. These test are crucial to maintain API stability and give future contributors confidence that they do
|
library's code. These tests are crucial to maintain API stability and give future contributors confidence that they do
|
||||||
not accidentally break things. As Titus Winters aptly put it:
|
not accidentally break things. As Titus Winters aptly put it:
|
||||||
|
|
||||||
> If you liked it, you should have put a test on it.
|
> If you liked it, you should have put a test on it.
|
||||||
@@ -118,14 +118,14 @@ exception into account.
|
|||||||
#### Coverage
|
#### Coverage
|
||||||
|
|
||||||
If test coverage decreases, an automatic warning comment will be posted on the pull request. You can access a code
|
If test coverage decreases, an automatic warning comment will be posted on the pull request. You can access a code
|
||||||
coverage report as artifact to the “Ubuntu” workflow.
|
coverage report as an artifact to the “Ubuntu” workflow.
|
||||||
|
|
||||||
### Update the documentation
|
### Update the documentation
|
||||||
|
|
||||||
The [main documentation](https://json.nlohmann.me) of the library is generated from the files
|
The [main documentation](https://json.nlohmann.me) of the library is generated from the files
|
||||||
[`docs/mkdocs/docs`](https://github.com/nlohmann/json/blob/develop/docs/mkdocs/docs). This folder contains dedicated
|
[`docs/mkdocs/docs`](https://github.com/nlohmann/json/blob/develop/docs/mkdocs/docs). This folder contains dedicated
|
||||||
pages for [certain features](https://github.com/nlohmann/json/tree/develop/docs/mkdocs/docs/features), a list of
|
pages for [certain features](https://github.com/nlohmann/json/tree/develop/docs/mkdocs/docs/features), a list of
|
||||||
[all exceptions](https://github.com/nlohmann/json/blob/develop/docs/mkdocs/docs/home/exceptions.md), and an
|
[all exceptions](https://github.com/nlohmann/json/blob/develop/docs/mkdocs/docs/home/exceptions.md), and
|
||||||
[extensive API documentation](https://github.com/nlohmann/json/tree/develop/docs/mkdocs/docs/api) with details on every
|
[extensive API documentation](https://github.com/nlohmann/json/tree/develop/docs/mkdocs/docs/api) with details on every
|
||||||
public API function.
|
public API function.
|
||||||
|
|
||||||
@@ -136,7 +136,7 @@ make install_venv -C docs/mkdocs
|
|||||||
make serve -C docs/mkdocs
|
make serve -C docs/mkdocs
|
||||||
```
|
```
|
||||||
|
|
||||||
The documentation will then available at <http://127.0.0.1:8000/>. See the documentation of
|
The documentation will then be available at <http://127.0.0.1:8000/>. See the documentation of
|
||||||
[mkdocs](https://www.mkdocs.org) and [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/) for more
|
[mkdocs](https://www.mkdocs.org) and [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/) for more
|
||||||
information.
|
information.
|
||||||
|
|
||||||
@@ -153,6 +153,9 @@ files directly; instead, modify the include/nlohmann sources and regenerate the
|
|||||||
make amalgamate
|
make amalgamate
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Running `make amalgamate` will also apply automatic formatting to the source files using
|
||||||
|
[`Artistic Style`](https://astyle.sourceforge.net/). This formatting may modify your source files in-place. Be certain to review and commit any changes to avoid unintended formatting diffs in commits.
|
||||||
|
|
||||||
## Recommended documentation
|
## Recommended documentation
|
||||||
|
|
||||||
- The library’s [README file](https://github.com/nlohmann/json/blob/master/README.md) is an excellent starting point to
|
- The library’s [README file](https://github.com/nlohmann/json/blob/master/README.md) is an excellent starting point to
|
||||||
@@ -184,8 +187,8 @@ API of the 3.x.y version is broken. This includes:
|
|||||||
Although these guidelines may seem restrictive, they are essential for maintaining the library’s utility.
|
Although these guidelines may seem restrictive, they are essential for maintaining the library’s utility.
|
||||||
|
|
||||||
Breaking changes may be introduced when they are guarded with a feature macro such as
|
Breaking changes may be introduced when they are guarded with a feature macro such as
|
||||||
[`JSON_USE_IMPLICIT_CONVERSIONS`](https://json.nlohmann.me/api/macros/json_use_implicit_conversions/) which allows to
|
[`JSON_USE_IMPLICIT_CONVERSIONS`](https://json.nlohmann.me/api/macros/json_use_implicit_conversions/) which allows
|
||||||
selectively change the behavior of the library. In next steps, the current behavior can then be deprecated. Using
|
selectively changing the behavior of the library. In next steps, the current behavior can then be deprecated. Using
|
||||||
feature macros then allows users to test their code against the library in the next major release.
|
feature macros then allows users to test their code against the library in the next major release.
|
||||||
|
|
||||||
### Break C++11 language conformance
|
### Break C++11 language conformance
|
||||||
@@ -211,7 +214,7 @@ The following areas really need contribution and are always welcomed:
|
|||||||
- Extending the **continuous integration** toward more exotic compilers such as Android NDK, Intel's Compiler, or the
|
- Extending the **continuous integration** toward more exotic compilers such as Android NDK, Intel's Compiler, or the
|
||||||
bleeding-edge versions Clang.
|
bleeding-edge versions Clang.
|
||||||
- Improving the efficiency of the **JSON parser**. The current parser is implemented as a naive recursive descent parser
|
- Improving the efficiency of the **JSON parser**. The current parser is implemented as a naive recursive descent parser
|
||||||
with hand coded string handling. More sophisticated approaches like LALR parsers would be really appreciated. That
|
with hand-coded string handling. More sophisticated approaches like LALR parsers would be really appreciated. That
|
||||||
said, parser generators like Bison or ANTLR do not play nice with single-header files -- I really would like to keep
|
said, parser generators like Bison or ANTLR do not play nice with single-header files -- I really would like to keep
|
||||||
the parser inside the `json.hpp` header, and I am not aware of approaches similar to [`re2c`](http://re2c.org) for
|
the parser inside the `json.hpp` header, and I am not aware of approaches similar to [`re2c`](http://re2c.org) for
|
||||||
parsing.
|
parsing.
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ body:
|
|||||||
Note that this form is for bug reports only. Please
|
Note that this form is for bug reports only. Please
|
||||||
[open a discussion](https://github.com/nlohmann/json/discussions/new)
|
[open a discussion](https://github.com/nlohmann/json/discussions/new)
|
||||||
for questions, feature requests, or support requests.
|
for questions, feature requests, or support requests.
|
||||||
|
**Please check the [FAQ](https://json.nlohmann.me/home/faq/) before
|
||||||
|
reporting an issue.** Common questions are answered there.
|
||||||
- type: textarea
|
- type: textarea
|
||||||
id: summary
|
id: summary
|
||||||
attributes:
|
attributes:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
[Describe your pull request here. Please read the text below the line, and make sure you follow the checklist.]
|
[Describe your pull request here. Please read the text below the line and make sure you follow the checklist.]
|
||||||
|
|
||||||
- [ ] The changes are described in detail, both the what and why.
|
- [ ] The changes are described in detail, both the what and why.
|
||||||
- [ ] If applicable, an [existing issue](https://github.com/nlohmann/json/issues) is referenced.
|
- [ ] If applicable, an [existing issue](https://github.com/nlohmann/json/issues) is referenced.
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
|
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ jobs:
|
|||||||
mkdir -p ./pr
|
mkdir -p ./pr
|
||||||
echo ${{ github.event.number }} > ./pr/number
|
echo ${{ github.event.number }} > ./pr/number
|
||||||
echo ${{ github.event.pull_request.user.login }} > ./pr/author
|
echo ${{ github.event.pull_request.user.login }} > ./pr/author
|
||||||
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||||
with:
|
with:
|
||||||
name: pr
|
name: pr
|
||||||
path: pr/
|
path: pr/
|
||||||
@@ -34,18 +34,18 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
|
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: Checkout pull request
|
- name: Checkout pull request
|
||||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
with:
|
with:
|
||||||
path: main
|
path: main
|
||||||
ref: ${{ github.event.pull_request.head.sha }}
|
ref: ${{ github.event.pull_request.head.sha }}
|
||||||
|
|
||||||
- name: Checkout tools
|
- name: Checkout tools
|
||||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
with:
|
with:
|
||||||
path: tools
|
path: tools
|
||||||
ref: develop
|
ref: develop
|
||||||
|
|||||||
@@ -6,29 +6,29 @@ permissions:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Fuzzing:
|
Fuzzing:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
|
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: Build Fuzzers
|
- name: Build Fuzzers
|
||||||
id: build
|
id: build
|
||||||
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@57fe4475324c5506adbfecdcdd2917f65c86ee9e # master
|
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
|
||||||
with:
|
with:
|
||||||
oss-fuzz-project-name: 'json'
|
oss-fuzz-project-name: 'json'
|
||||||
dry-run: false
|
dry-run: false
|
||||||
language: c++
|
language: c++
|
||||||
- name: Run Fuzzers
|
- name: Run Fuzzers
|
||||||
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@57fe4475324c5506adbfecdcdd2917f65c86ee9e # master
|
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
|
||||||
with:
|
with:
|
||||||
oss-fuzz-project-name: 'json'
|
oss-fuzz-project-name: 'json'
|
||||||
fuzz-seconds: 300
|
fuzz-seconds: 300
|
||||||
dry-run: false
|
dry-run: false
|
||||||
language: c++
|
language: c++
|
||||||
- name: Upload Crash
|
- name: Upload Crash
|
||||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||||
if: failure() && steps.build.outcome == 'success'
|
if: failure() && steps.build.outcome == 'success'
|
||||||
with:
|
with:
|
||||||
name: artifacts
|
name: artifacts
|
||||||
|
|||||||
@@ -27,23 +27,23 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
|
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@28deaeda66b76a05916b6923827895f2b14ab387 # v3.28.16
|
uses: github/codeql-action/init@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4.36.2
|
||||||
with:
|
with:
|
||||||
languages: c-cpp
|
languages: c-cpp
|
||||||
|
|
||||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
# If this step fails, then you should remove it and run the build manually (see below)
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
- name: Autobuild
|
- name: Autobuild
|
||||||
uses: github/codeql-action/autobuild@28deaeda66b76a05916b6923827895f2b14ab387 # v3.28.16
|
uses: github/codeql-action/autobuild@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4.36.2
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@28deaeda66b76a05916b6923827895f2b14ab387 # v3.28.16
|
uses: github/codeql-action/analyze@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4.36.2
|
||||||
|
|||||||
@@ -19,12 +19,12 @@ jobs:
|
|||||||
pull-requests: write
|
pull-requests: write
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
|
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: 'Download artifact'
|
- name: 'Download artifact'
|
||||||
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
|
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
|
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
|
||||||
@@ -46,7 +46,7 @@ jobs:
|
|||||||
- run: unzip pr.zip
|
- run: unzip pr.zip
|
||||||
|
|
||||||
- name: 'Comment on PR'
|
- name: 'Comment on PR'
|
||||||
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
|
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
script: |
|
script: |
|
||||||
|
|||||||
@@ -17,11 +17,11 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
|
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: 'Checkout Repository'
|
- name: 'Checkout Repository'
|
||||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
- name: 'Dependency Review'
|
- name: 'Dependency Review'
|
||||||
uses: actions/dependency-review-action@ce3cf9537a52e8119d91fd484ab5b8a807627bf8 # v4.6.0
|
uses: actions/dependency-review-action@a1d282b36b6f3519aa1f3fc636f609c47dddb294 # v5.0.0
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
# This workflow uses actions that are not certified by GitHub.
|
||||||
|
# They are provided by a third-party and are governed by
|
||||||
|
# separate terms of service, privacy policy, and support
|
||||||
|
# documentation.
|
||||||
|
|
||||||
|
name: flawfinder
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "develop" ]
|
||||||
|
pull_request:
|
||||||
|
# The branches below must be a subset of the branches above
|
||||||
|
branches: [ "develop" ]
|
||||||
|
schedule:
|
||||||
|
- cron: '41 14 * * 3'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
flawfinder:
|
||||||
|
name: Flawfinder
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
actions: read
|
||||||
|
contents: read
|
||||||
|
security-events: write
|
||||||
|
steps:
|
||||||
|
- name: Harden Runner
|
||||||
|
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
|
||||||
|
with:
|
||||||
|
egress-policy: audit
|
||||||
|
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
|
|
||||||
|
- name: flawfinder_scan
|
||||||
|
uses: david-a-wheeler/flawfinder@c4216b74cf2639ffa98503768bd6e4299b5440c9 # v2.0.20
|
||||||
|
with:
|
||||||
|
arguments: '--sarif ./'
|
||||||
|
output: 'flawfinder_results.sarif'
|
||||||
|
|
||||||
|
- name: Upload analysis results to GitHub Security tab
|
||||||
|
uses: github/codeql-action/upload-sarif@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4
|
||||||
|
with:
|
||||||
|
sarif_file: ${{github.workspace}}/flawfinder_results.sarif
|
||||||
@@ -17,10 +17,10 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
|
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- uses: srvaroa/labeler@e216fb40e2e6d3b17d90fb1d950f98bee92f65ce # master
|
- uses: srvaroa/labeler@e8fbb2561481ef6e711a770f0234e9379dc76892 # master
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
|
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
|
|||||||
+24
-23
@@ -27,7 +27,7 @@ jobs:
|
|||||||
# DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
# DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
||||||
#
|
#
|
||||||
# steps:
|
# steps:
|
||||||
# - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
# - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
# - name: Run CMake
|
# - name: Run CMake
|
||||||
# run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON
|
# run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON
|
||||||
# - name: Build
|
# - name: Build
|
||||||
@@ -45,7 +45,7 @@ jobs:
|
|||||||
# DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
# DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
||||||
#
|
#
|
||||||
# steps:
|
# steps:
|
||||||
# - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
# - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
# - name: Run CMake
|
# - name: Run CMake
|
||||||
# run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON
|
# run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON
|
||||||
# - name: Build
|
# - name: Build
|
||||||
@@ -53,33 +53,34 @@ jobs:
|
|||||||
# - name: Test
|
# - name: Test
|
||||||
# run: cd build ; ctest -j 10 --output-on-failure
|
# run: cd build ; ctest -j 10 --output-on-failure
|
||||||
|
|
||||||
macos-13:
|
# macos-13 is deprecated (https://github.com/actions/runner-images/issues/13046)
|
||||||
runs-on: macos-13 # https://github.com/actions/runner-images/blob/main/images/macos/macos-13-Readme.md
|
# macos-13:
|
||||||
strategy:
|
# runs-on: macos-13 # https://github.com/actions/runner-images/blob/main/images/macos/macos-13-Readme.md
|
||||||
matrix:
|
# strategy:
|
||||||
xcode: ['14.1', '14.2', '14.3', '14.3.1', '15.0.1', '15.1', '15.2']
|
# matrix:
|
||||||
env:
|
# xcode: ['14.1', '14.2', '14.3', '14.3.1', '15.0.1', '15.1', '15.2']
|
||||||
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
# env:
|
||||||
|
# DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
||||||
steps:
|
#
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
# steps:
|
||||||
- name: Run CMake
|
# - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON
|
# - name: Run CMake
|
||||||
- name: Build
|
# run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON
|
||||||
run: cmake --build build --parallel 10
|
# - name: Build
|
||||||
- name: Test
|
# run: cmake --build build --parallel 10
|
||||||
run: cd build ; ctest -j 10 --output-on-failure
|
# - name: Test
|
||||||
|
# run: cd build ; ctest -j 10 --output-on-failure
|
||||||
|
|
||||||
macos-14:
|
macos-14:
|
||||||
runs-on: macos-14 # https://github.com/actions/runner-images/blob/main/images/macos/macos-14-Readme.md
|
runs-on: macos-14 # https://github.com/actions/runner-images/blob/main/images/macos/macos-14-Readme.md
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
xcode: ['15.3', '15.4']
|
xcode: ['15.0.1', '15.1', '15.2', '15.3', '15.4']
|
||||||
env:
|
env:
|
||||||
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON
|
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -91,12 +92,12 @@ jobs:
|
|||||||
runs-on: macos-15 # https://github.com/actions/runner-images/blob/main/images/macos/macos-15-Readme.md
|
runs-on: macos-15 # https://github.com/actions/runner-images/blob/main/images/macos/macos-15-Readme.md
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
xcode: ['16.0', '16.1', '16.2']
|
xcode: ['16.0', '16.1', '16.2', '16.3', '16.4', '26.0.1']
|
||||||
env:
|
env:
|
||||||
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON
|
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -111,7 +112,7 @@ jobs:
|
|||||||
standard: [11, 14, 17, 20, 23, 26]
|
standard: [11, 14, 17, 20, 23, 26]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_TestStandards=${{ matrix.standard }}
|
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_TestStandards=${{ matrix.standard }}
|
||||||
- name: Build
|
- name: Build
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ jobs:
|
|||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
|
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
|
|
||||||
- name: Install virtual environment
|
- name: Install virtual environment
|
||||||
run: make install_venv -C docs/mkdocs
|
run: make install_venv -C docs/mkdocs
|
||||||
@@ -40,7 +40,7 @@ jobs:
|
|||||||
run: make build -C docs/mkdocs
|
run: make build -C docs/mkdocs
|
||||||
|
|
||||||
- name: Deploy documentation
|
- name: Deploy documentation
|
||||||
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0
|
uses: peaceiris/actions-gh-pages@84c30a85c19949d7eee79c4ff27748b70285e453 # v4.1.0
|
||||||
with:
|
with:
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
publish_dir: ./docs/mkdocs/site
|
publish_dir: ./docs/mkdocs/site
|
||||||
|
|||||||
@@ -36,17 +36,17 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
|
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: "Checkout code"
|
- name: "Checkout code"
|
||||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
- name: "Run analysis"
|
- name: "Run analysis"
|
||||||
uses: ossf/scorecard-action@f49aabe0b5af0936a0987cfb85d86b75731b0186 # v2.4.1
|
uses: ossf/scorecard-action@4eaacf0543bb3f2c246792bd56e8cdeffafb205a # v2.4.3
|
||||||
with:
|
with:
|
||||||
results_file: results.sarif
|
results_file: results.sarif
|
||||||
results_format: sarif
|
results_format: sarif
|
||||||
@@ -68,7 +68,7 @@ jobs:
|
|||||||
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
|
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
|
||||||
# format to the repository Actions tab.
|
# format to the repository Actions tab.
|
||||||
- name: "Upload artifact"
|
- name: "Upload artifact"
|
||||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||||
with:
|
with:
|
||||||
name: SARIF file
|
name: SARIF file
|
||||||
path: results.sarif
|
path: results.sarif
|
||||||
@@ -76,6 +76,6 @@ jobs:
|
|||||||
|
|
||||||
# Upload the results to GitHub's code scanning dashboard.
|
# Upload the results to GitHub's code scanning dashboard.
|
||||||
- name: "Upload to code-scanning"
|
- name: "Upload to code-scanning"
|
||||||
uses: github/codeql-action/upload-sarif@28deaeda66b76a05916b6923827895f2b14ab387 # v3.28.16
|
uses: github/codeql-action/upload-sarif@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4.36.2
|
||||||
with:
|
with:
|
||||||
sarif_file: results.sarif
|
sarif_file: results.sarif
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
# This workflow uses actions that are not certified by GitHub.
|
||||||
|
# They are provided by a third-party and are governed by
|
||||||
|
# separate terms of service, privacy policy, and support
|
||||||
|
# documentation.
|
||||||
|
|
||||||
|
# This workflow file requires a free account on Semgrep.dev to
|
||||||
|
# manage rules, file ignores, notifications, and more.
|
||||||
|
#
|
||||||
|
# See https://semgrep.dev/docs
|
||||||
|
|
||||||
|
name: Semgrep
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "develop" ]
|
||||||
|
pull_request:
|
||||||
|
# The branches below must be a subset of the branches above
|
||||||
|
branches: [ "develop" ]
|
||||||
|
schedule:
|
||||||
|
- cron: '23 2 * * 4'
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
semgrep:
|
||||||
|
permissions:
|
||||||
|
contents: read # for actions/checkout to fetch code
|
||||||
|
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
|
||||||
|
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
|
||||||
|
name: Scan
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Harden Runner
|
||||||
|
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
|
||||||
|
with:
|
||||||
|
egress-policy: audit
|
||||||
|
|
||||||
|
# Checkout project source
|
||||||
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
|
|
||||||
|
# Scan code using project's configuration on https://semgrep.dev/manage
|
||||||
|
- uses: returntocorp/semgrep-action@713efdd345f3035192eaa63f56867b88e63e4e5d
|
||||||
|
with:
|
||||||
|
publishToken: ${{ secrets.SEMGREP_APP_TOKEN }}
|
||||||
|
publishDeployment: ${{ secrets.SEMGREP_DEPLOYMENT_ID }}
|
||||||
|
generateSarif: "1"
|
||||||
|
|
||||||
|
# Upload SARIF file generated in previous step
|
||||||
|
- name: Upload SARIF file
|
||||||
|
uses: github/codeql-action/upload-sarif@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4
|
||||||
|
with:
|
||||||
|
sarif_file: semgrep.sarif
|
||||||
|
if: always()
|
||||||
@@ -16,11 +16,11 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
|
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- uses: actions/stale@5bef64f19d7facfb25b37b414482c7164d639639 # v9.1.0
|
- uses: actions/stale@eb5cf3af3ac0a1aa4c9c45633dd1ae542a27a899 # v10.3.0
|
||||||
with:
|
with:
|
||||||
stale-issue-label: 'state: stale'
|
stale-issue-label: 'state: stale'
|
||||||
stale-pr-label: 'state: stale'
|
stale-pr-label: 'state: stale'
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: gcc:latest
|
container: gcc:latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@57c20a23a6cac5b90f31864439996e5b206df9dc # v4.0.1
|
uses: lukka/get-cmake@591817e96fcad43505fb4eae36172462abb3a42e # v4.3.3
|
||||||
- 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
|
||||||
@@ -33,7 +33,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -46,15 +46,15 @@ jobs:
|
|||||||
target: [ci_test_amalgamation, ci_test_single_header, ci_cppcheck, ci_cpplint, ci_reproducible_tests, ci_non_git_tests, ci_offline_testdata, ci_reuse_compliance, ci_test_valgrind]
|
target: [ci_test_amalgamation, ci_test_single_header, ci_cppcheck, ci_cpplint, ci_reproducible_tests, ci_non_git_tests, ci_offline_testdata, ci_reuse_compliance, ci_test_valgrind]
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
|
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: Install Valgrind
|
- name: Install Valgrind
|
||||||
run: sudo apt-get update ; sudo apt-get install -y valgrind
|
run: sudo apt-get update ; sudo apt-get install -y valgrind
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@57c20a23a6cac5b90f31864439996e5b206df9dc # v4.0.1
|
uses: lukka/get-cmake@591817e96fcad43505fb4eae36172462abb3a42e # v4.3.3
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -69,9 +69,9 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Install git, clang-tools, iwyu (ci_single_binaries), and unzip
|
- name: Install git, clang-tools, iwyu (ci_single_binaries), and unzip
|
||||||
run: apt-get update ; apt-get install -y git clang-tools iwyu unzip
|
run: apt-get update ; apt-get install -y git clang-tools iwyu unzip
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@57c20a23a6cac5b90f31864439996e5b206df9dc # v4.0.1
|
uses: lukka/get-cmake@591817e96fcad43505fb4eae36172462abb3a42e # v4.3.3
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -86,9 +86,9 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Install build-essential
|
- name: Install build-essential
|
||||||
run: apt-get update ; apt-get install -y build-essential unzip wget git libssl-dev
|
run: apt-get update ; apt-get install -y build-essential unzip wget git libssl-dev
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@57c20a23a6cac5b90f31864439996e5b206df9dc # v4.0.1
|
uses: lukka/get-cmake@591817e96fcad43505fb4eae36172462abb3a42e # v4.3.3
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -98,11 +98,11 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
|
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
- name: Install dependencies and de_DE locale
|
- name: Install dependencies and de_DE locale
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get clean
|
sudo apt-get clean
|
||||||
@@ -115,15 +115,16 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: cmake --build build --target ci_test_coverage
|
run: cmake --build build --target ci_test_coverage
|
||||||
- name: Archive coverage report
|
- name: Archive coverage report
|
||||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||||
with:
|
with:
|
||||||
name: code-coverage-report
|
name: code-coverage-report
|
||||||
path: ${{ github.workspace }}/build/html
|
path: ${{ github.workspace }}/build/html
|
||||||
- name: Publish report to Coveralls
|
- name: Publish report to Coveralls
|
||||||
uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b # v2.3.6
|
uses: coverallsapp/github-action@5cbfd81b66ca5d10c19b062c04de0199c215fb6e # v2.3.7
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
path-to-lcov: ${{ github.workspace }}/build/json.info.filtered.noexcept
|
path-to-lcov: ${{ github.workspace }}/build/json.info.filtered.noexcept
|
||||||
|
fail-on-error: false
|
||||||
|
|
||||||
ci_test_compilers_gcc_old:
|
ci_test_compilers_gcc_old:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -132,7 +133,7 @@ jobs:
|
|||||||
compiler: ['4.8', '4.9', '5', '6']
|
compiler: ['4.8', '4.9', '5', '6']
|
||||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
- 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
|
||||||
@@ -146,9 +147,9 @@ jobs:
|
|||||||
compiler: ['7', '8', '9', '10', '11', '12', '13', '14', '15', 'latest']
|
compiler: ['7', '8', '9', '10', '11', '12', '13', '14', '15', 'latest']
|
||||||
container: gcc:${{ matrix.compiler }}
|
container: gcc:${{ matrix.compiler }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@57c20a23a6cac5b90f31864439996e5b206df9dc # v4.0.1
|
uses: lukka/get-cmake@591817e96fcad43505fb4eae36172462abb3a42e # v4.3.3
|
||||||
- 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
|
||||||
@@ -161,11 +162,9 @@ jobs:
|
|||||||
compiler: ['3.4', '3.5', '3.6', '3.7', '3.8', '3.9', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15-bullseye', '16', '17', '18', '19', '20', 'latest']
|
compiler: ['3.4', '3.5', '3.6', '3.7', '3.8', '3.9', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15-bullseye', '16', '17', '18', '19', '20', 'latest']
|
||||||
container: silkeh/clang:${{ matrix.compiler }}
|
container: silkeh/clang:${{ matrix.compiler }}
|
||||||
steps:
|
steps:
|
||||||
- name: Install unzip and git
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
run: apt-get update ; apt-get install -y unzip git
|
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@57c20a23a6cac5b90f31864439996e5b206df9dc # v4.0.1
|
uses: lukka/get-cmake@591817e96fcad43505fb4eae36172462abb3a42e # v4.3.3
|
||||||
- name: Set env FORCE_STDCPPFS_FLAG for clang 7 / 8 / 9 / 10
|
- name: Set env FORCE_STDCPPFS_FLAG for clang 7 / 8 / 9 / 10
|
||||||
run: echo "JSON_FORCED_GLOBAL_COMPILE_OPTIONS=-DJSON_HAS_FILESYSTEM=0;-DJSON_HAS_EXPERIMENTAL_FILESYSTEM=0" >> "$GITHUB_ENV"
|
run: echo "JSON_FORCED_GLOBAL_COMPILE_OPTIONS=-DJSON_HAS_FILESYSTEM=0;-DJSON_HAS_EXPERIMENTAL_FILESYSTEM=0" >> "$GITHUB_ENV"
|
||||||
if: ${{ matrix.compiler == '7' || matrix.compiler == '8' || matrix.compiler == '9' || matrix.compiler == '10' }}
|
if: ${{ matrix.compiler == '7' || matrix.compiler == '8' || matrix.compiler == '9' || matrix.compiler == '10' }}
|
||||||
@@ -181,9 +180,9 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
standard: [11, 14, 17, 20, 23, 26]
|
standard: [11, 14, 17, 20, 23, 26]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@57c20a23a6cac5b90f31864439996e5b206df9dc # v4.0.1
|
uses: lukka/get-cmake@591817e96fcad43505fb4eae36172462abb3a42e # v4.3.3
|
||||||
- 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
|
||||||
@@ -199,9 +198,9 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Install git and unzip
|
- name: Install git and unzip
|
||||||
run: apt-get update ; apt-get install -y git unzip
|
run: apt-get update ; apt-get install -y git unzip
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@57c20a23a6cac5b90f31864439996e5b206df9dc # v4.0.1
|
uses: lukka/get-cmake@591817e96fcad43505fb4eae36172462abb3a42e # v4.3.3
|
||||||
- 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++
|
||||||
@@ -215,7 +214,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
- 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
|
||||||
@@ -228,9 +227,9 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: ${{ matrix.container }}
|
container: ${{ matrix.container }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@57c20a23a6cac5b90f31864439996e5b206df9dc # v4.0.1
|
uses: lukka/get-cmake@591817e96fcad43505fb4eae36172462abb3a42e # v4.3.3
|
||||||
- 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
|
||||||
@@ -240,7 +239,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: ghcr.io/nlohmann/json-ci:v2.2.0
|
container: ghcr.io/nlohmann/json-ci:v2.2.0
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
- 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
|
||||||
@@ -252,15 +251,15 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
|
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: Install emscripten
|
- name: Install emscripten
|
||||||
uses: mymindstorm/setup-emsdk@v14
|
uses: mymindstorm/setup-emsdk@4528d102f7230f0e7b276855c01ea1159be0e984 # v16
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@57c20a23a6cac5b90f31864439996e5b206df9dc # v4.0.1
|
uses: lukka/get-cmake@591817e96fcad43505fb4eae36172462abb3a42e # v4.3.3
|
||||||
- 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
|
||||||
@@ -273,11 +272,11 @@ jobs:
|
|||||||
target: [ci_test_examples, ci_test_build_documentation]
|
target: [ci_test_examples, ci_test_build_documentation]
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
|
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
- 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
|
||||||
|
|||||||
@@ -18,15 +18,15 @@ concurrency:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
mingw:
|
mingw:
|
||||||
runs-on: windows-2019
|
runs-on: windows-2022
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
architecture: [x64, x86]
|
architecture: [x64, x86]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
- name: Set up MinGW
|
- name: Set up MinGW
|
||||||
uses: egor-tensin/setup-mingw@84c781b557efd538dec66bde06988d81cd3138cf # v2.2.0
|
uses: egor-tensin/setup-mingw@41b837e47d7f85214629d255b9c4bc3fcbe9fd63 # v3.0
|
||||||
with:
|
with:
|
||||||
platform: ${{ matrix.architecture }}
|
platform: ${{ matrix.architecture }}
|
||||||
version: 12.2.0 # https://github.com/egor-tensin/setup-mingw/issues/14
|
version: 12.2.0 # https://github.com/egor-tensin/setup-mingw/issues/14
|
||||||
@@ -40,24 +40,14 @@ jobs:
|
|||||||
msvc:
|
msvc:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
runs_on: [windows-2019, windows-2022]
|
|
||||||
build_type: [Debug, Release]
|
build_type: [Debug, Release]
|
||||||
architecture: [Win32, x64]
|
architecture: [Win32, x64]
|
||||||
std_version: [default, latest]
|
std_version: [default, latest]
|
||||||
|
|
||||||
runs-on: ${{ matrix.runs_on }}
|
runs-on: windows-2022
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
- name: Set generator
|
|
||||||
id: generator
|
|
||||||
run: |
|
|
||||||
if [ "${{ matrix.runs_on }}" = "windows-2019" ]; then
|
|
||||||
echo "generator=Visual Studio 16 2019" >> $GITHUB_ENV
|
|
||||||
else
|
|
||||||
echo "generator=Visual Studio 17 2022" >> $GITHUB_ENV
|
|
||||||
fi
|
|
||||||
shell: bash
|
|
||||||
- name: Set extra CXX_FLAGS for latest std_version
|
- name: Set extra CXX_FLAGS for latest std_version
|
||||||
id: cxxflags
|
id: cxxflags
|
||||||
run: |
|
run: |
|
||||||
@@ -68,11 +58,11 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
shell: bash
|
shell: bash
|
||||||
- name: Run CMake (Release)
|
- name: Run CMake (Release)
|
||||||
run: cmake -S . -B build -G "$env:generator" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="$env:flags"
|
run: cmake -S . -B build -G "Visual Studio 17 2022" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="$env:flags"
|
||||||
if: matrix.build_type == 'Release'
|
if: matrix.build_type == 'Release'
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
- name: Run CMake (Debug)
|
- name: Run CMake (Debug)
|
||||||
run: cmake -S . -B build -G "$env:generator" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DJSON_FastTests=ON -DCMAKE_CXX_FLAGS="$env:flags"
|
run: cmake -S . -B build -G "Visual Studio 17 2022" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DJSON_FastTests=ON -DCMAKE_CXX_FLAGS="$env:flags"
|
||||||
if: matrix.build_type == 'Debug'
|
if: matrix.build_type == 'Debug'
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -81,42 +71,54 @@ jobs:
|
|||||||
run: cd build ; ctest -j 10 -C ${{ matrix.build_type }} --output-on-failure
|
run: cd build ; ctest -j 10 -C ${{ matrix.build_type }} --output-on-failure
|
||||||
|
|
||||||
clang:
|
clang:
|
||||||
runs-on: windows-2019
|
runs-on: windows-2022
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
version: [11, 12, 13, 14, 15]
|
version: [11.0.1, 12.0.1, 13.0.1, 14.0.6, 15.0.7, 16.0.6, 18.1.8, 19.1.7, 20.1.8]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
- name: Install Clang
|
- name: Install Clang
|
||||||
run: curl -fsSL -o LLVM${{ matrix.version }}.exe https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ matrix.version }}.0.0/LLVM-${{ matrix.version }}.0.0-win64.exe ; 7z x LLVM${{ matrix.version }}.exe -y -o"C:/Program Files/LLVM"
|
run: curl -fsSL -o LLVM${{ matrix.version }}.exe https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ matrix.version }}/LLVM-${{ matrix.version }}-win64.exe ; 7z x LLVM${{ matrix.version }}.exe -y -o"C:/Program Files/LLVM"
|
||||||
|
- name: Set up MinGW
|
||||||
|
uses: egor-tensin/setup-mingw@41b837e47d7f85214629d255b9c4bc3fcbe9fd63 # v3.0
|
||||||
|
with:
|
||||||
|
platform: x64
|
||||||
|
version: 12.2.0 # https://github.com/egor-tensin/setup-mingw/issues/14
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang++.exe" -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On
|
run: cmake -S . -B build ^
|
||||||
|
-DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang++.exe" ^
|
||||||
|
-DCMAKE_CXX_FLAGS="--target=x86_64-w64-mingw32 -stdlib=libstdc++ -pthread" ^
|
||||||
|
-DCMAKE_EXE_LINKER_FLAGS="-lwinpthread" ^
|
||||||
|
-G"MinGW Makefiles" ^
|
||||||
|
-DCMAKE_BUILD_TYPE=Debug ^
|
||||||
|
-DJSON_BuildTests=On
|
||||||
- name: Build
|
- name: Build
|
||||||
run: cmake --build build --parallel 10
|
run: cmake --build build --parallel 10
|
||||||
- name: Test
|
- name: Test
|
||||||
run: cd build ; ctest -j 10 -C Debug --exclude-regex "test-unicode" --output-on-failure
|
run: cd build ; ctest -j 10 -C Debug --exclude-regex "test-unicode" --output-on-failure
|
||||||
|
|
||||||
clang-cl-12:
|
clang-cl-12:
|
||||||
runs-on: windows-2019
|
runs-on: windows-2022
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
architecture: [Win32, x64]
|
architecture: [Win32, x64]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -G "Visual Studio 16 2019" -A ${{ matrix.architecture }} -T ClangCL -DJSON_BuildTests=On
|
run: cmake -S . -B build -G "Visual Studio 17 2022" -A ${{ matrix.architecture }} -T ClangCL -DJSON_BuildTests=On
|
||||||
- name: Build
|
- name: Build
|
||||||
run: cmake --build build --config Debug --parallel 10
|
run: cmake --build build --config Debug --parallel 10
|
||||||
- name: Test
|
- name: Test
|
||||||
run: cd build ; ctest -j 10 -C Debug --exclude-regex "test-unicode" --output-on-failure
|
run: cd build ; ctest -j 10 -C Debug --exclude-regex "test-unicode" --output-on-failure
|
||||||
|
|
||||||
ci_module_cpp20:
|
ci_module_cpp20:
|
||||||
runs-on: windows-latest
|
runs-on: windows-2022
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
- name: Run CMake (Debug)
|
- name: Run CMake (Debug)
|
||||||
run: cmake -S . -B build -G "Visual Studio 17 2022" -DJSON_CI=ON -DCMAKE_CXX_FLAGS="/permissive- /std:c++latest /utf-8 /W4 /WX"
|
run: cmake -S . -B build -G "Visual Studio 17 2022" -DJSON_CI=ON -DCMAKE_CXX_FLAGS="/permissive- /std:c++latest /utf-8 /W4 /WX"
|
||||||
- name: Build
|
- name: Build
|
||||||
run: cmake --build build --config Debug --target ci_module_cpp20
|
run: cmake --build build --config Debug --target ci_module_cpp20
|
||||||
|
|
||||||
+1
-1
@@ -4,7 +4,7 @@ Upstream-Contact: Niels Lohmann <mail@nlohmann.me>
|
|||||||
Source: https://github.com/nlohmann/json
|
Source: https://github.com/nlohmann/json
|
||||||
|
|
||||||
Files: *
|
Files: *
|
||||||
Copyright: 2013-2025 Niels Lohmann <https://nlohmann.me>
|
Copyright: 2013-2026 Niels Lohmann <https://nlohmann.me>
|
||||||
License: MIT
|
License: MIT
|
||||||
|
|
||||||
Files: include/nlohmann/thirdparty/hedley.hpp
|
Files: include/nlohmann/thirdparty/hedley.hpp
|
||||||
|
|||||||
@@ -22,6 +22,18 @@ endif()
|
|||||||
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
|
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
|
||||||
include(ExternalProject)
|
include(ExternalProject)
|
||||||
|
|
||||||
|
# ---- C++ Modules Support (optional) ----
|
||||||
|
option(NLOHMANN_JSON_BUILD_MODULES "Build C++ modules support" OFF)
|
||||||
|
|
||||||
|
if(NLOHMANN_JSON_BUILD_MODULES)
|
||||||
|
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.28)
|
||||||
|
message(STATUS "Building nlohmann.json C++ module")
|
||||||
|
add_subdirectory(src/modules)
|
||||||
|
else()
|
||||||
|
message(WARNING "Skipping nlohmann.json C++ module (requires CMake 3.28+, found ${CMAKE_VERSION})")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
##
|
##
|
||||||
## OPTIONS
|
## OPTIONS
|
||||||
##
|
##
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ Further documentation:
|
|||||||
|
|
||||||
### `.github/dependabot.yml`
|
### `.github/dependabot.yml`
|
||||||
|
|
||||||
The configuration of [dependabot](https://github.com/dependabot) which ensures the dependencies (GitHub actions and Python packages used in the CI) remain up-to-date.
|
The configuration of [dependabot](https://github.com/dependabot) which ensures the dependencies (GitHub actions and Python packages used in the CI) remain up to date.
|
||||||
|
|
||||||
Further documentation:
|
Further documentation:
|
||||||
|
|
||||||
@@ -185,7 +185,7 @@ Further documentation:
|
|||||||
|
|
||||||
### `.reuse/dep5`
|
### `.reuse/dep5`
|
||||||
|
|
||||||
The file defines the licenses of certain third-party component in the repository. The root `Makefile` contains a target `reuse` that checks for compliance.
|
The file defines the licenses of certain third-party components in the repository. The root `Makefile` contains a target `reuse` that checks for compliance.
|
||||||
|
|
||||||
Further documentation:
|
Further documentation:
|
||||||
|
|
||||||
@@ -212,7 +212,7 @@ Further information:
|
|||||||
|
|
||||||
### `LICENSES`
|
### `LICENSES`
|
||||||
|
|
||||||
A folder that contains every license of all licenses files (library and third-party code).
|
A folder that contains every license of all license files (library and third-party code).
|
||||||
|
|
||||||
Further documentation:
|
Further documentation:
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2013-2025 Niels Lohmann
|
Copyright (c) 2013-2026 Niels Lohmann
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -0,0 +1,121 @@
|
|||||||
|
Creative Commons Legal Code
|
||||||
|
|
||||||
|
CC0 1.0 Universal
|
||||||
|
|
||||||
|
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
||||||
|
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
||||||
|
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
||||||
|
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
||||||
|
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
||||||
|
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
||||||
|
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
||||||
|
HEREUNDER.
|
||||||
|
|
||||||
|
Statement of Purpose
|
||||||
|
|
||||||
|
The laws of most jurisdictions throughout the world automatically confer
|
||||||
|
exclusive Copyright and Related Rights (defined below) upon the creator
|
||||||
|
and subsequent owner(s) (each and all, an "owner") of an original work of
|
||||||
|
authorship and/or a database (each, a "Work").
|
||||||
|
|
||||||
|
Certain owners wish to permanently relinquish those rights to a Work for
|
||||||
|
the purpose of contributing to a commons of creative, cultural and
|
||||||
|
scientific works ("Commons") that the public can reliably and without fear
|
||||||
|
of later claims of infringement build upon, modify, incorporate in other
|
||||||
|
works, reuse and redistribute as freely as possible in any form whatsoever
|
||||||
|
and for any purposes, including without limitation commercial purposes.
|
||||||
|
These owners may contribute to the Commons to promote the ideal of a free
|
||||||
|
culture and the further production of creative, cultural and scientific
|
||||||
|
works, or to gain reputation or greater distribution for their Work in
|
||||||
|
part through the use and efforts of others.
|
||||||
|
|
||||||
|
For these and/or other purposes and motivations, and without any
|
||||||
|
expectation of additional consideration or compensation, the person
|
||||||
|
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
||||||
|
is an owner of Copyright and Related Rights in the Work, voluntarily
|
||||||
|
elects to apply CC0 to the Work and publicly distribute the Work under its
|
||||||
|
terms, with knowledge of his or her Copyright and Related Rights in the
|
||||||
|
Work and the meaning and intended legal effect of CC0 on those rights.
|
||||||
|
|
||||||
|
1. Copyright and Related Rights. A Work made available under CC0 may be
|
||||||
|
protected by copyright and related or neighboring rights ("Copyright and
|
||||||
|
Related Rights"). Copyright and Related Rights include, but are not
|
||||||
|
limited to, the following:
|
||||||
|
|
||||||
|
i. the right to reproduce, adapt, distribute, perform, display,
|
||||||
|
communicate, and translate a Work;
|
||||||
|
ii. moral rights retained by the original author(s) and/or performer(s);
|
||||||
|
iii. publicity and privacy rights pertaining to a person's image or
|
||||||
|
likeness depicted in a Work;
|
||||||
|
iv. rights protecting against unfair competition in regards to a Work,
|
||||||
|
subject to the limitations in paragraph 4(a), below;
|
||||||
|
v. rights protecting the extraction, dissemination, use and reuse of data
|
||||||
|
in a Work;
|
||||||
|
vi. database rights (such as those arising under Directive 96/9/EC of the
|
||||||
|
European Parliament and of the Council of 11 March 1996 on the legal
|
||||||
|
protection of databases, and under any national implementation
|
||||||
|
thereof, including any amended or successor version of such
|
||||||
|
directive); and
|
||||||
|
vii. other similar, equivalent or corresponding rights throughout the
|
||||||
|
world based on applicable law or treaty, and any national
|
||||||
|
implementations thereof.
|
||||||
|
|
||||||
|
2. Waiver. To the greatest extent permitted by, but not in contravention
|
||||||
|
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
||||||
|
irrevocably and unconditionally waives, abandons, and surrenders all of
|
||||||
|
Affirmer's Copyright and Related Rights and associated claims and causes
|
||||||
|
of action, whether now known or unknown (including existing as well as
|
||||||
|
future claims and causes of action), in the Work (i) in all territories
|
||||||
|
worldwide, (ii) for the maximum duration provided by applicable law or
|
||||||
|
treaty (including future time extensions), (iii) in any current or future
|
||||||
|
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
||||||
|
including without limitation commercial, advertising or promotional
|
||||||
|
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
||||||
|
member of the public at large and to the detriment of Affirmer's heirs and
|
||||||
|
successors, fully intending that such Waiver shall not be subject to
|
||||||
|
revocation, rescission, cancellation, termination, or any other legal or
|
||||||
|
equitable action to disrupt the quiet enjoyment of the Work by the public
|
||||||
|
as contemplated by Affirmer's express Statement of Purpose.
|
||||||
|
|
||||||
|
3. Public License Fallback. Should any part of the Waiver for any reason
|
||||||
|
be judged legally invalid or ineffective under applicable law, then the
|
||||||
|
Waiver shall be preserved to the maximum extent permitted taking into
|
||||||
|
account Affirmer's express Statement of Purpose. In addition, to the
|
||||||
|
extent the Waiver is so judged Affirmer hereby grants to each affected
|
||||||
|
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
||||||
|
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
||||||
|
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
||||||
|
maximum duration provided by applicable law or treaty (including future
|
||||||
|
time extensions), (iii) in any current or future medium and for any number
|
||||||
|
of copies, and (iv) for any purpose whatsoever, including without
|
||||||
|
limitation commercial, advertising or promotional purposes (the
|
||||||
|
"License"). The License shall be deemed effective as of the date CC0 was
|
||||||
|
applied by Affirmer to the Work. Should any part of the License for any
|
||||||
|
reason be judged legally invalid or ineffective under applicable law, such
|
||||||
|
partial invalidity or ineffectiveness shall not invalidate the remainder
|
||||||
|
of the License, and in such case Affirmer hereby affirms that he or she
|
||||||
|
will not (i) exercise any of his or her remaining Copyright and Related
|
||||||
|
Rights in the Work or (ii) assert any associated claims and causes of
|
||||||
|
action with respect to the Work, in either case contrary to Affirmer's
|
||||||
|
express Statement of Purpose.
|
||||||
|
|
||||||
|
4. Limitations and Disclaimers.
|
||||||
|
|
||||||
|
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
||||||
|
surrendered, licensed or otherwise affected by this document.
|
||||||
|
b. Affirmer offers the Work as-is and makes no representations or
|
||||||
|
warranties of any kind concerning the Work, express, implied,
|
||||||
|
statutory or otherwise, including without limitation warranties of
|
||||||
|
title, merchantability, fitness for a particular purpose, non
|
||||||
|
infringement, or the absence of latent or other defects, accuracy, or
|
||||||
|
the present or absence of errors, whether or not discoverable, all to
|
||||||
|
the greatest extent permissible under applicable law.
|
||||||
|
c. Affirmer disclaims responsibility for clearing rights of other persons
|
||||||
|
that may apply to the Work or any use thereof, including without
|
||||||
|
limitation any person's Copyright and Related Rights in the Work.
|
||||||
|
Further, Affirmer disclaims responsibility for obtaining any necessary
|
||||||
|
consents, permissions or other rights required for any use of the
|
||||||
|
Work.
|
||||||
|
d. Affirmer understands and acknowledges that Creative Commons is not a
|
||||||
|
party to this document and has no duty or obligation with respect to
|
||||||
|
this CC0 or use of the Work.
|
||||||
@@ -258,8 +258,8 @@ serve_header:
|
|||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
reuse:
|
reuse:
|
||||||
pipx run reuse annotate --recursive single_include include -tjson --license MIT --copyright "Niels Lohmann <https://nlohmann.me>" --year "2013-2025" --merge-copyrights
|
pipx run reuse annotate --recursive single_include include -tjson --license MIT --copyright "Niels Lohmann <https://nlohmann.me>" --year "2013-2026" --merge-copyrights
|
||||||
pipx run reuse annotate $(TESTS_SRCS) -tjson_support --license MIT --copyright "Niels Lohmann <https://nlohmann.me>" --year "2013-2025" --merge-copyrights
|
pipx run reuse annotate $(TESTS_SRCS) -tjson_support --license MIT --copyright "Niels Lohmann <https://nlohmann.me>" --year "2013-2026" --merge-copyrights
|
||||||
pipx run reuse lint
|
pipx run reuse lint
|
||||||
|
|
||||||
spdx:
|
spdx:
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
[](https://isitmaintained.com/project/nlohmann/json "Average time to resolve an issue")
|
[](https://isitmaintained.com/project/nlohmann/json "Average time to resolve an issue")
|
||||||
[](https://bestpractices.coreinfrastructure.org/projects/289)
|
[](https://bestpractices.coreinfrastructure.org/projects/289)
|
||||||
[](https://scorecard.dev/viewer/?uri=github.com/nlohmann/json)
|
[](https://scorecard.dev/viewer/?uri=github.com/nlohmann/json)
|
||||||
|
[](https://cloudback.it)
|
||||||
[](https://github.com/sponsors/nlohmann)
|
[](https://github.com/sponsors/nlohmann)
|
||||||
[](https://api.reuse.software/info/github.com/nlohmann/json)
|
[](https://api.reuse.software/info/github.com/nlohmann/json)
|
||||||
[](https://discord.gg/6mrGXKvX7y)
|
[](https://discord.gg/6mrGXKvX7y)
|
||||||
@@ -30,7 +31,7 @@
|
|||||||
- [Examples](#examples)
|
- [Examples](#examples)
|
||||||
- [Read JSON from a file](#read-json-from-a-file)
|
- [Read JSON from a file](#read-json-from-a-file)
|
||||||
- [Creating `json` objects from JSON literals](#creating-json-objects-from-json-literals)
|
- [Creating `json` objects from JSON literals](#creating-json-objects-from-json-literals)
|
||||||
- [JSON as first-class data type](#json-as-first-class-data-type)
|
- [JSON as a first-class data type](#json-as-a-first-class-data-type)
|
||||||
- [Serialization / Deserialization](#serialization--deserialization)
|
- [Serialization / Deserialization](#serialization--deserialization)
|
||||||
- [STL-like access](#stl-like-access)
|
- [STL-like access](#stl-like-access)
|
||||||
- [Conversion from STL containers](#conversion-from-stl-containers)
|
- [Conversion from STL containers](#conversion-from-stl-containers)
|
||||||
@@ -57,7 +58,7 @@
|
|||||||
|
|
||||||
There are myriads of [JSON](https://json.org) libraries out there, and each may even have its reason to exist. Our class had these design goals:
|
There are myriads of [JSON](https://json.org) libraries out there, and each may even have its reason to exist. Our class had these design goals:
|
||||||
|
|
||||||
- **Intuitive syntax**. In languages such as Python, JSON feels like a first class data type. We used all the operator magic of modern C++ to achieve the same feeling in your code. Check out the [examples below](#examples) and you'll know what I mean.
|
- **Intuitive syntax**. In languages such as Python, JSON feels like a first-class data type. We used all the operator magic of modern C++ to achieve the same feeling in your code. Check out the [examples below](#examples) and you'll know what I mean.
|
||||||
|
|
||||||
- **Trivial integration**. Our whole code consists of a single header file [`json.hpp`](https://github.com/nlohmann/json/blob/develop/single_include/nlohmann/json.hpp). That's it. No library, no subproject, no dependencies, no complex build system. The class is written in vanilla C++11. All in all, everything should require no adjustment of your compiler flags or project settings. The library is also included in all popular [package managers](https://json.nlohmann.me/integration/package_managers/).
|
- **Trivial integration**. Our whole code consists of a single header file [`json.hpp`](https://github.com/nlohmann/json/blob/develop/single_include/nlohmann/json.hpp). That's it. No library, no subproject, no dependencies, no complex build system. The class is written in vanilla C++11. All in all, everything should require no adjustment of your compiler flags or project settings. The library is also included in all popular [package managers](https://json.nlohmann.me/integration/package_managers/).
|
||||||
|
|
||||||
@@ -79,6 +80,8 @@ You can sponsor this library at [GitHub Sponsors](https://github.com/sponsors/nl
|
|||||||
|
|
||||||
- [Martti Laine](https://github.com/codeclown)
|
- [Martti Laine](https://github.com/codeclown)
|
||||||
- [Paul Harrington](https://github.com/phrrngtn)
|
- [Paul Harrington](https://github.com/phrrngtn)
|
||||||
|
- [Mercedes-Benz Group](https://github.com/mercedes-benz)
|
||||||
|
- [Ryan McCaffery](https://github.com/mccaffers)
|
||||||
|
|
||||||
### :label: Named Sponsors
|
### :label: Named Sponsors
|
||||||
|
|
||||||
@@ -107,7 +110,7 @@ Thanks everyone!
|
|||||||
|
|
||||||
:bug: If you found a **bug**, please check the [**FAQ**](https://json.nlohmann.me/home/faq/) if it is a known issue or the result of a design decision. Please also have a look at the [**issue list**](https://github.com/nlohmann/json/issues) before you [**create a new issue**](https://github.com/nlohmann/json/issues/new/choose). Please provide as much information as possible to help us understand and reproduce your issue.
|
:bug: If you found a **bug**, please check the [**FAQ**](https://json.nlohmann.me/home/faq/) if it is a known issue or the result of a design decision. Please also have a look at the [**issue list**](https://github.com/nlohmann/json/issues) before you [**create a new issue**](https://github.com/nlohmann/json/issues/new/choose). Please provide as much information as possible to help us understand and reproduce your issue.
|
||||||
|
|
||||||
There is also a [**docset**](https://github.com/Kapeli/Dash-User-Contributions/tree/master/docsets/JSON_for_Modern_C%2B%2B) for the documentation browsers [Dash](https://kapeli.com/dash), [Velocity](https://velocity.silverlakesoftware.com), and [Zeal](https://zealdocs.org) that contains the full [documentation](https://json.nlohmann.me) as offline resource.
|
There is also a [**docset**](https://github.com/Kapeli/Dash-User-Contributions/tree/master/docsets/JSON_for_Modern_C%2B%2B) for the documentation browsers [Dash](https://kapeli.com/dash), [Velocity](https://velocity.silverlakesoftware.com), and [Zeal](https://zealdocs.org) that contains the full [documentation](https://json.nlohmann.me) as an offline resource.
|
||||||
|
|
||||||
## Quick reference
|
## Quick reference
|
||||||
|
|
||||||
@@ -136,7 +139,7 @@ There is also a [**docset**](https://github.com/Kapeli/Dash-User-Contributions/t
|
|||||||
|
|
||||||
Here are some examples to give you an idea how to use the class.
|
Here are some examples to give you an idea how to use the class.
|
||||||
|
|
||||||
Beside the examples below, you may want to:
|
Besides the examples below, you may want to:
|
||||||
|
|
||||||
→ Check the [documentation](https://json.nlohmann.me/)\
|
→ Check the [documentation](https://json.nlohmann.me/)\
|
||||||
→ Browse the [standalone example files](https://github.com/nlohmann/json/tree/develop/docs/mkdocs/docs/examples)\
|
→ Browse the [standalone example files](https://github.com/nlohmann/json/tree/develop/docs/mkdocs/docs/examples)\
|
||||||
@@ -157,9 +160,22 @@ std::ifstream f("example.json");
|
|||||||
json data = json::parse(f);
|
json data = json::parse(f);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If using modules (enabled with `NLOHMANN_JSON_BUILD_MODULES`), this example becomes:
|
||||||
|
```cpp
|
||||||
|
import std;
|
||||||
|
import nlohmann.json;
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
// ...
|
||||||
|
|
||||||
|
std::ifstream f("example.json");
|
||||||
|
json data = json::parse(f);
|
||||||
|
```
|
||||||
|
|
||||||
### Creating `json` objects from JSON literals
|
### Creating `json` objects from JSON literals
|
||||||
|
|
||||||
Assume you want to create hard-code this literal JSON value in a file, as a `json` object:
|
Assume you want to hard-code this literal JSON value as a `json` object:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
@@ -195,7 +211,7 @@ json ex3 = {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
### JSON as first-class data type
|
### JSON as a first-class data type
|
||||||
|
|
||||||
Here are some examples to give you an idea how to use the class.
|
Here are some examples to give you an idea how to use the class.
|
||||||
|
|
||||||
@@ -224,13 +240,13 @@ With this library, you could write:
|
|||||||
// create an empty structure (null)
|
// create an empty structure (null)
|
||||||
json j;
|
json j;
|
||||||
|
|
||||||
// add a number that is stored as double (note the implicit conversion of j to an object)
|
// add a number stored as double (note the implicit conversion of j to an object)
|
||||||
j["pi"] = 3.141;
|
j["pi"] = 3.141;
|
||||||
|
|
||||||
// add a Boolean that is stored as bool
|
// add a Boolean stored as bool
|
||||||
j["happy"] = true;
|
j["happy"] = true;
|
||||||
|
|
||||||
// add a string that is stored as std::string
|
// add a string stored as std::string
|
||||||
j["name"] = "Niels";
|
j["name"] = "Niels";
|
||||||
|
|
||||||
// add another null object by passing nullptr
|
// add another null object by passing nullptr
|
||||||
@@ -239,7 +255,7 @@ j["nothing"] = nullptr;
|
|||||||
// add an object inside the object
|
// add an object inside the object
|
||||||
j["answer"]["everything"] = 42;
|
j["answer"]["everything"] = 42;
|
||||||
|
|
||||||
// add an array that is stored as std::vector (using an initializer list)
|
// add an array stored as std::vector (using an initializer list)
|
||||||
j["list"] = { 1, 0, 2 };
|
j["list"] = { 1, 0, 2 };
|
||||||
|
|
||||||
// add another object (using an initializer list of pairs)
|
// add another object (using an initializer list of pairs)
|
||||||
@@ -331,7 +347,7 @@ Note the difference between serialization and assignment:
|
|||||||
json j_string = "this is a string";
|
json j_string = "this is a string";
|
||||||
|
|
||||||
// retrieve the string value
|
// retrieve the string value
|
||||||
auto cpp_string = j_string.template get<std::string>();
|
auto cpp_string = j_string.get<std::string>();
|
||||||
// retrieve the string value (alternative when a variable already exists)
|
// retrieve the string value (alternative when a variable already exists)
|
||||||
std::string cpp_string2;
|
std::string cpp_string2;
|
||||||
j_string.get_to(cpp_string2);
|
j_string.get_to(cpp_string2);
|
||||||
@@ -340,7 +356,7 @@ j_string.get_to(cpp_string2);
|
|||||||
std::string serialized_string = j_string.dump();
|
std::string serialized_string = j_string.dump();
|
||||||
|
|
||||||
// output of original string
|
// output of original string
|
||||||
std::cout << cpp_string << " == " << cpp_string2 << " == " << j_string.template get<std::string>() << '\n';
|
std::cout << cpp_string << " == " << cpp_string2 << " == " << j_string.get<std::string>() << '\n';
|
||||||
// output of serialized value
|
// output of serialized value
|
||||||
std::cout << j_string << " == " << serialized_string << std::endl;
|
std::cout << j_string << " == " << serialized_string << std::endl;
|
||||||
```
|
```
|
||||||
@@ -349,7 +365,7 @@ std::cout << j_string << " == " << serialized_string << std::endl;
|
|||||||
|
|
||||||
Note the library only supports UTF-8. When you store strings with different encodings in the library, calling [`dump()`](https://json.nlohmann.me/api/basic_json/dump/) may throw an exception unless `json::error_handler_t::replace` or `json::error_handler_t::ignore` are used as error handlers.
|
Note the library only supports UTF-8. When you store strings with different encodings in the library, calling [`dump()`](https://json.nlohmann.me/api/basic_json/dump/) may throw an exception unless `json::error_handler_t::replace` or `json::error_handler_t::ignore` are used as error handlers.
|
||||||
|
|
||||||
#### To/from streams (e.g. files, string streams)
|
#### To/from streams (e.g., files, string streams)
|
||||||
|
|
||||||
You can also use streams to serialize and deserialize:
|
You can also use streams to serialize and deserialize:
|
||||||
|
|
||||||
@@ -382,7 +398,7 @@ Please note that setting the exception bit for `failbit` is inappropriate for th
|
|||||||
|
|
||||||
#### Read from iterator range
|
#### Read from iterator range
|
||||||
|
|
||||||
You can also parse JSON from an iterator range; that is, from any container accessible by iterators whose `value_type` is an integral type of 1, 2 or 4 bytes, which will be interpreted as UTF-8, UTF-16 and UTF-32 respectively. For instance, a `std::vector<std::uint8_t>`, or a `std::list<std::uint16_t>`:
|
You can also parse JSON from an iterator range; that is, from any container accessible by iterators whose `value_type` is an integral type of 1, 2, or 4 bytes, which will be interpreted as UTF-8, UTF-16, and UTF-32 respectively. For instance, a `std::vector<std::uint8_t>`, or a `std::list<std::uint16_t>`:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
std::vector<std::uint8_t> v = {'t', 'r', 'u', 'e'};
|
std::vector<std::uint8_t> v = {'t', 'r', 'u', 'e'};
|
||||||
@@ -486,7 +502,7 @@ To implement your own SAX handler, proceed as follows:
|
|||||||
2. Create an object of your SAX interface class, e.g. `my_sax`.
|
2. Create an object of your SAX interface class, e.g. `my_sax`.
|
||||||
3. Call `bool json::sax_parse(input, &my_sax)`; where the first parameter can be any input like a string or an input stream and the second parameter is a pointer to your SAX interface.
|
3. Call `bool json::sax_parse(input, &my_sax)`; where the first parameter can be any input like a string or an input stream and the second parameter is a pointer to your SAX interface.
|
||||||
|
|
||||||
Note the `sax_parse` function only returns a `bool` indicating the result of the last executed SAX event. It does not return a `json` value - it is up to you to decide what to do with the SAX events. Furthermore, no exceptions are thrown in case of a parse error - it is up to you what to do with the exception object passed to your `parse_error` implementation. Internally, the SAX interface is used for the DOM parser (class `json_sax_dom_parser`) as well as the acceptor (`json_sax_acceptor`), see file [`json_sax.hpp`](https://github.com/nlohmann/json/blob/develop/include/nlohmann/detail/input/json_sax.hpp).
|
Note the `sax_parse` function only returns a `bool` indicating the result of the last executed SAX event. It does not return a `json` value - it is up to you to decide what to do with the SAX events. Furthermore, no exceptions are thrown in case of a parse error -- it is up to you what to do with the exception object passed to your `parse_error` implementation. Internally, the SAX interface is used for the DOM parser (class `json_sax_dom_parser`) as well as the acceptor (`json_sax_acceptor`), see file [`json_sax.hpp`](https://github.com/nlohmann/json/blob/develop/include/nlohmann/detail/input/json_sax.hpp).
|
||||||
|
|
||||||
### STL-like access
|
### STL-like access
|
||||||
|
|
||||||
@@ -513,7 +529,7 @@ for (auto& element : j) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getter/setter
|
// getter/setter
|
||||||
const auto tmp = j[0].template get<std::string>();
|
const auto tmp = j[0].get<std::string>();
|
||||||
j[1] = 42;
|
j[1] = 42;
|
||||||
bool foo = j.at(2);
|
bool foo = j.at(2);
|
||||||
|
|
||||||
@@ -618,7 +634,7 @@ json j_umset(c_umset); // both entries for "one" are used
|
|||||||
// maybe ["one", "two", "one", "four"]
|
// maybe ["one", "two", "one", "four"]
|
||||||
```
|
```
|
||||||
|
|
||||||
Likewise, any associative key-value containers (`std::map`, `std::multimap`, `std::unordered_map`, `std::unordered_multimap`) whose keys can construct an `std::string` and whose values can be used to construct JSON values (see examples above) can be used to create a JSON object. Note that in case of multimaps only one key is used in the JSON object and the value depends on the internal order of the STL container.
|
Likewise, any associative key-value containers (`std::map`, `std::multimap`, `std::unordered_map`, `std::unordered_multimap`) whose keys can construct an `std::string` and whose values can be used to construct JSON values (see examples above) can be used to create a JSON object. Note that in case of multimaps, only one key is used in the JSON object and the value depends on the internal order of the STL container.
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
std::map<std::string, int> c_map { {"one", 1}, {"two", 2}, {"three", 3} };
|
std::map<std::string, int> c_map { {"one", 1}, {"two", 2}, {"three", 3} };
|
||||||
@@ -640,7 +656,7 @@ json j_ummap(c_ummap); // only one entry for key "three" is used
|
|||||||
|
|
||||||
### JSON Pointer and JSON Patch
|
### JSON Pointer and JSON Patch
|
||||||
|
|
||||||
The library supports **JSON Pointer** ([RFC 6901](https://tools.ietf.org/html/rfc6901)) as alternative means to address structured values. On top of this, **JSON Patch** ([RFC 6902](https://tools.ietf.org/html/rfc6902)) allows describing differences between two JSON values - effectively allowing patch and diff operations known from Unix.
|
The library supports **JSON Pointer** ([RFC 6901](https://tools.ietf.org/html/rfc6901)) as an alternative means to address structured values. On top of this, **JSON Patch** ([RFC 6902](https://tools.ietf.org/html/rfc6902)) allows describing differences between two JSON values -- effectively allowing patch and diff operations known from Unix.
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
// a JSON value
|
// a JSON value
|
||||||
@@ -720,7 +736,7 @@ You can switch off implicit conversions by defining `JSON_USE_IMPLICIT_CONVERSIO
|
|||||||
// strings
|
// strings
|
||||||
std::string s1 = "Hello, world!";
|
std::string s1 = "Hello, world!";
|
||||||
json js = s1;
|
json js = s1;
|
||||||
auto s2 = js.template get<std::string>();
|
auto s2 = js.get<std::string>();
|
||||||
// NOT RECOMMENDED
|
// NOT RECOMMENDED
|
||||||
std::string s3 = js;
|
std::string s3 = js;
|
||||||
std::string s4;
|
std::string s4;
|
||||||
@@ -729,7 +745,7 @@ s4 = js;
|
|||||||
// Booleans
|
// Booleans
|
||||||
bool b1 = true;
|
bool b1 = true;
|
||||||
json jb = b1;
|
json jb = b1;
|
||||||
auto b2 = jb.template get<bool>();
|
auto b2 = jb.get<bool>();
|
||||||
// NOT RECOMMENDED
|
// NOT RECOMMENDED
|
||||||
bool b3 = jb;
|
bool b3 = jb;
|
||||||
bool b4;
|
bool b4;
|
||||||
@@ -738,7 +754,7 @@ b4 = jb;
|
|||||||
// numbers
|
// numbers
|
||||||
int i = 42;
|
int i = 42;
|
||||||
json jn = i;
|
json jn = i;
|
||||||
auto f = jn.template get<double>();
|
auto f = jn.get<double>();
|
||||||
// NOT RECOMMENDED
|
// NOT RECOMMENDED
|
||||||
double f2 = jb;
|
double f2 = jb;
|
||||||
double f3;
|
double f3;
|
||||||
@@ -781,9 +797,9 @@ j["age"] = p.age;
|
|||||||
|
|
||||||
// convert from JSON: copy each value from the JSON object
|
// convert from JSON: copy each value from the JSON object
|
||||||
ns::person p {
|
ns::person p {
|
||||||
j["name"].template get<std::string>(),
|
j["name"].get<std::string>(),
|
||||||
j["address"].template get<std::string>(),
|
j["address"].get<std::string>(),
|
||||||
j["age"].template get<int>()
|
j["age"].get<int>()
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -800,7 +816,7 @@ std::cout << j << std::endl;
|
|||||||
// {"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"}
|
// {"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"}
|
||||||
|
|
||||||
// conversion: json -> person
|
// conversion: json -> person
|
||||||
auto p2 = j.template get<ns::person>();
|
auto p2 = j.get<ns::person>();
|
||||||
|
|
||||||
// that's it
|
// that's it
|
||||||
assert(p == p2);
|
assert(p == p2);
|
||||||
@@ -827,21 +843,21 @@ namespace ns {
|
|||||||
```
|
```
|
||||||
|
|
||||||
That's all! When calling the `json` constructor with your type, your custom `to_json` method will be automatically called.
|
That's all! When calling the `json` constructor with your type, your custom `to_json` method will be automatically called.
|
||||||
Likewise, when calling `template get<your_type>()` or `get_to(your_type&)`, the `from_json` method will be called.
|
Likewise, when calling `get<your_type>()` or `get_to(your_type&)`, the `from_json` method will be called.
|
||||||
|
|
||||||
Some important things:
|
Some important things:
|
||||||
|
|
||||||
- Those methods **MUST** be in your type's namespace (which can be the global namespace), or the library will not be able to locate them (in this example, they are in namespace `ns`, where `person` is defined).
|
- Those methods **MUST** be in your type's namespace (which can be the global namespace), or the library will not be able to locate them (in this example, they are in namespace `ns`, where `person` is defined).
|
||||||
- Those methods **MUST** be available (e.g., proper headers must be included) everywhere you use these conversions. Look at [issue 1108](https://github.com/nlohmann/json/issues/1108) for errors that may occur otherwise.
|
- Those methods **MUST** be available (e.g., proper headers must be included) everywhere you use these conversions. Look at [issue 1108](https://github.com/nlohmann/json/issues/1108) for errors that may occur otherwise.
|
||||||
- When using `template get<your_type>()`, `your_type` **MUST** be [DefaultConstructible](https://en.cppreference.com/w/cpp/named_req/DefaultConstructible). (There is a way to bypass this requirement described later.)
|
- When using `get<your_type>()`, `your_type` **MUST** be [DefaultConstructible](https://en.cppreference.com/w/cpp/named_req/DefaultConstructible). (There is a way to bypass this requirement described later.)
|
||||||
- In function `from_json`, use function [`at()`](https://json.nlohmann.me/api/basic_json/at/) to access the object values rather than `operator[]`. In case a key does not exist, `at` throws an exception that you can handle, whereas `operator[]` exhibits undefined behavior.
|
- In function `from_json`, use function [`at()`](https://json.nlohmann.me/api/basic_json/at/) to access the object values rather than `operator[]`. In case a key does not exist, `at` throws an exception that you can handle, whereas `operator[]` exhibits undefined behavior.
|
||||||
- You do not need to add serializers or deserializers for STL types like `std::vector`: the library already implements these.
|
- You do not need to add serializers or deserializers for STL types like `std::vector`: the library already implements these.
|
||||||
|
|
||||||
#### Simplify your life with macros
|
#### Simplify your life with macros
|
||||||
|
|
||||||
If you just want to serialize/deserialize some structs, the `to_json`/`from_json` functions can be a lot of boilerplate. There are [**several macros**](https://json.nlohmann.me/features/arbitrary_types/#simplify-your-life-with-macros) to make your life easier as long as you (1) want to use a JSON object as serialization and (2) want to use the member variable names as object keys in that object.
|
If you just want to serialize/deserialize some structs, the `to_json`/`from_json` functions can be a lot of boilerplate. There are [**several macros**](https://json.nlohmann.me/api/macros/#serializationdeserialization-macros) to make your life easier as long as you want to use a JSON object as serialization.
|
||||||
|
|
||||||
Which macro to choose depends on whether private member variables need to be accessed, a deserialization is needed, missing values should yield an error or should be replaced by default values, and if derived classes are used. See [this overview to choose the right one for your use case](https://json.nlohmann.me/api/macros/#serializationdeserialization-macros).
|
Which macro to choose depends on whether private member variables need to be accessed, a deserialization is needed, missing values should yield an error or should be replaced by default values, and if derived classes are used. See [this overview to choose the right one for your use case](https://json.nlohmann.me/features/arbitrary_types/#simplify-your-life-with-macros).
|
||||||
|
|
||||||
##### Example usage of macros
|
##### Example usage of macros
|
||||||
|
|
||||||
@@ -853,6 +869,18 @@ namespace ns {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you want to inherit the `person` struct and add a field to it, it can be done with:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
namespace ns {
|
||||||
|
struct person_derived : person {
|
||||||
|
std::string email;
|
||||||
|
};
|
||||||
|
|
||||||
|
NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE(person_derived, person, email)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Here is another example with private members, where [`NLOHMANN_DEFINE_TYPE_INTRUSIVE`](https://json.nlohmann.me/api/macros/nlohmann_define_type_intrusive/) is needed:
|
Here is another example with private members, where [`NLOHMANN_DEFINE_TYPE_INTRUSIVE`](https://json.nlohmann.me/api/macros/nlohmann_define_type_intrusive/) is needed:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
@@ -869,11 +897,29 @@ namespace ns {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Or in case if you use some naming convention that you do not want to expose to JSON:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
namespace ns {
|
||||||
|
class address {
|
||||||
|
private:
|
||||||
|
std::string m_street;
|
||||||
|
int m_housenumber;
|
||||||
|
int m_postcode;
|
||||||
|
|
||||||
|
public:
|
||||||
|
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_NAMES(address, "street", m_street,
|
||||||
|
"housenumber", m_housenumber,
|
||||||
|
"postcode", m_postcode)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
#### How do I convert third-party types?
|
#### How do I convert third-party types?
|
||||||
|
|
||||||
This requires a bit more advanced technique. But first, let's see how this conversion mechanism works:
|
This requires a bit more advanced technique. But first, let's see how this conversion mechanism works:
|
||||||
|
|
||||||
The library uses **JSON Serializers** to convert types to json.
|
The library uses **JSON Serializers** to convert types to JSON.
|
||||||
The default serializer for `nlohmann::json` is `nlohmann::adl_serializer` (ADL means [Argument-Dependent Lookup](https://en.cppreference.com/w/cpp/language/adl)).
|
The default serializer for `nlohmann::json` is `nlohmann::adl_serializer` (ADL means [Argument-Dependent Lookup](https://en.cppreference.com/w/cpp/language/adl)).
|
||||||
|
|
||||||
It is implemented like this (simplified):
|
It is implemented like this (simplified):
|
||||||
@@ -913,8 +959,8 @@ namespace nlohmann {
|
|||||||
if (j.is_null()) {
|
if (j.is_null()) {
|
||||||
opt = boost::none;
|
opt = boost::none;
|
||||||
} else {
|
} else {
|
||||||
opt = j.template get<T>(); // same as above, but with
|
opt = j.get<T>(); // same as above, but with
|
||||||
// adl_serializer<T>::from_json
|
// adl_serializer<T>::from_json
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -923,7 +969,7 @@ namespace nlohmann {
|
|||||||
|
|
||||||
#### How can I use `get()` for non-default constructible/non-copyable types?
|
#### How can I use `get()` for non-default constructible/non-copyable types?
|
||||||
|
|
||||||
There is a way, if your type is [MoveConstructible](https://en.cppreference.com/w/cpp/named_req/MoveConstructible). You will need to specialize the `adl_serializer` as well, but with a special `from_json` overload:
|
There is a way if your type is [MoveConstructible](https://en.cppreference.com/w/cpp/named_req/MoveConstructible). You will need to specialize the `adl_serializer` as well, but with a special `from_json` overload:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
struct move_only_type {
|
struct move_only_type {
|
||||||
@@ -941,7 +987,7 @@ namespace nlohmann {
|
|||||||
// note: the return type is no longer 'void', and the method only takes
|
// note: the return type is no longer 'void', and the method only takes
|
||||||
// one argument
|
// one argument
|
||||||
static move_only_type from_json(const json& j) {
|
static move_only_type from_json(const json& j) {
|
||||||
return {j.template get<int>()};
|
return {j.get<int>()};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Here's the catch! You must provide a to_json method! Otherwise, you
|
// Here's the catch! You must provide a to_json method! Otherwise, you
|
||||||
@@ -1005,14 +1051,14 @@ struct bad_serializer
|
|||||||
static void to_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!
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
### Specializing enum conversion
|
### Specializing enum conversion
|
||||||
|
|
||||||
By default, enum values are serialized to JSON as integers. In some cases this could result in undesired behavior. If an enum is modified or re-ordered after data has been serialized to JSON, the later de-serialized JSON data may be undefined or a different enum value than was originally intended.
|
By default, enum values are serialized to JSON as integers. In some cases, this could result in undesired behavior. If an enum is modified or re-ordered after data has been serialized to JSON, the later deserialized JSON data may be undefined or a different enum value than was originally intended.
|
||||||
|
|
||||||
It is possible to more precisely specify how a given enum is mapped to and from JSON as shown below:
|
It is possible to more precisely specify how a given enum is mapped to and from JSON as shown below:
|
||||||
|
|
||||||
@@ -1045,11 +1091,11 @@ assert(j == "stopped");
|
|||||||
|
|
||||||
// json string to enum
|
// json string to enum
|
||||||
json j3 = "running";
|
json j3 = "running";
|
||||||
assert(j3.template get<TaskState>() == TS_RUNNING);
|
assert(j3.get<TaskState>() == TS_RUNNING);
|
||||||
|
|
||||||
// undefined json value to enum (where the first map entry above is the default)
|
// undefined json value to enum (where the first map entry above is the default)
|
||||||
json jPi = 3.14;
|
json jPi = 3.14;
|
||||||
assert(jPi.template get<TaskState>() == TS_INVALID);
|
assert(jPi.get<TaskState>() == TS_INVALID);
|
||||||
```
|
```
|
||||||
|
|
||||||
Just as in [Arbitrary Type Conversions](#arbitrary-types-conversions) above,
|
Just as in [Arbitrary Type Conversions](#arbitrary-types-conversions) above,
|
||||||
@@ -1059,7 +1105,7 @@ Just as in [Arbitrary Type Conversions](#arbitrary-types-conversions) above,
|
|||||||
|
|
||||||
Other Important points:
|
Other Important points:
|
||||||
|
|
||||||
- When using `template get<ENUM_TYPE>()`, undefined JSON values will default to the first pair specified in your map. Select this default pair carefully.
|
- When using `get<ENUM_TYPE>()`, undefined JSON values will default to the first pair specified in your map. Select this default pair carefully. If you desire an exception in this circumstance use `NLOHMANN_JSON_SERIALIZE_ENUM_STRICT()` which behaves identically except for throwing an exception on unrecognized values.
|
||||||
- If an enum or JSON value is specified more than once in your map, the first matching occurrence from the top of the map will be returned when converting to or from JSON.
|
- If an enum or JSON value is specified more than once in your map, the first matching occurrence from the top of the map will be returned when converting to or from JSON.
|
||||||
|
|
||||||
### Binary formats (BSON, CBOR, MessagePack, UBJSON, and BJData)
|
### Binary formats (BSON, CBOR, MessagePack, UBJSON, and BJData)
|
||||||
@@ -1141,7 +1187,7 @@ The library is used in multiple projects, applications, operating systems, etc.
|
|||||||
|
|
||||||
## Supported compilers
|
## Supported compilers
|
||||||
|
|
||||||
Though it's 2025 already, the support for C++11 is still a bit sparse. Currently, the following compilers are known to work:
|
Though it's 2026 already, the support for C++11 is still a bit sparse. Currently, the following compilers are known to work:
|
||||||
|
|
||||||
- GCC 4.8 - 14.2 (and possibly later)
|
- GCC 4.8 - 14.2 (and possibly later)
|
||||||
- Clang 3.4 - 21.0 (and possibly later)
|
- Clang 3.4 - 21.0 (and possibly later)
|
||||||
@@ -1168,7 +1214,7 @@ Please note:
|
|||||||
|
|
||||||
The code compiles successfully with [Android NDK](https://developer.android.com/ndk/index.html?hl=ml), Revision 9 - 11 (and possibly later) and [CrystaX's Android NDK](https://www.crystax.net/en/android/ndk) version 10.
|
The code compiles successfully with [Android NDK](https://developer.android.com/ndk/index.html?hl=ml), Revision 9 - 11 (and possibly later) and [CrystaX's Android NDK](https://www.crystax.net/en/android/ndk) version 10.
|
||||||
|
|
||||||
- For GCC running on MinGW or Android SDK, the error `'to_string' is not a member of 'std'` (or similarly, for `strtod` or `strtof`) may occur. Note this is not an issue with the code, but rather with the compiler itself. On Android, see above to build with a newer environment. For MinGW, please refer to [this site](https://tehsausage.com/mingw-to-string) and [this discussion](https://github.com/nlohmann/json/issues/136) for information on how to fix this bug. For Android NDK using `APP_STL := gnustl_static`, please refer to [this discussion](https://github.com/nlohmann/json/issues/219).
|
- For GCC running on MinGW or Android SDK, the error `'to_string' is not a member of 'std'` (or similarly, for `strtod` or `strtof`) may occur. Note this is not an issue with the code, but rather with the compiler itself. On Android, see above to build with a newer environment. For MinGW, please refer to [this site](https://tehsausage.com/mingw-to-string) and [this discussion](https://github.com/nlohmann/json/issues/136) for information on how to fix this bug. For Android NDK using `APP_STL := gnustl_static`, please refer to [this discussion](https://github.com/nlohmann/json/issues/219).
|
||||||
|
|
||||||
- Unsupported versions of GCC and Clang are rejected by `#error` directives. This can be switched off by defining `JSON_SKIP_UNSUPPORTED_COMPILER_CHECK`. Note that you can expect no support in this case.
|
- Unsupported versions of GCC and Clang are rejected by `#error` directives. This can be switched off by defining `JSON_SKIP_UNSUPPORTED_COMPILER_CHECK`. Note that you can expect no support in this case.
|
||||||
|
|
||||||
@@ -1187,7 +1233,7 @@ using json = nlohmann::json;
|
|||||||
|
|
||||||
to the files you want to process JSON and set the necessary switches to enable C++11 (e.g., `-std=c++11` for GCC and Clang).
|
to the files you want to process JSON and set the necessary switches to enable C++11 (e.g., `-std=c++11` for GCC and Clang).
|
||||||
|
|
||||||
You can further use file [`include/nlohmann/json_fwd.hpp`](https://github.com/nlohmann/json/blob/develop/include/nlohmann/json_fwd.hpp) for forward-declarations. The installation of json_fwd.hpp (as part of cmake's install step), can be achieved by setting `-DJSON_MultipleHeaders=ON`.
|
You can further use file [`include/nlohmann/json_fwd.hpp`](https://github.com/nlohmann/json/blob/develop/include/nlohmann/json_fwd.hpp) for forward-declarations. The installation of `json_fwd.hpp` (as part of cmake's install step) can be achieved by setting `-DJSON_MultipleHeaders=ON`.
|
||||||
|
|
||||||
### CMake
|
### CMake
|
||||||
|
|
||||||
@@ -1249,7 +1295,7 @@ FetchContent_MakeAvailable(json)
|
|||||||
target_link_libraries(foo PRIVATE nlohmann_json::nlohmann_json)
|
target_link_libraries(foo PRIVATE nlohmann_json::nlohmann_json)
|
||||||
```
|
```
|
||||||
|
|
||||||
**Note**: It is recommended to use the URL approach described above which is supported as of version 3.10.0. See
|
**Note**: It is recommended to use the URL approach described above, which is supported as of version 3.10.0. See
|
||||||
<https://json.nlohmann.me/integration/cmake/#fetchcontent> for more information.
|
<https://json.nlohmann.me/integration/cmake/#fetchcontent> for more information.
|
||||||
|
|
||||||
#### Supporting Both
|
#### Supporting Both
|
||||||
@@ -1320,7 +1366,7 @@ pkg-config nlohmann_json --cflags
|
|||||||
|
|
||||||
The class is licensed under the [MIT License](https://opensource.org/licenses/MIT):
|
The class is licensed under the [MIT License](https://opensource.org/licenses/MIT):
|
||||||
|
|
||||||
Copyright © 2013-2025 [Niels Lohmann](https://nlohmann.me)
|
Copyright © 2013-2026 [Niels Lohmann](https://nlohmann.me)
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
@@ -1371,13 +1417,13 @@ I deeply appreciate the help of the following people.
|
|||||||
9. [Florian Weber](https://github.com/Florianjw) fixed a bug in and improved the performance of the comparison operators.
|
9. [Florian Weber](https://github.com/Florianjw) fixed a bug in and improved the performance of the comparison operators.
|
||||||
10. [Eric Cornelius](https://github.com/EricMCornelius) pointed out a bug in the handling with NaN and infinity values. He also improved the performance of the string escaping.
|
10. [Eric Cornelius](https://github.com/EricMCornelius) pointed out a bug in the handling with NaN and infinity values. He also improved the performance of the string escaping.
|
||||||
11. [易思龙](https://github.com/likebeta) implemented a conversion from anonymous enums.
|
11. [易思龙](https://github.com/likebeta) implemented a conversion from anonymous enums.
|
||||||
12. [kepkin](https://github.com/kepkin) patiently pushed forward the support for Microsoft Visual studio.
|
12. [kepkin](https://github.com/kepkin) patiently pushed forward the support for Microsoft Visual Studio.
|
||||||
13. [gregmarr](https://github.com/gregmarr) simplified the implementation of reverse iterators and helped with numerous hints and improvements. In particular, he pushed forward the implementation of user-defined types.
|
13. [gregmarr](https://github.com/gregmarr) simplified the implementation of reverse iterators and helped with numerous hints and improvements. In particular, he pushed forward the implementation of user-defined types.
|
||||||
14. [Caio Luppi](https://github.com/caiovlp) fixed a bug in the Unicode handling.
|
14. [Caio Luppi](https://github.com/caiovlp) fixed a bug in the Unicode handling.
|
||||||
15. [dariomt](https://github.com/dariomt) fixed some typos in the examples.
|
15. [dariomt](https://github.com/dariomt) fixed some typos in the examples.
|
||||||
16. [Daniel Frey](https://github.com/d-frey) cleaned up some pointers and implemented exception-safe memory allocation.
|
16. [Daniel Frey](https://github.com/d-frey) cleaned up some pointers and implemented exception-safe memory allocation.
|
||||||
17. [Colin Hirsch](https://github.com/ColinH) took care of a small namespace issue.
|
17. [Colin Hirsch](https://github.com/ColinH) took care of a small namespace issue.
|
||||||
18. [Huu Nguyen](https://github.com/whoshuu) correct a variable name in the documentation.
|
18. [Huu Nguyen](https://github.com/whoshuu) corrected a variable name in the documentation.
|
||||||
19. [Silverweed](https://github.com/silverweed) overloaded `parse()` to accept an rvalue reference.
|
19. [Silverweed](https://github.com/silverweed) overloaded `parse()` to accept an rvalue reference.
|
||||||
20. [dariomt](https://github.com/dariomt) fixed a subtlety in MSVC type support and implemented the `get_ref()` function to get a reference to stored values.
|
20. [dariomt](https://github.com/dariomt) fixed a subtlety in MSVC type support and implemented the `get_ref()` function to get a reference to stored values.
|
||||||
21. [ZahlGraf](https://github.com/ZahlGraf) added a workaround that allows compilation using Android NDK.
|
21. [ZahlGraf](https://github.com/ZahlGraf) added a workaround that allows compilation using Android NDK.
|
||||||
@@ -1412,7 +1458,7 @@ I deeply appreciate the help of the following people.
|
|||||||
50. [Jared Grubb](https://github.com/jaredgrubb) silenced a nasty documentation warning.
|
50. [Jared Grubb](https://github.com/jaredgrubb) silenced a nasty documentation warning.
|
||||||
51. [Yixin Zhang](https://github.com/qwename) fixed an integer overflow check.
|
51. [Yixin Zhang](https://github.com/qwename) fixed an integer overflow check.
|
||||||
52. [Bosswestfalen](https://github.com/Bosswestfalen) merged two iterator classes into a smaller one.
|
52. [Bosswestfalen](https://github.com/Bosswestfalen) merged two iterator classes into a smaller one.
|
||||||
53. [Daniel599](https://github.com/Daniel599) helped to get Travis execute the tests with Clang's sanitizers.
|
53. [Daniel599](https://github.com/Daniel599) helped to get Travis to execute the tests with Clang's sanitizers.
|
||||||
54. [Jonathan Lee](https://github.com/vjon) fixed an example in the README file.
|
54. [Jonathan Lee](https://github.com/vjon) fixed an example in the README file.
|
||||||
55. [gnzlbg](https://github.com/gnzlbg) supported the implementation of user-defined types.
|
55. [gnzlbg](https://github.com/gnzlbg) supported the implementation of user-defined types.
|
||||||
56. [Alexej Harm](https://github.com/qis) helped to get the user-defined types working with Visual Studio.
|
56. [Alexej Harm](https://github.com/qis) helped to get the user-defined types working with Visual Studio.
|
||||||
@@ -1433,7 +1479,7 @@ I deeply appreciate the help of the following people.
|
|||||||
71. [Vincent Thiery](https://github.com/vthiery) maintains a package for the Conan package manager.
|
71. [Vincent Thiery](https://github.com/vthiery) maintains a package for the Conan package manager.
|
||||||
72. [Steffen](https://github.com/koemeet) fixed a potential issue with MSVC and `std::min`.
|
72. [Steffen](https://github.com/koemeet) fixed a potential issue with MSVC and `std::min`.
|
||||||
73. [Mike Tzou](https://github.com/Chocobo1) fixed some typos.
|
73. [Mike Tzou](https://github.com/Chocobo1) fixed some typos.
|
||||||
74. [amrcode](https://github.com/amrcode) noted a misleading documentation about comparison of floats.
|
74. [amrcode](https://github.com/amrcode) noted misleading documentation about comparison of floats.
|
||||||
75. [Oleg Endo](https://github.com/olegendo) reduced the memory consumption by replacing `<iostream>` with `<iosfwd>`.
|
75. [Oleg Endo](https://github.com/olegendo) reduced the memory consumption by replacing `<iostream>` with `<iosfwd>`.
|
||||||
76. [dan-42](https://github.com/dan-42) cleaned up the CMake files to simplify including/reusing of the library.
|
76. [dan-42](https://github.com/dan-42) cleaned up the CMake files to simplify including/reusing of the library.
|
||||||
77. [Nikita Ofitserov](https://github.com/himikof) allowed for moving values from initializer lists.
|
77. [Nikita Ofitserov](https://github.com/himikof) allowed for moving values from initializer lists.
|
||||||
@@ -1460,13 +1506,13 @@ I deeply appreciate the help of the following people.
|
|||||||
98. [Vadim Evard](https://github.com/Pipeliner) fixed a Markdown issue in the README.
|
98. [Vadim Evard](https://github.com/Pipeliner) fixed a Markdown issue in the README.
|
||||||
99. [zerodefect](https://github.com/zerodefect) fixed a compiler warning.
|
99. [zerodefect](https://github.com/zerodefect) fixed a compiler warning.
|
||||||
100. [Kert](https://github.com/kaidokert) allowed to template the string type in the serialization and added the possibility to override the exceptional behavior.
|
100. [Kert](https://github.com/kaidokert) allowed to template the string type in the serialization and added the possibility to override the exceptional behavior.
|
||||||
101. [mark-99](https://github.com/mark-99) helped fixing an ICC error.
|
101. [mark-99](https://github.com/mark-99) helped fix an ICC error.
|
||||||
102. [Patrik Huber](https://github.com/patrikhuber) fixed links in the README file.
|
102. [Patrik Huber](https://github.com/patrikhuber) fixed links in the README file.
|
||||||
103. [johnfb](https://github.com/johnfb) found a bug in the implementation of CBOR's indefinite length strings.
|
103. [johnfb](https://github.com/johnfb) found a bug in the implementation of CBOR's indefinite length strings.
|
||||||
104. [Paul Fultz II](https://github.com/pfultz2) added a note on the cget package manager.
|
104. [Paul Fultz II](https://github.com/pfultz2) added a note on the cget package manager.
|
||||||
105. [Wilson Lin](https://github.com/wla80) made the integration section of the README more concise.
|
105. [Wilson Lin](https://github.com/wla80) made the integration section of the README more concise.
|
||||||
106. [RalfBielig](https://github.com/ralfbielig) detected and fixed a memory leak in the parser callback.
|
106. [RalfBielig](https://github.com/ralfbielig) detected and fixed a memory leak in the parser callback.
|
||||||
107. [agrianius](https://github.com/agrianius) allowed to dump JSON to an alternative string type.
|
107. [agrianius](https://github.com/agrianius) allowed dumping JSON to an alternative string type.
|
||||||
108. [Kevin Tonon](https://github.com/ktonon) overworked the C++11 compiler checks in CMake.
|
108. [Kevin Tonon](https://github.com/ktonon) overworked the C++11 compiler checks in CMake.
|
||||||
109. [Axel Huebl](https://github.com/ax3l) simplified a CMake check and added support for the [Spack package manager](https://spack.io).
|
109. [Axel Huebl](https://github.com/ax3l) simplified a CMake check and added support for the [Spack package manager](https://spack.io).
|
||||||
110. [Carlos O'Ryan](https://github.com/coryan) fixed a typo.
|
110. [Carlos O'Ryan](https://github.com/coryan) fixed a typo.
|
||||||
@@ -1515,12 +1561,12 @@ I deeply appreciate the help of the following people.
|
|||||||
153. [Ivor Wanders](https://github.com/iwanders) helped to reduce the CMake requirement to version 3.1.
|
153. [Ivor Wanders](https://github.com/iwanders) helped to reduce the CMake requirement to version 3.1.
|
||||||
154. [njlr](https://github.com/njlr) updated the Buckaroo instructions.
|
154. [njlr](https://github.com/njlr) updated the Buckaroo instructions.
|
||||||
155. [Lion](https://github.com/lieff) fixed a compilation issue with GCC 7 on CentOS.
|
155. [Lion](https://github.com/lieff) fixed a compilation issue with GCC 7 on CentOS.
|
||||||
156. [Isaac Nickaein](https://github.com/nickaein) improved the integer serialization performance and implemented the `contains()` function.
|
156. [Isaac Nickaein](https://github.com/nickaein) improved the integer serialization performance and implemented the `contains()` function.
|
||||||
157. [past-due](https://github.com/past-due) suppressed an unfixable warning.
|
157. [past-due](https://github.com/past-due) suppressed an unfixable warning.
|
||||||
158. [Elvis Oric](https://github.com/elvisoric) improved Meson support.
|
158. [Elvis Oric](https://github.com/elvisoric) improved Meson support.
|
||||||
159. [Matěj Plch](https://github.com/Afforix) fixed an example in the README.
|
159. [Matěj Plch](https://github.com/Afforix) fixed an example in the README.
|
||||||
160. [Mark Beckwith](https://github.com/wythe) fixed a typo.
|
160. [Mark Beckwith](https://github.com/wythe) fixed a typo.
|
||||||
161. [scinart](https://github.com/scinart) fixed bug in the serializer.
|
161. [scinart](https://github.com/scinart) fixed a bug in the serializer.
|
||||||
162. [Patrick Boettcher](https://github.com/pboettch) implemented `push_back()` and `pop_back()` for JSON Pointers.
|
162. [Patrick Boettcher](https://github.com/pboettch) implemented `push_back()` and `pop_back()` for JSON Pointers.
|
||||||
163. [Bruno Oliveira](https://github.com/nicoddemus) added support for Conda.
|
163. [Bruno Oliveira](https://github.com/nicoddemus) added support for Conda.
|
||||||
164. [Michele Caini](https://github.com/skypjack) fixed links in the README.
|
164. [Michele Caini](https://github.com/skypjack) fixed links in the README.
|
||||||
@@ -1562,7 +1608,7 @@ I deeply appreciate the help of the following people.
|
|||||||
200. [Alexander “weej” Jones](https://github.com/alex-weej) fixed an example in the README.
|
200. [Alexander “weej” Jones](https://github.com/alex-weej) fixed an example in the README.
|
||||||
201. [Antoine Cœur](https://github.com/Coeur) fixed some typos in the documentation.
|
201. [Antoine Cœur](https://github.com/Coeur) fixed some typos in the documentation.
|
||||||
202. [jothepro](https://github.com/jothepro) updated links to the Hunter package.
|
202. [jothepro](https://github.com/jothepro) updated links to the Hunter package.
|
||||||
203. [Dave Lee](https://github.com/kastiglione) fixed link in the README.
|
203. [Dave Lee](https://github.com/kastiglione) fixed a link in the README.
|
||||||
204. [Joël Lamotte](https://github.com/Klaim) added instruction for using Build2's package manager.
|
204. [Joël Lamotte](https://github.com/Klaim) added instruction for using Build2's package manager.
|
||||||
205. [Paul Jurczak](https://github.com/pauljurczak) fixed an example in the README.
|
205. [Paul Jurczak](https://github.com/pauljurczak) fixed an example in the README.
|
||||||
206. [Sonu Lohani](https://github.com/sonulohani) fixed a warning.
|
206. [Sonu Lohani](https://github.com/sonulohani) fixed a warning.
|
||||||
@@ -1605,7 +1651,7 @@ I deeply appreciate the help of the following people.
|
|||||||
243. [raduteo](https://github.com/raduteo) fixed a warning.
|
243. [raduteo](https://github.com/raduteo) fixed a warning.
|
||||||
244. [David Pfahler](https://github.com/theShmoo) added the possibility to compile the library without I/O support.
|
244. [David Pfahler](https://github.com/theShmoo) added the possibility to compile the library without I/O support.
|
||||||
245. [Morten Fyhn Amundsen](https://github.com/mortenfyhn) fixed a typo.
|
245. [Morten Fyhn Amundsen](https://github.com/mortenfyhn) fixed a typo.
|
||||||
246. [jpl-mac](https://github.com/jpl-mac) allowed to treat the library as a system header in CMake.
|
246. [jpl-mac](https://github.com/jpl-mac) allowed treating the library as a system header in CMake.
|
||||||
247. [Jason Dsouza](https://github.com/jasmcaus) fixed the indentation of the CMake file.
|
247. [Jason Dsouza](https://github.com/jasmcaus) fixed the indentation of the CMake file.
|
||||||
248. [offa](https://github.com/offa) added a link to Conan Center to the documentation.
|
248. [offa](https://github.com/offa) added a link to Conan Center to the documentation.
|
||||||
249. [TotalCaesar659](https://github.com/TotalCaesar659) updated the links in the documentation to use HTTPS.
|
249. [TotalCaesar659](https://github.com/TotalCaesar659) updated the links in the documentation to use HTTPS.
|
||||||
@@ -1647,7 +1693,7 @@ I deeply appreciate the help of the following people.
|
|||||||
285. [Wolf Vollprecht](https://github.com/wolfv) added the `patch_inplace` function.
|
285. [Wolf Vollprecht](https://github.com/wolfv) added the `patch_inplace` function.
|
||||||
286. [Jake Zimmerman](https://github.com/jez) highlighted common usage patterns in the README file.
|
286. [Jake Zimmerman](https://github.com/jez) highlighted common usage patterns in the README file.
|
||||||
287. [NN](https://github.com/NN---) added the Visual Studio output directory to `.gitignore`.
|
287. [NN](https://github.com/NN---) added the Visual Studio output directory to `.gitignore`.
|
||||||
288. [Romain Reignier](https://github.com/romainreignier) improved the performance the vector output adapter.
|
288. [Romain Reignier](https://github.com/romainreignier) improved the performance of the vector output adapter.
|
||||||
289. [Mike](https://github.com/Mike-Leo-Smith) fixed the `std::iterator_traits`.
|
289. [Mike](https://github.com/Mike-Leo-Smith) fixed the `std::iterator_traits`.
|
||||||
290. [Richard Hozák](https://github.com/zxey) added macro `JSON_NO_ENUM` to disable default enum conversions.
|
290. [Richard Hozák](https://github.com/zxey) added macro `JSON_NO_ENUM` to disable default enum conversions.
|
||||||
291. [vakokako](https://github.com/vakokako) fixed tests when compiling with C++20.
|
291. [vakokako](https://github.com/vakokako) fixed tests when compiling with C++20.
|
||||||
@@ -1694,9 +1740,9 @@ I deeply appreciate the help of the following people.
|
|||||||
332. [taro](https://github.com/tarolling) fixed a typo in the `CODEOWNERS` file.
|
332. [taro](https://github.com/tarolling) fixed a typo in the `CODEOWNERS` file.
|
||||||
333. [Ikko Eltociear Ashimine](https://github.com/eltociear) fixed a typo.
|
333. [Ikko Eltociear Ashimine](https://github.com/eltociear) fixed a typo.
|
||||||
334. [Felix Yan](https://github.com/felixonmars) fixed a typo in the README.
|
334. [Felix Yan](https://github.com/felixonmars) fixed a typo in the README.
|
||||||
335. [HO-COOH](https://github.com/HO-COOH) fixed a parentheses in the documentation.
|
335. [HO-COOH](https://github.com/HO-COOH) fixed a parenthesis in the documentation.
|
||||||
336. [Ivor Wanders](https://github.com/iwanders) fixed the examples to catch exception by `const&`.
|
336. [Ivor Wanders](https://github.com/iwanders) fixed the examples to catch exception by `const&`.
|
||||||
337. [miny1233](https://github.com/miny1233) fixed a parentheses in the documentation.
|
337. [miny1233](https://github.com/miny1233) fixed a parenthesis in the documentation.
|
||||||
338. [tomalakgeretkal](https://github.com/tomalakgeretkal) fixed a compilation error.
|
338. [tomalakgeretkal](https://github.com/tomalakgeretkal) fixed a compilation error.
|
||||||
339. [alferov](https://github.com/ALF-ONE) fixed a compilation error.
|
339. [alferov](https://github.com/ALF-ONE) fixed a compilation error.
|
||||||
340. [Craig Scott](https://github.com/craigscott-crascit) fixed a deprecation warning in CMake.
|
340. [Craig Scott](https://github.com/craigscott-crascit) fixed a deprecation warning in CMake.
|
||||||
@@ -1779,7 +1825,7 @@ The library itself consists of a single header file licensed under the MIT licen
|
|||||||
|
|
||||||
The library supports **Unicode input** as follows:
|
The library supports **Unicode input** as follows:
|
||||||
|
|
||||||
- Only **UTF-8** encoded input is supported which is the default encoding for JSON according to [RFC 8259](https://tools.ietf.org/html/rfc8259.html#section-8.1).
|
- Only **UTF-8** encoded input is supported, which is the default encoding for JSON according to [RFC 8259](https://tools.ietf.org/html/rfc8259.html#section-8.1).
|
||||||
- `std::u16string` and `std::u32string` can be parsed, assuming UTF-16 and UTF-32 encoding, respectively. These encodings are not supported when reading from files or other input containers.
|
- `std::u16string` and `std::u32string` can be parsed, assuming UTF-16 and UTF-32 encoding, respectively. These encodings are not supported when reading from files or other input containers.
|
||||||
- Other encodings such as Latin-1 or ISO 8859-1 are **not** supported and will yield parse or serialization errors.
|
- Other encodings such as Latin-1 or ISO 8859-1 are **not** supported and will yield parse or serialization errors.
|
||||||
- [Unicode noncharacters](https://www.unicode.org/faq/private_use.html#nonchar1) will not be replaced by the library.
|
- [Unicode noncharacters](https://www.unicode.org/faq/private_use.html#nonchar1) will not be replaced by the library.
|
||||||
@@ -1801,7 +1847,17 @@ This library does not support comments by default. It does so for three reasons:
|
|||||||
|
|
||||||
3. It is dangerous for interoperability if some libraries would add comment support while others don't. Please check [The Harmful Consequences of the Robustness Principle](https://tools.ietf.org/html/draft-iab-protocol-maintenance-01) on this.
|
3. It is dangerous for interoperability if some libraries would add comment support while others don't. Please check [The Harmful Consequences of the Robustness Principle](https://tools.ietf.org/html/draft-iab-protocol-maintenance-01) on this.
|
||||||
|
|
||||||
However, you can pass set parameter `ignore_comments` to true in the `parse` function to ignore `//` or `/* */` comments. Comments will then be treated as whitespace.
|
However, you can set set parameter `ignore_comments` to true in the `parse` function to ignore `//` or `/* */` comments. Comments will then be treated as whitespace.
|
||||||
|
|
||||||
|
### Trailing commas
|
||||||
|
|
||||||
|
The JSON specification does not allow trailing commas in arrays and objects, and hence this library is treating them as parsing errors by default.
|
||||||
|
|
||||||
|
Like comments, you can set parameter `ignore_trailing_commas` to true in the `parse` function to ignore trailing commas in arrays and objects. Note that a single comma as the only content of the array or object (`[,]` or `{,}`) is not allowed, and multiple trailing commas (`[1,,]`) are not allowed either.
|
||||||
|
|
||||||
|
This library does not add trailing commas when serializing JSON data.
|
||||||
|
|
||||||
|
For more information, see [JSON With Commas and Comments (JWCC)](https://nigeltao.github.io/blog/2021/json-with-commas-comments.html).
|
||||||
|
|
||||||
### Order of object keys
|
### Order of object keys
|
||||||
|
|
||||||
@@ -1841,7 +1897,7 @@ ctest --output-on-failure
|
|||||||
|
|
||||||
Note that during the `ctest` stage, several JSON test files are downloaded from an [external repository](https://github.com/nlohmann/json_test_data). If policies forbid downloading artifacts during testing, you can download the files yourself and pass the directory with the test files via `-DJSON_TestDataDirectory=path` to CMake. Then, no Internet connectivity is required. See [issue #2189](https://github.com/nlohmann/json/issues/2189) for more information.
|
Note that during the `ctest` stage, several JSON test files are downloaded from an [external repository](https://github.com/nlohmann/json_test_data). If policies forbid downloading artifacts during testing, you can download the files yourself and pass the directory with the test files via `-DJSON_TestDataDirectory=path` to CMake. Then, no Internet connectivity is required. See [issue #2189](https://github.com/nlohmann/json/issues/2189) for more information.
|
||||||
|
|
||||||
If the test suite is not found, several test suites will fail like this:
|
If the testdata is not found, several test suites will fail like this:
|
||||||
|
|
||||||
```
|
```
|
||||||
===============================================================================
|
===============================================================================
|
||||||
@@ -1859,6 +1915,8 @@ json/tests/src/make_test_data_available.hpp:23: FATAL ERROR: REQUIRE( utils::che
|
|||||||
|
|
||||||
In case you have downloaded the library rather than checked out the code via Git, test `cmake_fetch_content_configure` will fail. Please execute `ctest -LE git_required` to skip these tests. See [issue #2189](https://github.com/nlohmann/json/issues/2189) for more information.
|
In case you have downloaded the library rather than checked out the code via Git, test `cmake_fetch_content_configure` will fail. Please execute `ctest -LE git_required` to skip these tests. See [issue #2189](https://github.com/nlohmann/json/issues/2189) for more information.
|
||||||
|
|
||||||
|
Some tests are requiring network to be properly execute. They are labeled as `git_required`. Please execute `ctest -LE git_required` to skip these tests. See [issue #4851](https://github.com/nlohmann/json/issues/4851) for more information.
|
||||||
|
|
||||||
Some tests change the installed files and hence make the whole process not reproducible. Please execute `ctest -LE not_reproducible` to skip these tests. See [issue #2324](https://github.com/nlohmann/json/issues/2324) for more information. Furthermore, assertions must be switched off to ensure reproducible builds (see [discussion 4494](https://github.com/nlohmann/json/discussions/4494)).
|
Some tests change the installed files and hence make the whole process not reproducible. Please execute `ctest -LE not_reproducible` to skip these tests. See [issue #2324](https://github.com/nlohmann/json/issues/2324) for more information. Furthermore, assertions must be switched off to ensure reproducible builds (see [discussion 4494](https://github.com/nlohmann/json/discussions/4494)).
|
||||||
|
|
||||||
Note you need to call `cmake -LE "not_reproducible|git_required"` to exclude both labels. See [issue #2596](https://github.com/nlohmann/json/issues/2596) for more information.
|
Note you need to call `cmake -LE "not_reproducible|git_required"` to exclude both labels. See [issue #2596](https://github.com/nlohmann/json/issues/2596) for more information.
|
||||||
|
|||||||
+17
-1
@@ -212,6 +212,21 @@ add_custom_target(ci_test_legacycomparison
|
|||||||
COMMENT "Compile and test with legacy discarded value comparison enabled"
|
COMMENT "Compile and test with legacy discarded value comparison enabled"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Enable brace-init copy semantics.
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
add_custom_target(ci_test_brace_init_copy_semantics
|
||||||
|
COMMAND ${CMAKE_COMMAND}
|
||||||
|
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||||
|
-DJSON_BuildTests=ON -DJSON_FastTests=ON
|
||||||
|
-DCMAKE_CXX_FLAGS=-DJSON_BRACE_INIT_COPY_SEMANTICS=1
|
||||||
|
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_brace_init_copy_semantics
|
||||||
|
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_brace_init_copy_semantics
|
||||||
|
COMMAND cd ${PROJECT_BINARY_DIR}/build_brace_init_copy_semantics && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
|
||||||
|
COMMENT "Compile and test with brace-init copy semantics enabled"
|
||||||
|
)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Disable global UDLs.
|
# Disable global UDLs.
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@@ -665,7 +680,8 @@ add_custom_target(ci_cuda_example
|
|||||||
|
|
||||||
add_custom_target(ci_module_cpp20
|
add_custom_target(ci_module_cpp20
|
||||||
COMMAND ${CMAKE_COMMAND}
|
COMMAND ${CMAKE_COMMAND}
|
||||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||||
|
-DJSON_CI=ON -DNLOHMANN_JSON_BUILD_MODULES=ON -DJSON_Install=ON
|
||||||
-S${PROJECT_SOURCE_DIR}/tests/module_cpp20 -B${PROJECT_BINARY_DIR}/ci_module_cpp20
|
-S${PROJECT_SOURCE_DIR}/tests/module_cpp20 -B${PROJECT_BINARY_DIR}/ci_module_cpp20
|
||||||
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/ci_module_cpp20
|
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/ci_module_cpp20
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
# -Wno-padded We do not care about padding warnings.
|
# -Wno-padded We do not care about padding warnings.
|
||||||
# -Wno-covered-switch-default All switches list all cases and a default case.
|
# -Wno-covered-switch-default All switches list all cases and a default case.
|
||||||
# -Wno-unsafe-buffer-usage Otherwise Doctest would not compile.
|
# -Wno-unsafe-buffer-usage Otherwise Doctest would not compile.
|
||||||
|
# -Wno-missing-noreturn We found no way to silence this warning otherwise, see PR #4871
|
||||||
|
|
||||||
set(CLANG_CXXFLAGS
|
set(CLANG_CXXFLAGS
|
||||||
-Werror
|
-Werror
|
||||||
@@ -17,4 +18,5 @@ set(CLANG_CXXFLAGS
|
|||||||
-Wno-padded
|
-Wno-padded
|
||||||
-Wno-covered-switch-default
|
-Wno-covered-switch-default
|
||||||
-Wno-unsafe-buffer-usage
|
-Wno-unsafe-buffer-usage
|
||||||
|
-Wno-missing-noreturn
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Detect used C++ Standard Library
|
||||||
|
*
|
||||||
|
* This file is compiled and run via try_run in download_test_data.cmake.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
// see https://en.cppreference.com/w/cpp/header/ciso646
|
||||||
|
#if __cplusplus >= 202002L
|
||||||
|
#include <version>
|
||||||
|
#else
|
||||||
|
#include <ciso646>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
#if defined(_LIBCPP_VERSION)
|
||||||
|
std::printf("LLVM C++ Standard Library (libc++), _LIBCPP_VERSION=%d", _LIBCPP_VERSION);
|
||||||
|
#elif defined(__GLIBCXX__)
|
||||||
|
std::printf("GNU C++ Standard Library (libstdc++), __GLIBCXX__=%d", __GLIBCXX__);
|
||||||
|
#elif defined(_MSVC_STL_VERSION)
|
||||||
|
std::printf("Microsoft C++ Standard Library (MSVC STL), _MSVC_STL_VERSION=%d", _MSVC_STL_VERSION);
|
||||||
|
#elif defined(_LIBCUDACXX_VERSION)
|
||||||
|
std::printf("NVIDIA C++ Standard Library (libcudacxx), _LIBCUDACXX_VERSION=%d", _LIBCUDACXX_VERSION);
|
||||||
|
#elif defined(EASTL_VERSION)
|
||||||
|
std::printf("Electronic Arts Standard Template Library (EASTL), EASTL_VERSION=%d", EASTL_VERSION);
|
||||||
|
#else
|
||||||
|
std::printf("unknown");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
@@ -1,21 +1,33 @@
|
|||||||
set(JSON_TEST_DATA_URL https://github.com/nlohmann/json_test_data)
|
set(JSON_TEST_DATA_URL https://github.com/nlohmann/json_test_data)
|
||||||
set(JSON_TEST_DATA_VERSION 3.1.0)
|
set(JSON_TEST_DATA_VERSION 3.1.0)
|
||||||
|
|
||||||
|
include(ExternalProject)
|
||||||
|
|
||||||
# if variable is set, use test data from given directory rather than downloading them
|
# if variable is set, use test data from given directory rather than downloading them
|
||||||
if(JSON_TestDataDirectory)
|
if(JSON_TestDataDirectory)
|
||||||
message(STATUS "Using test data in ${JSON_TestDataDirectory}.")
|
message(STATUS "Using test data in ${JSON_TestDataDirectory}.")
|
||||||
add_custom_target(download_test_data)
|
add_custom_target(download_test_data)
|
||||||
file(WRITE ${CMAKE_BINARY_DIR}/include/test_data.hpp "#define TEST_DATA_DIRECTORY \"${JSON_TestDataDirectory}\"\n")
|
file(WRITE ${CMAKE_BINARY_DIR}/include/test_data.hpp "#define TEST_DATA_DIRECTORY \"${JSON_TestDataDirectory}\"\n")
|
||||||
else()
|
else()
|
||||||
find_package(Git)
|
# create a header with the path to the downloaded test data
|
||||||
|
file(WRITE ${CMAKE_BINARY_DIR}/include/test_data.hpp "#define TEST_DATA_DIRECTORY \"${CMAKE_BINARY_DIR}/test_files\"\n")
|
||||||
|
|
||||||
|
# download test data from GitHub release
|
||||||
|
ExternalProject_Add(download_test_data_project
|
||||||
|
URL "${JSON_TEST_DATA_URL}/archive/refs/tags/v${JSON_TEST_DATA_VERSION}.zip"
|
||||||
|
SOURCE_DIR "${CMAKE_BINARY_DIR}/test_files"
|
||||||
|
CONFIGURE_COMMAND ""
|
||||||
|
BUILD_COMMAND ""
|
||||||
|
INSTALL_COMMAND ""
|
||||||
|
LOG_DOWNLOAD TRUE
|
||||||
|
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
|
||||||
|
EXCLUDE_FROM_ALL TRUE
|
||||||
|
)
|
||||||
|
|
||||||
# target to download test data
|
# target to download test data
|
||||||
add_custom_target(download_test_data
|
add_custom_target(download_test_data
|
||||||
COMMAND test -d json_test_data || ${GIT_EXECUTABLE} clone -c advice.detachedHead=false --branch v${JSON_TEST_DATA_VERSION} ${JSON_TEST_DATA_URL}.git --quiet --depth 1
|
DEPENDS download_test_data_project
|
||||||
COMMENT "Downloading test data from ${JSON_TEST_DATA_URL} (v${JSON_TEST_DATA_VERSION})"
|
|
||||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
||||||
)
|
)
|
||||||
# create a header with the path to the downloaded test data
|
|
||||||
file(WRITE ${CMAKE_BINARY_DIR}/include/test_data.hpp "#define TEST_DATA_DIRECTORY \"${CMAKE_BINARY_DIR}/json_test_data\"\n")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# determine the operating system (for debug and support purposes)
|
# determine the operating system (for debug and support purposes)
|
||||||
@@ -54,3 +66,22 @@ else()
|
|||||||
endif()
|
endif()
|
||||||
string(REGEX REPLACE "[ ]*\n" "; " CXX_VERSION_RESULT "${CXX_VERSION_RESULT}")
|
string(REGEX REPLACE "[ ]*\n" "; " CXX_VERSION_RESULT "${CXX_VERSION_RESULT}")
|
||||||
message(STATUS "Compiler: ${CXX_VERSION_RESULT}")
|
message(STATUS "Compiler: ${CXX_VERSION_RESULT}")
|
||||||
|
|
||||||
|
# determine used C++ standard library (for debug and support purposes)
|
||||||
|
if(CMAKE_CROSSCOMPILING)
|
||||||
|
set(LIBCPP_VERSION_OUTPUT_CACHED "could not be detected due to cross-compiling" CACHE STRING "Detected C++ standard library version")
|
||||||
|
endif()
|
||||||
|
if(NOT DEFINED LIBCPP_VERSION_OUTPUT_CACHED)
|
||||||
|
try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR
|
||||||
|
"${CMAKE_BINARY_DIR}" SOURCES "${CMAKE_SOURCE_DIR}/cmake/detect_libcpp_version.cpp"
|
||||||
|
RUN_OUTPUT_VARIABLE LIBCPP_VERSION_OUTPUT
|
||||||
|
COMPILE_OUTPUT_VARIABLE LIBCPP_VERSION_COMPILE_OUTPUT
|
||||||
|
)
|
||||||
|
if(NOT LIBCPP_VERSION_OUTPUT)
|
||||||
|
set(LIBCPP_VERSION_OUTPUT "Unknown")
|
||||||
|
message(AUTHOR_WARNING "Failed to compile cmake/detect_libcpp_version to detect the used C++ standard library. This does not affect the library or the test cases. Please still create an issue at https://github.com/nlohmann/json to investigate this.\n${LIBCPP_VERSION_COMPILE_OUTPUT}")
|
||||||
|
endif()
|
||||||
|
set(LIBCPP_VERSION_OUTPUT_CACHED "${LIBCPP_VERSION_OUTPUT}" CACHE STRING "Detected C++ standard library version")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
message(STATUS "C++ standard library: ${LIBCPP_VERSION_OUTPUT_CACHED}")
|
||||||
|
|||||||
+28
-13
@@ -1,13 +1,13 @@
|
|||||||
# Warning flags determined for GCC 14.2.0 with https://github.com/nlohmann/gcc_flags:
|
# Warning flags determined for GCC 15.1.0 with https://github.com/nlohmann/gcc_flags:
|
||||||
# Ignored GCC warnings:
|
# Ignored GCC warnings:
|
||||||
# -Wno-abi-tag We do not care about ABI tags.
|
# -Wno-abi-tag We do not care about ABI tags.
|
||||||
# -Wno-aggregate-return The library uses aggregate returns.
|
# -Wno-aggregate-return The library uses aggregate returns.
|
||||||
# -Wno-long-long The library uses the long long type to interface with system functions.
|
# -Wno-long-long The library uses the long long type to interface with system functions.
|
||||||
# -Wno-namespaces The library uses namespaces.
|
# -Wno-namespaces The library uses namespaces.
|
||||||
# -Wno-nrvo Doctest triggers this warning.
|
# -Wno-nrvo Doctest triggers this warning.
|
||||||
# -Wno-padded We do not care about padding warnings.
|
# -Wno-padded We do not care about padding warnings.
|
||||||
# -Wno-system-headers We do not care about warnings in system headers.
|
# -Wno-system-headers We do not care about warnings in system headers.
|
||||||
# -Wno-templates The library uses templates.
|
# -Wno-templates The library uses templates.
|
||||||
|
|
||||||
set(GCC_CXXFLAGS
|
set(GCC_CXXFLAGS
|
||||||
-pedantic
|
-pedantic
|
||||||
@@ -65,6 +65,7 @@ set(GCC_CXXFLAGS
|
|||||||
-Wanalyzer-tainted-offset
|
-Wanalyzer-tainted-offset
|
||||||
-Wanalyzer-tainted-size
|
-Wanalyzer-tainted-size
|
||||||
-Wanalyzer-too-complex
|
-Wanalyzer-too-complex
|
||||||
|
-Wanalyzer-undefined-behavior-ptrdiff
|
||||||
-Wanalyzer-undefined-behavior-strtok
|
-Wanalyzer-undefined-behavior-strtok
|
||||||
-Wanalyzer-unsafe-call-within-signal-handler
|
-Wanalyzer-unsafe-call-within-signal-handler
|
||||||
-Wanalyzer-use-after-free
|
-Wanalyzer-use-after-free
|
||||||
@@ -123,6 +124,7 @@ set(GCC_CXXFLAGS
|
|||||||
-Wcoverage-invalid-line-number
|
-Wcoverage-invalid-line-number
|
||||||
-Wcoverage-mismatch
|
-Wcoverage-mismatch
|
||||||
-Wcoverage-too-many-conditions
|
-Wcoverage-too-many-conditions
|
||||||
|
-Wcoverage-too-many-paths
|
||||||
-Wcpp
|
-Wcpp
|
||||||
-Wctad-maybe-unsupported
|
-Wctad-maybe-unsupported
|
||||||
-Wctor-dtor-privacy
|
-Wctor-dtor-privacy
|
||||||
@@ -130,6 +132,7 @@ set(GCC_CXXFLAGS
|
|||||||
-Wdangling-pointer=2
|
-Wdangling-pointer=2
|
||||||
-Wdangling-reference
|
-Wdangling-reference
|
||||||
-Wdate-time
|
-Wdate-time
|
||||||
|
-Wdefaulted-function-deleted
|
||||||
-Wdelete-incomplete
|
-Wdelete-incomplete
|
||||||
-Wdelete-non-virtual-dtor
|
-Wdelete-non-virtual-dtor
|
||||||
-Wdeprecated
|
-Wdeprecated
|
||||||
@@ -138,6 +141,8 @@ set(GCC_CXXFLAGS
|
|||||||
-Wdeprecated-declarations
|
-Wdeprecated-declarations
|
||||||
-Wdeprecated-enum-enum-conversion
|
-Wdeprecated-enum-enum-conversion
|
||||||
-Wdeprecated-enum-float-conversion
|
-Wdeprecated-enum-float-conversion
|
||||||
|
-Wdeprecated-literal-operator
|
||||||
|
-Wdeprecated-variadic-comma-omission
|
||||||
-Wdisabled-optimization
|
-Wdisabled-optimization
|
||||||
-Wdiv-by-zero
|
-Wdiv-by-zero
|
||||||
-Wdouble-promotion
|
-Wdouble-promotion
|
||||||
@@ -157,20 +162,21 @@ set(GCC_CXXFLAGS
|
|||||||
-Wfloat-conversion
|
-Wfloat-conversion
|
||||||
-Wfloat-equal
|
-Wfloat-equal
|
||||||
-Wformat -Wformat-contains-nul
|
-Wformat -Wformat-contains-nul
|
||||||
|
-Wformat -Wformat-diag
|
||||||
-Wformat -Wformat-extra-args
|
-Wformat -Wformat-extra-args
|
||||||
-Wformat -Wformat-nonliteral
|
-Wformat -Wformat-nonliteral
|
||||||
|
-Wformat -Wformat-overflow=2
|
||||||
-Wformat -Wformat-security
|
-Wformat -Wformat-security
|
||||||
|
-Wformat -Wformat-signedness
|
||||||
|
-Wformat -Wformat-truncation=2
|
||||||
-Wformat -Wformat-y2k
|
-Wformat -Wformat-y2k
|
||||||
-Wformat -Wformat-zero-length
|
-Wformat -Wformat-zero-length
|
||||||
-Wformat-diag
|
|
||||||
-Wformat-overflow=2
|
|
||||||
-Wformat-signedness
|
|
||||||
-Wformat-truncation=2
|
|
||||||
-Wformat=2
|
-Wformat=2
|
||||||
-Wframe-address
|
-Wframe-address
|
||||||
-Wfree-nonheap-object
|
-Wfree-nonheap-object
|
||||||
-Wglobal-module
|
-Wglobal-module
|
||||||
-Whardened
|
-Whardened
|
||||||
|
-Wheader-guard
|
||||||
-Whsa
|
-Whsa
|
||||||
-Wif-not-aligned
|
-Wif-not-aligned
|
||||||
-Wignored-attributes
|
-Wignored-attributes
|
||||||
@@ -197,6 +203,7 @@ set(GCC_CXXFLAGS
|
|||||||
-Wno-long-long
|
-Wno-long-long
|
||||||
-Wlto-type-mismatch
|
-Wlto-type-mismatch
|
||||||
-Wmain
|
-Wmain
|
||||||
|
-Wmaybe-musttail-local-addr
|
||||||
-Wmaybe-uninitialized
|
-Wmaybe-uninitialized
|
||||||
-Wmemset-elt-size
|
-Wmemset-elt-size
|
||||||
-Wmemset-transposed-args
|
-Wmemset-transposed-args
|
||||||
@@ -215,6 +222,7 @@ set(GCC_CXXFLAGS
|
|||||||
-Wmultichar
|
-Wmultichar
|
||||||
-Wmultiple-inheritance
|
-Wmultiple-inheritance
|
||||||
-Wmultistatement-macros
|
-Wmultistatement-macros
|
||||||
|
-Wmusttail-local-addr
|
||||||
-Wno-namespaces
|
-Wno-namespaces
|
||||||
-Wnarrowing
|
-Wnarrowing
|
||||||
-Wnoexcept
|
-Wnoexcept
|
||||||
@@ -245,6 +253,7 @@ set(GCC_CXXFLAGS
|
|||||||
-Wpmf-conversions
|
-Wpmf-conversions
|
||||||
-Wpointer-arith
|
-Wpointer-arith
|
||||||
-Wpointer-compare
|
-Wpointer-compare
|
||||||
|
-Wpragma-once-outside-header
|
||||||
-Wpragmas
|
-Wpragmas
|
||||||
-Wprio-ctor-dtor
|
-Wprio-ctor-dtor
|
||||||
-Wpsabi
|
-Wpsabi
|
||||||
@@ -276,10 +285,12 @@ set(GCC_CXXFLAGS
|
|||||||
-Wsizeof-pointer-div
|
-Wsizeof-pointer-div
|
||||||
-Wsizeof-pointer-memaccess
|
-Wsizeof-pointer-memaccess
|
||||||
-Wstack-protector
|
-Wstack-protector
|
||||||
|
-Wstrict-aliasing
|
||||||
-Wstrict-aliasing=3
|
-Wstrict-aliasing=3
|
||||||
-Wstrict-null-sentinel
|
-Wstrict-null-sentinel
|
||||||
-Wstrict-overflow
|
-Wstrict-overflow
|
||||||
-Wstring-compare
|
-Wstring-compare
|
||||||
|
-Wstringop-overflow
|
||||||
-Wstringop-overflow=4
|
-Wstringop-overflow=4
|
||||||
-Wstringop-overread
|
-Wstringop-overread
|
||||||
-Wstringop-truncation
|
-Wstringop-truncation
|
||||||
@@ -304,8 +315,12 @@ set(GCC_CXXFLAGS
|
|||||||
-Wsynth
|
-Wsynth
|
||||||
-Wno-system-headers
|
-Wno-system-headers
|
||||||
-Wtautological-compare
|
-Wtautological-compare
|
||||||
|
-Wtemplate-body
|
||||||
|
-Wtemplate-id-cdtor
|
||||||
|
-Wtemplate-names-tu-local
|
||||||
-Wno-templates
|
-Wno-templates
|
||||||
-Wterminate
|
-Wterminate
|
||||||
|
-Wtrailing-whitespace
|
||||||
-Wtrampolines
|
-Wtrampolines
|
||||||
-Wtrigraphs
|
-Wtrigraphs
|
||||||
-Wtrivial-auto-var-init
|
-Wtrivial-auto-var-init
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
cppcheck==1.5.0
|
cppcheck==1.5.1
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
reuse==5.0.2
|
reuse==6.2.0
|
||||||
|
|||||||
+10
-7
@@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
## Generate documentation
|
## Generate documentation
|
||||||
|
|
||||||
Note on documentation: The source files contain links to the online documentation at https://json.nlohmann.me. This URL
|
Note on documentation: The source files contain links to the online documentation at https://json.nlohmann.me.
|
||||||
contains the most recent documentation and should also be applicable to previous versions; documentation for deprecated
|
This URL provides the most recent documentation and also applies to previous versions. Documentation for deprecated
|
||||||
functions is not removed, but marked deprecated.
|
functions is not removed; instead, it is marked as deprecated.
|
||||||
|
|
||||||
If you want to see the documentation for a specific tag or commit hash, you can generate it as follows (here for tag
|
If you want to view the documentation for a specific tag or commit hash, you can generate it locally as follows (example
|
||||||
`v3.10.2`):
|
using tag `v3.10.2`):
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
git clone https://github.com/nlohmann/json.git
|
git clone https://github.com/nlohmann/json.git
|
||||||
@@ -16,5 +16,8 @@ git checkout v3.10.2
|
|||||||
make install_venv serve -C docs/mkdocs
|
make install_venv serve -C docs/mkdocs
|
||||||
```
|
```
|
||||||
|
|
||||||
Open URL <http://127.0.0.1:8000/> in your browser. Replace from any URL from the source code `https://json.nlohmann.me`
|
Open <http://127.0.0.1:8000/> in your browser. Replace any URL in the source code that points to
|
||||||
with `http://127.0.0.1:8000` to see the documentation for your tag or commit hash.
|
`https://json.nlohmann.me` with `http://127.0.0.1:8000` to view the documentation for the selected tag or commit hash.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ Copy of the JSON value, converted to `ValueType`
|
|||||||
??? example "Example: (1) Default-constructible type"
|
??? example "Example: (1) Default-constructible type"
|
||||||
|
|
||||||
The example below shows how a `from_json` function can be implemented for a user-defined type. This function is
|
The example below shows how a `from_json` function can be implemented for a user-defined type. This function is
|
||||||
called by the `adl_serializer` when `template get<ns::person>()` is called.
|
called by the `adl_serializer` when `get<ns::person>()` is called.
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
--8<-- "examples/from_json__default_constructible.cpp"
|
--8<-- "examples/from_json__default_constructible.cpp"
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ struct adl_serializer;
|
|||||||
Serializer that uses ADL ([Argument-Dependent Lookup](https://en.cppreference.com/w/cpp/language/adl)) to choose
|
Serializer that uses ADL ([Argument-Dependent Lookup](https://en.cppreference.com/w/cpp/language/adl)) to choose
|
||||||
`to_json`/`from_json` functions from the types' namespaces.
|
`to_json`/`from_json` functions from the types' namespaces.
|
||||||
|
|
||||||
It is implemented similar to
|
It is implemented similarly to
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
template<typename ValueType>
|
template<typename ValueType>
|
||||||
|
|||||||
@@ -4,12 +4,14 @@
|
|||||||
// (1)
|
// (1)
|
||||||
template<typename InputType>
|
template<typename InputType>
|
||||||
static bool accept(InputType&& i,
|
static bool accept(InputType&& i,
|
||||||
const bool ignore_comments = false);
|
const bool ignore_comments = false,
|
||||||
|
const bool ignore_trailing_commas = false);
|
||||||
|
|
||||||
// (2)
|
// (2)
|
||||||
template<typename IteratorType>
|
template<typename IteratorType>
|
||||||
static bool accept(IteratorType first, IteratorType last,
|
static bool accept(IteratorType first, IteratorType last,
|
||||||
const bool ignore_comments = false);
|
const bool ignore_comments = false,
|
||||||
|
const bool ignore_trailing_commas = false);
|
||||||
```
|
```
|
||||||
|
|
||||||
Checks whether the input is valid JSON.
|
Checks whether the input is valid JSON.
|
||||||
@@ -50,6 +52,10 @@ Unlike the [`parse()`](parse.md) function, this function neither throws an excep
|
|||||||
: whether comments should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error
|
: whether comments should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error
|
||||||
(`#!cpp false`); (optional, `#!cpp false` by default)
|
(`#!cpp false`); (optional, `#!cpp false` by default)
|
||||||
|
|
||||||
|
`ignore_trailing_commas` (in)
|
||||||
|
: whether trailing commas in arrays or objects should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error
|
||||||
|
(`#!cpp false`); (optional, `#!cpp false` by default)
|
||||||
|
|
||||||
`first` (in)
|
`first` (in)
|
||||||
: iterator to the start of the character range
|
: iterator to the start of the character range
|
||||||
|
|
||||||
@@ -102,6 +108,7 @@ A UTF-8 byte order mark is silently ignored.
|
|||||||
- Added in version 3.0.0.
|
- Added in version 3.0.0.
|
||||||
- Ignoring comments via `ignore_comments` added in version 3.9.0.
|
- Ignoring comments via `ignore_comments` added in version 3.9.0.
|
||||||
- Changed [runtime assertion](../../features/assertions.md) in case of `FILE*` null pointers to exception in version 3.12.0.
|
- Changed [runtime assertion](../../features/assertions.md) in case of `FILE*` null pointers to exception in version 3.12.0.
|
||||||
|
- Added `ignore_trailing_commas` in version 3.12.1.
|
||||||
|
|
||||||
!!! warning "Deprecation"
|
!!! warning "Deprecation"
|
||||||
|
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ basic_json(basic_json&& other) noexcept;
|
|||||||
- **boolean**: `boolean_t` / `bool` can be used.
|
- **boolean**: `boolean_t` / `bool` can be used.
|
||||||
- **binary**: `binary_t` / `std::vector<uint8_t>` may be used; unfortunately because string literals cannot be
|
- **binary**: `binary_t` / `std::vector<uint8_t>` may be used; unfortunately because string literals cannot be
|
||||||
distinguished from binary character arrays by the C++ type system, all types compatible with `const char*` will be
|
distinguished from binary character arrays by the C++ type system, all types compatible with `const char*` will be
|
||||||
directed to the string constructor instead. This is both for backwards compatibility, and due to the fact that a
|
directed to the string constructor instead. This is both for backwards compatibility and due to the fact that a
|
||||||
binary type is not a standard JSON type.
|
binary type is not a standard JSON type.
|
||||||
|
|
||||||
See the examples below.
|
See the examples below.
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
bool empty() const noexcept;
|
bool empty() const noexcept;
|
||||||
```
|
```
|
||||||
|
|
||||||
Checks if a JSON value has no elements (i.e. whether its [`size()`](size.md) is `0`).
|
Checks if a JSON value has no elements (i.e., whether its [`size()`](size.md) is `0`).
|
||||||
|
|
||||||
## Return value
|
## Return value
|
||||||
|
|
||||||
|
|||||||
@@ -90,10 +90,25 @@ Depends on what `json_serializer<ValueType>` `from_json()` method throws
|
|||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
!!! danger "Undefined behavior"
|
!!! danger "Undefined behavior for pointers"
|
||||||
|
|
||||||
Writing data to the pointee (overload 3) of the result yields an undefined state.
|
Writing data to the pointee (overload 3) of the result yields an undefined state.
|
||||||
|
|
||||||
|
!!! danger "Undefined behavior for numeric conversions"
|
||||||
|
|
||||||
|
Conversions between numeric types are performed by the corresponding
|
||||||
|
`from_json()` implementation using the target C++ type. When converting
|
||||||
|
between numeric types, the library does not check whether the source
|
||||||
|
value is representable by the target type.
|
||||||
|
|
||||||
|
If the source value is outside the range of the target type, the behavior
|
||||||
|
is the same as the corresponding C++ conversion. In particular, converting
|
||||||
|
a floating-point value to an integer type that cannot represent the value
|
||||||
|
results in undefined behavior.
|
||||||
|
|
||||||
|
See [Number conversion](../../features/types/number_handling.md#number-conversion)
|
||||||
|
for more information.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
??? example
|
??? example
|
||||||
|
|||||||
@@ -29,11 +29,11 @@ void insert(const_iterator first, const_iterator last);
|
|||||||
For all cases where an element is added to an **array**, a reallocation can happen, in which case all iterators
|
For all cases where an element is added to an **array**, a reallocation can happen, in which case all iterators
|
||||||
(including the [`end()`](end.md) iterator) and all references to the elements are invalidated. Otherwise, only the
|
(including the [`end()`](end.md) iterator) and all references to the elements are invalidated. Otherwise, only the
|
||||||
[`end()`](end.md) iterator is invalidated. Also, any iterator or reference after the insertion point will point to the
|
[`end()`](end.md) iterator is invalidated. Also, any iterator or reference after the insertion point will point to the
|
||||||
same index which is now a different value.
|
same index, which is now a different value.
|
||||||
|
|
||||||
For [`ordered_json`](../ordered_json.md), also adding an element to an **object** can yield a reallocation which again
|
For [`ordered_json`](../ordered_json.md), also adding an element to an **object** can yield a reallocation which again
|
||||||
invalidates all iterators and all references. Also, any iterator or reference after the insertion point will point to
|
invalidates all iterators and all references. Also, any iterator or reference after the insertion point will point to
|
||||||
the same index which is now a different value.
|
the same index, which is now a different value.
|
||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ Examples of such functionality might be metadata, additional member functions (e
|
|||||||
|
|
||||||
#### Default type
|
#### Default type
|
||||||
|
|
||||||
The default value for `CustomBaseClass` is `void`. In this case an
|
The default value for `CustomBaseClass` is `void`. In this case, an
|
||||||
[empty base class](https://en.cppreference.com/w/cpp/language/ebo) is used and no additional functionality is injected.
|
[empty base class](https://en.cppreference.com/w/cpp/language/ebo) is used and no additional functionality is injected.
|
||||||
|
|
||||||
#### Limitations
|
#### Limitations
|
||||||
|
|||||||
@@ -6,14 +6,16 @@ template<typename InputType>
|
|||||||
static basic_json parse(InputType&& i,
|
static basic_json parse(InputType&& i,
|
||||||
const parser_callback_t cb = nullptr,
|
const parser_callback_t cb = nullptr,
|
||||||
const bool allow_exceptions = true,
|
const bool allow_exceptions = true,
|
||||||
const bool ignore_comments = false);
|
const bool ignore_comments = false,
|
||||||
|
const bool ignore_trailing_commas = false);
|
||||||
|
|
||||||
// (2)
|
// (2)
|
||||||
template<typename IteratorType>
|
template<typename IteratorType>
|
||||||
static basic_json parse(IteratorType first, IteratorType last,
|
static basic_json parse(IteratorType first, IteratorType last,
|
||||||
const parser_callback_t cb = nullptr,
|
const parser_callback_t cb = nullptr,
|
||||||
const bool allow_exceptions = true,
|
const bool allow_exceptions = true,
|
||||||
const bool ignore_comments = false);
|
const bool ignore_comments = false,
|
||||||
|
const bool ignore_trailing_commas = false);
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Deserialize from a compatible input.
|
1. Deserialize from a compatible input.
|
||||||
@@ -56,6 +58,10 @@ static basic_json parse(IteratorType first, IteratorType last,
|
|||||||
: whether comments should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error
|
: whether comments should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error
|
||||||
(`#!cpp false`); (optional, `#!cpp false` by default)
|
(`#!cpp false`); (optional, `#!cpp false` by default)
|
||||||
|
|
||||||
|
`ignore_trailing_commas` (in)
|
||||||
|
: whether trailing commas in arrays or objects should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error
|
||||||
|
(`#!cpp false`); (optional, `#!cpp false` by default)
|
||||||
|
|
||||||
`first` (in)
|
`first` (in)
|
||||||
: iterator to the start of a character range
|
: iterator to the start of a character range
|
||||||
|
|
||||||
@@ -189,6 +195,34 @@ A UTF-8 byte order mark is silently ignored.
|
|||||||
--8<-- "examples/parse__allow_exceptions.output"
|
--8<-- "examples/parse__allow_exceptions.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
??? example "Effect of `ignore_comments` parameter"
|
||||||
|
|
||||||
|
The example below demonstrates the effect of the `ignore_comments` parameter in the `parse()` function.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/comments.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```
|
||||||
|
--8<-- "examples/comments.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
??? example "Effect of `ignore_trailing_commas` parameter"
|
||||||
|
|
||||||
|
The example below demonstrates the effect of the `ignore_trailing_commas` parameter in the `parse()` function.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/trailing_commas.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```
|
||||||
|
--8<-- "examples/trailing_commas.output"
|
||||||
|
```
|
||||||
|
|
||||||
## See also
|
## See also
|
||||||
|
|
||||||
- [accept](accept.md) - check if the input is valid JSON
|
- [accept](accept.md) - check if the input is valid JSON
|
||||||
@@ -200,6 +234,7 @@ A UTF-8 byte order mark is silently ignored.
|
|||||||
- Overload for contiguous containers (1) added in version 2.0.3.
|
- Overload for contiguous containers (1) added in version 2.0.3.
|
||||||
- Ignoring comments via `ignore_comments` added in version 3.9.0.
|
- Ignoring comments via `ignore_comments` added in version 3.9.0.
|
||||||
- Changed [runtime assertion](../../features/assertions.md) in case of `FILE*` null pointers to exception in version 3.12.0.
|
- Changed [runtime assertion](../../features/assertions.md) in case of `FILE*` null pointers to exception in version 3.12.0.
|
||||||
|
- Added `ignore_trailing_commas` in version 3.12.1.
|
||||||
|
|
||||||
!!! warning "Deprecation"
|
!!! warning "Deprecation"
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ static bool sax_parse(InputType&& i,
|
|||||||
SAX* sax,
|
SAX* sax,
|
||||||
input_format_t format = input_format_t::json,
|
input_format_t format = input_format_t::json,
|
||||||
const bool strict = true,
|
const bool strict = true,
|
||||||
const bool ignore_comments = false);
|
const bool ignore_comments = false,
|
||||||
|
const bool ignore_trailing_commas = false);
|
||||||
|
|
||||||
// (2)
|
// (2)
|
||||||
template<class IteratorType, class SAX>
|
template<class IteratorType, class SAX>
|
||||||
@@ -15,7 +16,8 @@ static bool sax_parse(IteratorType first, IteratorType last,
|
|||||||
SAX* sax,
|
SAX* sax,
|
||||||
input_format_t format = input_format_t::json,
|
input_format_t format = input_format_t::json,
|
||||||
const bool strict = true,
|
const bool strict = true,
|
||||||
const bool ignore_comments = false);
|
const bool ignore_comments = false,
|
||||||
|
const bool ignore_trailing_commas = false);
|
||||||
```
|
```
|
||||||
|
|
||||||
Read from input and generate SAX events
|
Read from input and generate SAX events
|
||||||
@@ -49,10 +51,10 @@ The SAX event lister must follow the interface of [`json_sax`](../json_sax/index
|
|||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
`i` (in)
|
`i` (in)
|
||||||
: Input to parse from.
|
: Input to parse from
|
||||||
|
|
||||||
`sax` (in)
|
`sax` (in)
|
||||||
: SAX event listener
|
: SAX event listener (must not be null)
|
||||||
|
|
||||||
`format` (in)
|
`format` (in)
|
||||||
: the format to parse (JSON, CBOR, MessagePack, or UBJSON) (optional, `input_format_t::json` by default), see
|
: the format to parse (JSON, CBOR, MessagePack, or UBJSON) (optional, `input_format_t::json` by default), see
|
||||||
@@ -65,6 +67,10 @@ The SAX event lister must follow the interface of [`json_sax`](../json_sax/index
|
|||||||
: whether comments should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error
|
: whether comments should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error
|
||||||
(`#!cpp false`); (optional, `#!cpp false` by default)
|
(`#!cpp false`); (optional, `#!cpp false` by default)
|
||||||
|
|
||||||
|
`ignore_trailing_commas` (in)
|
||||||
|
: whether trailing commas in arrays or objects should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error
|
||||||
|
(`#!cpp false`); (optional, `#!cpp false` by default)
|
||||||
|
|
||||||
`first` (in)
|
`first` (in)
|
||||||
: iterator to the start of a character range
|
: iterator to the start of a character range
|
||||||
|
|
||||||
@@ -77,6 +83,16 @@ return value of the last processed SAX event
|
|||||||
|
|
||||||
## Exception safety
|
## Exception safety
|
||||||
|
|
||||||
|
Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
|
||||||
|
|
||||||
|
## Exceptions
|
||||||
|
|
||||||
|
- Throws [`parse_error.101`](../../home/exceptions.md#jsonexceptionparse_error101) in case of an unexpected token, or
|
||||||
|
empty input like a null `FILE*` or `char*` pointer.
|
||||||
|
- Throws [`parse_error.102`](../../home/exceptions.md#jsonexceptionparse_error102) if `to_unicode` fails or surrogate
|
||||||
|
error.
|
||||||
|
- Throws [`parse_error.103`](../../home/exceptions.md#jsonexceptionparse_error103) if `to_unicode` fails.
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
Linear in the length of the input. The parser is a predictive LL(1) parser. The complexity can be higher if the SAX
|
Linear in the length of the input. The parser is a predictive LL(1) parser. The complexity can be higher if the SAX
|
||||||
@@ -107,6 +123,7 @@ A UTF-8 byte order mark is silently ignored.
|
|||||||
|
|
||||||
- Added in version 3.2.0.
|
- Added in version 3.2.0.
|
||||||
- Ignoring comments via `ignore_comments` added in version 3.9.0.
|
- Ignoring comments via `ignore_comments` added in version 3.9.0.
|
||||||
|
- Added `ignore_trailing_commas` in version 3.12.1.
|
||||||
|
|
||||||
!!! warning "Deprecation"
|
!!! warning "Deprecation"
|
||||||
|
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ changes to any JSON value.
|
|||||||
The value function is a template, and the return type of the function is determined by the type of the provided
|
The value function is a template, and the return type of the function is determined by the type of the provided
|
||||||
default value unless otherwise specified. This can have unexpected effects. In the example below, we store a 64-bit
|
default value unless otherwise specified. This can have unexpected effects. In the example below, we store a 64-bit
|
||||||
unsigned integer. We get exactly that value when using [`operator[]`](operator[].md). However, when we call `value`
|
unsigned integer. We get exactly that value when using [`operator[]`](operator[].md). However, when we call `value`
|
||||||
and provide `#!c 0` as default value, then `#!c -1` is returned. The occurs, because `#!c 0` has type `#!c int`
|
and provide `#!c 0` as default value, then `#!c -1` is returned. This occurs, because `#!c 0` has type `#!c int`
|
||||||
which overflows when handling the value `#!c 18446744073709551615`.
|
which overflows when handling the value `#!c 18446744073709551615`.
|
||||||
|
|
||||||
To address this issue, either provide a correctly typed default value or use the template parameter to specify the
|
To address this issue, either provide a correctly typed default value or use the template parameter to specify the
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
# <small>nlohmann::json_pointer::</small>front
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
const string_t& front() const;
|
||||||
|
```
|
||||||
|
|
||||||
|
Return the first reference token.
|
||||||
|
|
||||||
|
## Return value
|
||||||
|
|
||||||
|
First reference token.
|
||||||
|
|
||||||
|
## Exceptions
|
||||||
|
|
||||||
|
Throws [out_of_range.405](../../home/exceptions.md#jsonexceptionout_of_range405) if the JSON pointer has no parent.
|
||||||
|
|
||||||
|
## Complexity
|
||||||
|
|
||||||
|
Constant.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example shows the usage of `front`.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/json_pointer__front.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```json
|
||||||
|
--8<-- "examples/json_pointer__front.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version history
|
||||||
@@ -37,6 +37,9 @@ are the base for JSON patches.
|
|||||||
- [**pop_back**](pop_back.md) - remove the last reference token
|
- [**pop_back**](pop_back.md) - remove the last reference token
|
||||||
- [**back**](back.md) - return last reference token
|
- [**back**](back.md) - return last reference token
|
||||||
- [**push_back**](push_back.md) - append an unescaped token at the end of the pointer
|
- [**push_back**](push_back.md) - append an unescaped token at the end of the pointer
|
||||||
|
- [**pop_front**](pop_front.md) - remove the first reference token
|
||||||
|
- [**front**](front.md) - return first reference token
|
||||||
|
- [**push_front**](push_front.md) - append an unescaped token at the start of the pointer
|
||||||
- [**empty**](empty.md) - return whether the pointer points to the root document
|
- [**empty**](empty.md) - return whether the pointer points to the root document
|
||||||
|
|
||||||
## Literals
|
## Literals
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
# <small>nlohmann::json_pointer::</small>pop_front
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
void pop_front();
|
||||||
|
```
|
||||||
|
|
||||||
|
Remove the first reference token.
|
||||||
|
|
||||||
|
## Exceptions
|
||||||
|
|
||||||
|
Throws [out_of_range.405](../../home/exceptions.md#jsonexceptionout_of_range405) if the JSON pointer has no parent.
|
||||||
|
|
||||||
|
## Complexity
|
||||||
|
|
||||||
|
Linear in the number of reference tokens in the `json_pointer`.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example shows the usage of `pop_front`.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/json_pointer__pop_front.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```json
|
||||||
|
--8<-- "examples/json_pointer__pop_front.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version history
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
# <small>nlohmann::json_pointer::</small>push_front
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
void push_front(const string_t& token);
|
||||||
|
|
||||||
|
void push_front(string_t&& token);
|
||||||
|
```
|
||||||
|
|
||||||
|
Append an unescaped token at the start of the reference pointer.
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
`token` (in)
|
||||||
|
: token to add
|
||||||
|
|
||||||
|
## Complexity
|
||||||
|
|
||||||
|
Linear in the number of reference tokens in the `json_pointer`.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example shows the result of `push_front` for different JSON Pointers.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/json_pointer__push_front.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```json
|
||||||
|
--8<-- "examples/json_pointer__push_front.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version history
|
||||||
@@ -40,6 +40,7 @@ header. See also the [macro overview page](../../features/macros.md).
|
|||||||
|
|
||||||
## Type conversions
|
## Type conversions
|
||||||
|
|
||||||
|
- [**JSON_BRACE_INIT_COPY_SEMANTICS**](json_brace_init_copy_semantics.md) - opt in to copy/move semantics for single-element brace initialization
|
||||||
- [**JSON_DISABLE_ENUM_SERIALIZATION**](json_disable_enum_serialization.md) - switch off default serialization/deserialization functions for enums
|
- [**JSON_DISABLE_ENUM_SERIALIZATION**](json_disable_enum_serialization.md) - switch off default serialization/deserialization functions for enums
|
||||||
- [**JSON_USE_IMPLICIT_CONVERSIONS**](json_use_implicit_conversions.md) - control implicit conversions
|
- [**JSON_USE_IMPLICIT_CONVERSIONS**](json_use_implicit_conversions.md) - control implicit conversions
|
||||||
|
|
||||||
@@ -53,6 +54,7 @@ header. See also the [macro overview page](../../features/macros.md).
|
|||||||
### Enums
|
### Enums
|
||||||
|
|
||||||
- [**NLOHMANN_JSON_SERIALIZE_ENUM**](nlohmann_json_serialize_enum.md) - serialize/deserialize an enum
|
- [**NLOHMANN_JSON_SERIALIZE_ENUM**](nlohmann_json_serialize_enum.md) - serialize/deserialize an enum
|
||||||
|
- [**NLOHMANN_JSON_SERIALIZE_ENUM_STRICT**](nlohmann_json_serialize_enum_strict.md) - serialize/deserialize an enum with exceptions
|
||||||
|
|
||||||
### Classes and structs
|
### Classes and structs
|
||||||
|
|
||||||
@@ -81,3 +83,28 @@ header. See also the [macro overview page](../../features/macros.md).
|
|||||||
a derived class; uses default values
|
a derived class; uses default values
|
||||||
- [**NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE**](nlohmann_define_derived_type.md) - serialize a derived
|
- [**NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE**](nlohmann_define_derived_type.md) - serialize a derived
|
||||||
class
|
class
|
||||||
|
- [**NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_NAMES**](nlohmann_define_type_with_names.md) - serialize/deserialize a non-derived class
|
||||||
|
with private members; uses custom names
|
||||||
|
- [**NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT_WITH_NAMES**](nlohmann_define_type_with_names.md) - serialize/deserialize a
|
||||||
|
non-derived class with private members; uses default values; uses custom names
|
||||||
|
- [**NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE_WITH_NAMES**](nlohmann_define_type_with_names.md) - serialize a non-derived class
|
||||||
|
with private members; uses custom names
|
||||||
|
- [**NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_NAMES**](nlohmann_define_type_with_names.md) - serialize/deserialize a non-derived
|
||||||
|
class; uses custom names
|
||||||
|
- [**NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT_WITH_NAMES**](nlohmann_define_type_with_names.md) - serialize/deserialize a
|
||||||
|
non-derived class; uses default values; uses custom names
|
||||||
|
- [**NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE_WITH_NAMES**](nlohmann_define_type_with_names.md) - serialize a
|
||||||
|
non-derived class; uses custom names
|
||||||
|
|
||||||
|
- [**NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_NAMES**](nlohmann_define_type_with_names.md) - serialize/deserialize a derived class
|
||||||
|
with private members; uses custom names
|
||||||
|
- [**NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_DEFAULT_WITH_NAMES**](nlohmann_define_type_with_names.md) - serialize/deserialize a
|
||||||
|
derived class with private members; uses default values; uses custom names
|
||||||
|
- [**NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_ONLY_SERIALIZE_WITH_NAMES**](nlohmann_define_type_with_names.md) - serialize a derived
|
||||||
|
class with private members; uses custom names
|
||||||
|
- [**NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_WITH_NAMES**](nlohmann_define_type_with_names.md) - serialize/deserialize a derived
|
||||||
|
class; uses custom names
|
||||||
|
- [**NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_WITH_DEFAULT_WITH_NAMES**](nlohmann_define_type_with_names.md) - serialize/deserialize
|
||||||
|
a derived class; uses default values; uses custom names
|
||||||
|
- [**NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE_WITH_NAMES**](nlohmann_define_type_with_names.md) - serialize a derived
|
||||||
|
class; uses custom names
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
# JSON_BRACE_INIT_COPY_SEMANTICS
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
#define JSON_BRACE_INIT_COPY_SEMANTICS /* value */
|
||||||
|
```
|
||||||
|
|
||||||
|
When defined to `1`, single-element brace initialization of a `basic_json` value is treated as a copy/move of the
|
||||||
|
element rather than wrapping it in a single-element array.
|
||||||
|
|
||||||
|
## Default definition
|
||||||
|
|
||||||
|
The default value is `0` (disabled — existing behavior is preserved).
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
#define JSON_BRACE_INIT_COPY_SEMANTICS 0
|
||||||
|
```
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
!!! note "Background"
|
||||||
|
|
||||||
|
C++ always prefers the `initializer_list` constructor over the copy/move constructor for brace initialization. This
|
||||||
|
means that code like
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
json obj = {{"key", "value"}};
|
||||||
|
json j{obj};
|
||||||
|
```
|
||||||
|
|
||||||
|
creates a single-element **array** `[{"key":"value"}]` instead of a copy of `obj`. This behavior is
|
||||||
|
compiler-dependent for older compilers (GCC wrapped, Clang did not), but starting from Clang 20, both compilers
|
||||||
|
behave the same way.
|
||||||
|
|
||||||
|
Enabling this macro opts into copy/move semantics for this case
|
||||||
|
(see [#5074](https://github.com/nlohmann/json/issues/5074)).
|
||||||
|
|
||||||
|
!!! warning "Opt-in only"
|
||||||
|
|
||||||
|
This macro must be defined **before** including `<nlohmann/json.hpp>`. Defining it after the include has no effect.
|
||||||
|
|
||||||
|
!!! tip "Workaround without the macro"
|
||||||
|
|
||||||
|
To explicitly create a single-element array without enabling this macro, use `json::array()`:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
json j = json::array({obj}); // always creates [obj]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example "Default behavior (macro not defined)"
|
||||||
|
|
||||||
|
Without the macro, single-element brace initialization wraps the value in an array:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
json obj = {{"key", "value"}};
|
||||||
|
|
||||||
|
json j{obj};
|
||||||
|
// j is [{"key":"value"}] -- single-element array, NOT a copy of obj
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
??? example "Opt-in copy semantics (macro defined to 1)"
|
||||||
|
|
||||||
|
With the macro, single-element brace initialization copies/moves the value:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
#define JSON_BRACE_INIT_COPY_SEMANTICS 1
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
json obj = {{"key", "value"}};
|
||||||
|
|
||||||
|
json j{obj};
|
||||||
|
// j is {"key":"value"} -- copy of obj
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [FAQ: Brace initialization yields arrays](../../home/faq.md#brace-initialization-yields-arrays)
|
||||||
|
- [**basic_json(initializer_list_t)**](../basic_json/basic_json.md) - the affected constructor
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.12.0.
|
||||||
@@ -53,7 +53,7 @@ The default value is `0`.
|
|||||||
const json j = Choice::first;
|
const json j = Choice::first;
|
||||||
|
|
||||||
// normally invokes from_json parse function but with JSON_DISABLE_ENUM_SERIALIZATION defined, it does not
|
// normally invokes from_json parse function but with JSON_DISABLE_ENUM_SERIALIZATION defined, it does not
|
||||||
Choice ch = j.template get<Choice>();
|
Choice ch = j.get<Choice>();
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ The default value is `0`.
|
|||||||
const json j = Choice::first;
|
const json j = Choice::first;
|
||||||
|
|
||||||
// uses user-defined from_json function defined by macro
|
// uses user-defined from_json function defined by macro
|
||||||
Choice ch = j.template get<Choice>();
|
Choice ch = j.get<Choice>();
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ The default value is `0`.
|
|||||||
|
|
||||||
void from_json(const json& j, Choice& ch)
|
void from_json(const json& j, Choice& ch)
|
||||||
{
|
{
|
||||||
auto value = j.template get<std::string>();
|
auto value = j.get<std::string>();
|
||||||
if (value == "first")
|
if (value == "first")
|
||||||
{
|
{
|
||||||
ch = Choice::first;
|
ch = Choice::first;
|
||||||
@@ -122,7 +122,7 @@ The default value is `0`.
|
|||||||
|
|
||||||
void to_json(json& j, const Choice& ch)
|
void to_json(json& j, const Choice& ch)
|
||||||
{
|
{
|
||||||
auto value = j.template get<std::string>();
|
auto value = j.get<std::string>();
|
||||||
if (value == "first")
|
if (value == "first")
|
||||||
{
|
{
|
||||||
ch = Choice::first;
|
ch = Choice::first;
|
||||||
@@ -139,7 +139,7 @@ The default value is `0`.
|
|||||||
const json j = Choice::first;
|
const json j = Choice::first;
|
||||||
|
|
||||||
// uses user-defined from_json function
|
// uses user-defined from_json function
|
||||||
Choice ch = j.template get<Choice>();
|
Choice ch = j.get<Choice>();
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ By default, implicit conversions are enabled.
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
json j = "Hello, world!";
|
json j = "Hello, world!";
|
||||||
auto s = j.template get<std::string>();
|
auto s = j.get<std::string>();
|
||||||
```
|
```
|
||||||
|
|
||||||
## See also
|
## See also
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ Summary:
|
|||||||
: name of the base type (class, struct) `type` is derived from
|
: name of the base type (class, struct) `type` is derived from
|
||||||
|
|
||||||
`member` (in)
|
`member` (in)
|
||||||
: name of the member variable to serialize/deserialize; up to 64 members can be given as a comma-separated list
|
: name of the member variable to serialize/deserialize; up to 63 members can be given as a comma-separated list
|
||||||
|
|
||||||
## Default definition
|
## Default definition
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ template<typename BasicJsonType>
|
|||||||
void from_json(const BasicJsonType&, type&);
|
void from_json(const BasicJsonType&, type&);
|
||||||
```
|
```
|
||||||
|
|
||||||
Macros 3 and 6 add one function to the namespace which takes care of the serialization only:
|
Macros 3 and 6 add one function to the namespace, which takes care of the serialization only:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
template<typename BasicJsonType>
|
template<typename BasicJsonType>
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ Summary:
|
|||||||
: name of the type (class, struct) to serialize/deserialize
|
: name of the type (class, struct) to serialize/deserialize
|
||||||
|
|
||||||
`member` (in)
|
`member` (in)
|
||||||
: name of the member variable to serialize/deserialize; up to 64 members can be given as a comma-separated list
|
: name of the member variable to serialize/deserialize; up to 63 members can be given as a comma-separated list
|
||||||
|
|
||||||
## Default definition
|
## Default definition
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ template<typename BasicJsonType>
|
|||||||
friend void from_json(const BasicJsonType&, type&); // except (3)
|
friend void from_json(const BasicJsonType&, type&); // except (3)
|
||||||
```
|
```
|
||||||
|
|
||||||
See examples below for the concrete generated code.
|
See the examples below for the concrete generated code.
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
@@ -60,8 +60,8 @@ See examples below for the concrete generated code.
|
|||||||
|
|
||||||
!!! warning "Implementation limits"
|
!!! warning "Implementation limits"
|
||||||
|
|
||||||
- The current implementation is limited to at most 64 member variables. If you want to serialize/deserialize types
|
- The current implementation is limited to at most 63 member variables. If you want to serialize/deserialize types
|
||||||
with more than 64 member variables, you need to define the `to_json`/`from_json` functions manually.
|
with more than 63 member variables, you need to define the `to_json`/`from_json` functions manually.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ Summary:
|
|||||||
: name of the type (class, struct) to serialize/deserialize
|
: name of the type (class, struct) to serialize/deserialize
|
||||||
|
|
||||||
`member` (in)
|
`member` (in)
|
||||||
: name of the (public) member variable to serialize/deserialize; up to 64 members can be given as a comma-separated list
|
: name of the (public) member variable to serialize/deserialize; up to 63 members can be given as a comma-separated list
|
||||||
|
|
||||||
## Default definition
|
## Default definition
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ template<typename BasicJsonType>
|
|||||||
void from_json(const BasicJsonType&, type&); // except (3)
|
void from_json(const BasicJsonType&, type&); // except (3)
|
||||||
```
|
```
|
||||||
|
|
||||||
See examples below for the concrete generated code.
|
See the examples below for the concrete generated code.
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
@@ -61,8 +61,8 @@ See examples below for the concrete generated code.
|
|||||||
|
|
||||||
!!! warning "Implementation limits"
|
!!! warning "Implementation limits"
|
||||||
|
|
||||||
- The current implementation is limited to at most 64 member variables. If you want to serialize/deserialize types
|
- The current implementation is limited to at most 63 member variables. If you want to serialize/deserialize types
|
||||||
with more than 64 member variables, you need to define the `to_json`/`from_json` functions manually.
|
with more than 63 member variables, you need to define the `to_json`/`from_json` functions manually.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
<h1>NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_NAMES, NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT_WITH_NAMES,
|
||||||
|
NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE_WITH_NAMES, NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_NAMES,
|
||||||
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT_WITH_NAMES, NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE_WITH_NAMES,
|
||||||
|
NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_NAMES, NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_DEFAULT_WITH_NAMES,
|
||||||
|
NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_ONLY_SERIALIZE_WITH_NAMES, NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_WITH_NAMES,
|
||||||
|
NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_WITH_DEFAULT_WITH_NAMES, NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE_WITH_NAMES</h1>
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_NAMES(type, "json_member_name", member...)
|
||||||
|
#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT_WITH_NAMES(type, "json_member_name", member...)
|
||||||
|
#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE_WITH_NAMES(type, "json_member_name", member...)
|
||||||
|
#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_NAMES(type, "json_member_name", member...)
|
||||||
|
#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT_WITH_NAMES(type, "json_member_name", member...)
|
||||||
|
#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE_WITH_NAMES(type, "json_member_name", member...)
|
||||||
|
#define NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_NAMES(type, base_type, "json_member_name", member...)
|
||||||
|
#define NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_DEFAULT_WITH_NAMES(type, base_type, "json_member_name", member...)
|
||||||
|
#define NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_ONLY_SERIALIZE_WITH_NAMES(type, base_type, "json_member_name", member...)
|
||||||
|
#define NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_WITH_NAMES(type, base_type, "json_member_name", member...)
|
||||||
|
#define NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_WITH_DEFAULT_WITH_NAMES(type, base_type, "json_member_name", member...)
|
||||||
|
#define NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE_WITH_NAMES(type, base_type, "json_member_name", member...)
|
||||||
|
```
|
||||||
|
|
||||||
|
These macros can be used in case you want to use the custom names for the member variables in the resulting JSON.
|
||||||
|
They behave exactly as their non-`WITH_NAMES` counterparts, but require an additional parameter for each member variable
|
||||||
|
which will be used in JSON. Both serialization and deserialization will only use the custom names for JSON, the names of
|
||||||
|
the member variables themselves will be ignored.
|
||||||
|
|
||||||
|
Using the named conversion macros will halve the maximum number of member variables from 63 to 31.
|
||||||
|
|
||||||
|
For further information please refer to the corresponding macros without `WITH_NAMES`.
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
`type` (in)
|
||||||
|
: name of the type (class, struct) to serialize/deserialize
|
||||||
|
|
||||||
|
`base_type` (in)
|
||||||
|
: name of the base type (class, struct) `type` is derived from (used only in `DEFINE_DERIVED_TYPE` macros)
|
||||||
|
|
||||||
|
`json_member_name` (in)
|
||||||
|
: the string that will be used as the name for the next value
|
||||||
|
|
||||||
|
`member` (in)
|
||||||
|
: name of the member variable to serialize/deserialize
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example "Example (1): NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_NAMES"
|
||||||
|
|
||||||
|
Consider the following complete example:
|
||||||
|
|
||||||
|
```cpp hl_lines="16"
|
||||||
|
--8<-- "examples/nlohmann_define_type_non_intrusive_with_names_macro.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```json
|
||||||
|
--8<-- "examples/nlohmann_define_type_non_intrusive_with_names_macro.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
|
||||||
|
- `ns::person` is default-constructible. This is a requirement for using the macro.
|
||||||
|
- `ns::person` has only public member variables. This makes `NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_NAMES` applicable.
|
||||||
|
- The macro `NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_NAMES` is used _outside_ the class, but _inside_ its namespace `ns`.
|
||||||
|
- A missing key "age" in the deserialization yields an exception. To fall back to the default value,
|
||||||
|
`NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT_WITH_NAMES` can be used.
|
||||||
|
|
||||||
|
The macro is equivalent to:
|
||||||
|
|
||||||
|
```cpp hl_lines="16 17 18 19 20 21 22 23 24 25 26 27 28"
|
||||||
|
--8<-- "examples/nlohmann_define_type_non_intrusive_with_names_explicit.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
1. Added in version 3.11.x.
|
||||||
@@ -4,8 +4,8 @@
|
|||||||
#define NLOHMANN_JSON_SERIALIZE_ENUM(type, conversion...)
|
#define NLOHMANN_JSON_SERIALIZE_ENUM(type, conversion...)
|
||||||
```
|
```
|
||||||
|
|
||||||
By default, enum values are serialized to JSON as integers. In some cases this could result in undesired behavior. If an
|
By default, enum values are serialized to JSON as integers. In some cases, this could result in undesired behavior. If
|
||||||
enum is modified or re-ordered after data has been serialized to JSON, the later deserialized JSON data may be
|
an enum is modified or re-ordered after data has been serialized to JSON, the later deserialized JSON data may be
|
||||||
undefined or a different enum value than was originally intended.
|
undefined or a different enum value than was originally intended.
|
||||||
|
|
||||||
The `NLOHMANN_JSON_SERIALIZE_ENUM` allows to define a user-defined serialization for every enumerator.
|
The `NLOHMANN_JSON_SERIALIZE_ENUM` allows to define a user-defined serialization for every enumerator.
|
||||||
@@ -37,7 +37,7 @@ inline void from_json(const BasicJsonType& j, type& e);
|
|||||||
|
|
||||||
!!! important "Important notes"
|
!!! important "Important notes"
|
||||||
|
|
||||||
- When using [`template get<ENUM_TYPE>()`](../basic_json/get.md), undefined JSON values will default to the first specified
|
- When using [`get<ENUM_TYPE>()`](../basic_json/get.md), undefined JSON values will default to the first specified
|
||||||
conversion. Select this default pair carefully. See example 1 below.
|
conversion. Select this default pair carefully. See example 1 below.
|
||||||
- If an enum or JSON value is specified in multiple conversions, the first matching conversion from the top of the
|
- If an enum or JSON value is specified in multiple conversions, the first matching conversion from the top of the
|
||||||
list will be returned when converting to or from JSON. See example 2 below.
|
list will be returned when converting to or from JSON. See example 2 below.
|
||||||
@@ -78,6 +78,7 @@ inline void from_json(const BasicJsonType& j, type& e);
|
|||||||
## See also
|
## See also
|
||||||
|
|
||||||
- [Specializing enum conversion](../../features/enum_conversion.md)
|
- [Specializing enum conversion](../../features/enum_conversion.md)
|
||||||
|
- [`NLOHMANN_JSON_SERIALIZE_ENUM_STRICT`](./nlohmann_json_serialize_enum_strict.md)
|
||||||
- [`JSON_DISABLE_ENUM_SERIALIZATION`](json_disable_enum_serialization.md)
|
- [`JSON_DISABLE_ENUM_SERIALIZATION`](json_disable_enum_serialization.md)
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
# NLOHMANN_JSON_SERIALIZE_ENUM_STRICT
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
#define NLOHMANN_JSON_SERIALIZE_ENUM_STRICT(type, conversion...)
|
||||||
|
```
|
||||||
|
|
||||||
|
By default, enum values are serialized to JSON as integers. In some cases, this could result in undesired behavior. If
|
||||||
|
an enum is modified or re-ordered after data has been serialized to JSON, the later deserialized JSON data may be
|
||||||
|
undefined or a different enum value than was originally intended.
|
||||||
|
|
||||||
|
`NLOHMANN_JSON_SERIALIZE_ENUM_STRICT` allows to define a user-defined serialization for every enumerator that
|
||||||
|
throws an exception on undefined input.
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
`type` (in)
|
||||||
|
: name of the enum to serialize/deserialize
|
||||||
|
|
||||||
|
`conversion` (in)
|
||||||
|
: a pair of an enumerator and a JSON serialization; arbitrary pairs can be given as a comma-separated list
|
||||||
|
|
||||||
|
## Default definition
|
||||||
|
|
||||||
|
The macro adds two functions to the namespace which take care of the serialization and deserialization:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
template<typename BasicJsonType>
|
||||||
|
inline void to_json(BasicJsonType& j, const type& e);
|
||||||
|
template<typename BasicJsonType>
|
||||||
|
inline void from_json(const BasicJsonType& j, type& e);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
!!! info "Prerequisites"
|
||||||
|
|
||||||
|
The macro must be used inside the namespace of the enum.
|
||||||
|
|
||||||
|
!!! important "Important notes"
|
||||||
|
|
||||||
|
- When using [`get<ENUM_TYPE>()`](../basic_json/get.md), undefined JSON values will throw an exception.
|
||||||
|
- If an enum or JSON value is specified in multiple conversions, the first matching conversion from the top of the
|
||||||
|
list will be returned when converting to or from JSON. See example 2 below.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example "Example 1: Basic usage"
|
||||||
|
|
||||||
|
The example shows how `NLOHMANN_JSON_SERIALIZE_ENUM_STRICT` can be used to serialize/deserialize both classical enums and
|
||||||
|
C++11 enum classes:
|
||||||
|
|
||||||
|
```cpp hl_lines="16 17 18 19 20 21 22 29 30 31 32 33"
|
||||||
|
--8<-- "examples/nlohmann_json_serialize_enum_strict.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```json
|
||||||
|
--8<-- "examples/nlohmann_json_serialize_enum_strict.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
??? example "Example 2: Multiple conversions for one enumerator"
|
||||||
|
|
||||||
|
The example shows how to use multiple conversions for a single enumerator. In the example, `Color::red` will always
|
||||||
|
be *serialized* to `"red"`, because the first occurring conversion. The second conversion, however, offers an
|
||||||
|
alternative *deserialization* from `"rot"` to `Color::red`.
|
||||||
|
|
||||||
|
```cpp hl_lines="17"
|
||||||
|
--8<-- "examples/nlohmann_json_serialize_enum_strict_2.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```json
|
||||||
|
--8<-- "examples/nlohmann_json_serialize_enum_strict_2.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
??? example "Example 3: exceptions on invalid serialization"
|
||||||
|
|
||||||
|
The example shows how an invalid serialization causes an exception to be thrown. In the example,
|
||||||
|
Color::unknown is not defined in the mapping used to call `NLOHMANN_JSON_SERIALIZE_ENUM_STRICT`
|
||||||
|
so causes an exception when used to serialize. Similarly, "what" does not refer to an enum
|
||||||
|
value so also causes an exception when deserialization is attempted.
|
||||||
|
|
||||||
|
```cpp hl_lines="14 32 33 43 44 45"
|
||||||
|
--8<-- "examples/nlohmann_json_serialize_enum_strict_err.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
```json
|
||||||
|
--8<-- "examples/nlohmann_json_serialize_enum_strict_err.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [Specializing enum conversion](../../features/enum_conversion.md)
|
||||||
|
- [`NLOHMANN_JSON_SERIALIZE_ENUM`](./nlohmann_json_serialize_enum.md)
|
||||||
|
- [`JSON_DISABLE_ENUM_SERIALIZATION`](json_disable_enum_serialization.md)
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
Added in version 3.12.0.
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
json operator ""_json(const char* s, std::size_t n);
|
json operator ""_json(const char* s, std::size_t n);
|
||||||
|
json operator ""_json(const char8_t* s, std::size_t n); // since C++20
|
||||||
```
|
```
|
||||||
|
|
||||||
This operator implements a user-defined string literal for JSON objects. It can be used by adding `#!cpp _json` to a
|
This operator implements a user-defined string literal for JSON objects. It can be used by adding `#!cpp _json` to a
|
||||||
@@ -59,3 +60,4 @@ Linear.
|
|||||||
|
|
||||||
- Added in version 1.0.0.
|
- Added in version 1.0.0.
|
||||||
- Moved to namespace `nlohmann::literals::json_literals` in 3.11.0.
|
- Moved to namespace `nlohmann::literals::json_literals` in 3.11.0.
|
||||||
|
- Added `char8_t*` overload in 3.12.1.
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
json_pointer operator ""_json_pointer(const char* s, std::size_t n);
|
json_pointer operator ""_json_pointer(const char* s, std::size_t n);
|
||||||
|
json_pointer operator ""_json_pointer(const char8_t* s, std::size_t n); // since C++20
|
||||||
```
|
```
|
||||||
|
|
||||||
This operator implements a user-defined string literal for JSON Pointers. It can be used by adding `#!cpp _json_pointer`
|
This operator implements a user-defined string literal for JSON Pointers. It can be used by adding `#!cpp _json_pointer`
|
||||||
@@ -62,3 +63,4 @@ Linear.
|
|||||||
|
|
||||||
- Added in version 2.0.0.
|
- Added in version 2.0.0.
|
||||||
- Moved to namespace `nlohmann::literals::json_literals` in 3.11.0.
|
- Moved to namespace `nlohmann::literals::json_literals` in 3.11.0.
|
||||||
|
- Added `char8_t*` overload in 3.12.1.
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ This type preserves the insertion order of object keys.
|
|||||||
The type is based on [`ordered_map`](ordered_map.md) which in turn uses a `std::vector` to store object elements.
|
The type is based on [`ordered_map`](ordered_map.md) which in turn uses a `std::vector` to store object elements.
|
||||||
Therefore, adding object elements can yield a reallocation in which case all iterators (including the
|
Therefore, adding object elements can yield a reallocation in which case all iterators (including the
|
||||||
[`end()`](basic_json/end.md) iterator) and all references to the elements are invalidated. Also, any iterator or
|
[`end()`](basic_json/end.md) iterator) and all references to the elements are invalidated. Also, any iterator or
|
||||||
reference after the insertion point will point to the same index which is now a different value.
|
reference after the insertion point will point to the same index, which is now a different value.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
|||||||
@@ -15,81 +15,83 @@ violations will result in a failed build.
|
|||||||
|
|
||||||
??? abstract "Compilers used in continuous integration"
|
??? abstract "Compilers used in continuous integration"
|
||||||
|
|
||||||
| Compiler | Architecture | Operating System | CI |
|
| Compiler | Architecture | Operating System | CI |
|
||||||
|----------------------------------------------|--------------|--------------------------|-----------|
|
|----------------------------------------------|--------------|-----------------------------------|-----------|
|
||||||
| AppleClang 14.0.0.14000029; Xcode 14.1 | x86_64 | macOS 13.7.2 (Ventura) | GitHub |
|
| AppleClang 15.0.0.15000040; Xcode 15.0.1 | x86_64 | macOS 13.7.2 (Ventura) | GitHub |
|
||||||
| AppleClang 14.0.0.14000029; Xcode 14.2 | x86_64 | macOS 13.7.2 (Ventura) | GitHub |
|
| AppleClang 15.0.0.15000100; Xcode 15.1 | x86_64 | macOS 13.7.2 (Ventura) | GitHub |
|
||||||
| AppleClang 14.0.3.14030022; Xcode 14.3.1 | x86_64 | macOS 13.7.2 (Ventura) | GitHub |
|
| AppleClang 15.0.0.15000100; Xcode 15.2 | x86_64 | macOS 13.7.2 (Ventura) | GitHub |
|
||||||
| AppleClang 15.0.0.15000040; Xcode 15.0.1 | x86_64 | macOS 13.7.2 (Ventura) | GitHub |
|
| AppleClang 15.0.0.15000309; Xcode 15.3 | arm64 | macOS 14.7.2 (Sonoma) | GitHub |
|
||||||
| AppleClang 15.0.0.15000100; Xcode 15.1 | x86_64 | macOS 13.7.2 (Ventura) | GitHub |
|
| AppleClang 15.0.0.15000309; Xcode 15.4 | arm64 | macOS 14.7.2 (Sonoma) | GitHub |
|
||||||
| AppleClang 15.0.0.15000100; Xcode 15.2 | x86_64 | macOS 13.7.2 (Ventura) | GitHub |
|
| AppleClang 16.0.0.16000026; Xcode 16 | arm64 | macOS 15.2 (Sequoia) | GitHub |
|
||||||
| AppleClang 15.0.0.15000309; Xcode 15.3 | arm64 | macOS 14.7.2 (Sonoma) | GitHub |
|
| AppleClang 16.0.0.16000026; Xcode 16.1 | arm64 | macOS 15.2 (Sequoia) | GitHub |
|
||||||
| AppleClang 15.0.0.15000309; Xcode 15.4 | arm64 | macOS 14.7.2 (Sonoma) | GitHub |
|
| AppleClang 16.0.0.16000026; Xcode 16.2 | arm64 | macOS 15.2 (Sequoia) | GitHub |
|
||||||
| AppleClang 16.0.0.16000026; Xcode 16 | arm64 | macOS 15.2 (Sequoia) | GitHub |
|
| AppleClang 17.0.0.17000013; Xcode 16.3 | arm64 | macOS 15.5 (Sequoia) | GitHub |
|
||||||
| AppleClang 16.0.0.16000026; Xcode 16.1 | arm64 | macOS 15.2 (Sequoia) | GitHub |
|
| AppleClang 17.0.0.17000013; Xcode 16.4 | arm64 | macOS 15.5 (Sequoia) | GitHub |
|
||||||
| AppleClang 16.0.0.16000026; Xcode 16.2 | arm64 | macOS 15.2 (Sequoia) | GitHub |
|
| AppleClang 17.0.0.17000319; Xcode 26.0.1 | arm64 | macOS 15.5 (Sequoia) | GitHub |
|
||||||
| Clang 3.5.2 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 3.5.2 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| Clang 3.6.2 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 3.6.2 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| Clang 3.7.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 3.7.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| Clang 3.8.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 3.8.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| Clang 3.9.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 3.9.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| Clang 4.0.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 4.0.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| Clang 5.0.2 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 5.0.2 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| Clang 6.0.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 6.0.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| Clang 7.1.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 7.1.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| Clang 8.0.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 8.0.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| Clang 9.0.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 9.0.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| Clang 10.0.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 10.0.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| Clang 11.0.0 with GNU-like command-line | x86_64 | Windows 10 (Build 17763) | GitHub |
|
| Clang 11.0.1 with GNU-like command-line | x86_64 | Windows Server 2022 (Build 20348) | GitHub |
|
||||||
| Clang 11.1.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 11.1.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| Clang 12.0.0 with GNU-like command-line | x86_64 | Windows 10 (Build 17763) | GitHub |
|
| Clang 12.0.1 with GNU-like command-line | x86_64 | Windows Server 2022 (Build 20348) | GitHub |
|
||||||
| Clang 12.0.0 with MSVC-like command-line | x86_64 | Windows 10 (Build 17763) | GitHub |
|
| Clang 12.0.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| Clang 12.0.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 13.0.1 with GNU-like command-line | x86_64 | Windows Server 2022 (Build 20348) | GitHub |
|
||||||
| Clang 13.0.0 with GNU-like command-line | x86_64 | Windows 10 (Build 17763) | GitHub |
|
| Clang 13.0.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| Clang 13.0.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 14.0.6 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| Clang 14.0.0 with GNU-like command-line | x86_64 | Windows 10 (Build 17763) | GitHub |
|
| Clang 14.0.6 with GNU-like command-line | x86_64 | Windows Server 2022 (Build 20348) | GitHub |
|
||||||
| Clang 14.0.6 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 15.0.7 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| Clang 15.0.0 with GNU-like command-line | x86_64 | Windows 10 (Build 17763) | GitHub |
|
| Clang 15.0.7 with GNU-like command-line | x86_64 | Windows Server 2022 (Build 20348) | GitHub |
|
||||||
| Clang 15.0.7 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 16.0.6 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| Clang 16.0.6 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 16.0.6 with GNU-like command-line | x86_64 | Windows Server 2022 (Build 20348) | GitHub |
|
||||||
| Clang 17.0.6 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 17.0.6 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| Clang 18.1.8 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 18.1.8 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| Clang 19.1.7 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 18.1.8 with GNU-like command-line | x86_64 | Windows Server 2022 (Build 20348) | GitHub |
|
||||||
| Clang 20.1.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 19.1.5 with MSVC-like command-line | x86_64 | Windows Server 2022 (Build 20348) | GitHub |
|
||||||
| Clang 21.0.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 19.1.7 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| Emscripten 4.0.6 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 19.1.7 with GNU-like command-line | x86_64 | Windows Server 2022 (Build 20348) | GitHub |
|
||||||
| GNU 4.8.5 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 20.1.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| GNU 4.9.3 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 20.1.8 with GNU-like command-line | x86_64 | Windows Server 2022 (Build 20348) | GitHub |
|
||||||
| GNU 5.5.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 21.0.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| GNU 6.4.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Emscripten 4.0.6 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| GNU 7.5.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| GNU 4.8.5 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| GNU 8.5.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| GNU 4.9.3 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| GNU 9.3.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| GNU 5.5.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| GNU 9.4.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| GNU 6.4.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| GNU 9.5.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| GNU 7.5.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| GNU 10.5.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| GNU 8.5.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| GNU 11.4.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| GNU 9.3.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| GNU 11.5.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| GNU 9.4.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| GNU 12.2.0 (MinGW-W64 i686-ucrt-posix-dwarf) | x86_64 | Windows 10 (Build 17763) | GitHub |
|
| GNU 9.5.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| GNU 12.2.0 (MinGW-W64 x86_64-ucrt-posix-seh) | x86_64 | Windows 10 (Build 17763) | GitHub |
|
| GNU 10.5.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| GNU 12.4.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| GNU 11.4.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| GNU 13.3.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| GNU 11.5.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| GNU 14.2.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| GNU 12.2.0 (MinGW-W64 i686-ucrt-posix-dwarf) | x86_64 | Windows Server 2022 (Build 20348) | GitHub |
|
||||||
| GNU 14.2.0 | arm64 | Linux 6.1.100 | Cirrus CI |
|
| GNU 12.2.0 (MinGW-W64 x86_64-ucrt-posix-seh) | x86_64 | Windows Server 2022 (Build 20348) | GitHub |
|
||||||
| GNU 15.1.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| GNU 12.4.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| icpc (ICC) 2021.5.0 20211109 | x86_64 | Ubuntu 20.04.3 LTS | GitHub |
|
| GNU 13.3.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| MSVC 19.0.24241.7 | x86 | Windows 8.1 | AppVeyor |
|
| GNU 14.2.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| MSVC 19.16.27035.0 | x86 | Windows-10 (Build 14393) | AppVeyor |
|
| GNU 14.2.0 | arm64 | Linux 6.1.100 | Cirrus CI |
|
||||||
| MSVC 19.29.30157.0 | x86 | Windows 10 (Build 17763) | GitHub |
|
| GNU 15.1.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| MSVC 19.29.30157.0 | x86_64 | Windows 10 (Build 17763) | GitHub |
|
| icpc (ICC) 2021.5.0 20211109 | x86_64 | Ubuntu 20.04.3 LTS | GitHub |
|
||||||
| MSVC 19.29.30157.0 | x86 | Windows-10 (Build 17763) | AppVeyor |
|
| MSVC 19.0.24241.7 | x86 | Windows 8.1 | AppVeyor |
|
||||||
| MSVC 19.42.34435.0 | x86 | Windows 10 (Build 20348) | GitHub |
|
| MSVC 19.16.27035.0 | x86 | Windows-10 (Build 14393) | AppVeyor |
|
||||||
| MSVC 19.42.34435.0 | x86_64 | Windows 10 (Build 20348) | GitHub |
|
| MSVC 19.29.30157.0 | x86 | Windows-10 (Build 17763) | AppVeyor |
|
||||||
|
| MSVC 19.44.35214.0 | x86 | Windows Server 2022 (Build 20348) | GitHub |
|
||||||
|
| MSVC 19.44.35214.0 | x86_64 | Windows Server 2022 (Build 20348) | GitHub |
|
||||||
|
|
||||||
- [x] The library is compiled with all C++ language revisions (C++11, C++14, C++17, C++20, C++23, and C++26) to detect
|
- [x] The library is compiled with all C++ language revisions (C++11, C++14, C++17, C++20, C++23, and C++26) to detect
|
||||||
and fix language deprecations early.
|
and fix language deprecations early.
|
||||||
- [x] The library is checked for compiler warnings:
|
- [x] The library is checked for compiler warnings:
|
||||||
- On Clang, `-Weverything` is used with 7 exceptions.
|
- On Clang, `-Weverything` is used with 8 exceptions.
|
||||||
|
|
||||||
??? abstract "Clang warnings"
|
??? abstract "Clang warnings"
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::string s = R"(
|
||||||
|
{
|
||||||
|
// update in 2006: removed Pluto
|
||||||
|
"planets": ["Mercury", "Venus", "Earth", "Mars",
|
||||||
|
"Jupiter", "Uranus", "Neptune" /*, "Pluto" */]
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
json j = json::parse(s);
|
||||||
|
}
|
||||||
|
catch (json::exception& e)
|
||||||
|
{
|
||||||
|
std::cout << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
json j = json::parse(s,
|
||||||
|
/* callback */ nullptr,
|
||||||
|
/* allow exceptions */ true,
|
||||||
|
/* ignore_comments */ true);
|
||||||
|
std::cout << j.dump(2) << '\n';
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
[json.exception.parse_error.101] parse error at line 3, column 9: syntax error while parsing object key - invalid literal; last read: '<U+000A> {<U+000A> /'; expected string literal
|
||||||
|
{
|
||||||
|
"planets": [
|
||||||
|
"Mercury",
|
||||||
|
"Venus",
|
||||||
|
"Earth",
|
||||||
|
"Mars",
|
||||||
|
"Jupiter",
|
||||||
|
"Uranus",
|
||||||
|
"Neptune"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
/* Demonstration of type error exception with diagnostic postions support enabled */
|
/* Demonstration of type error exception with diagnostic positions support enabled */
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
//Invalid json string - housenumber type must be int instead of string
|
//Invalid json string - housenumber type must be int instead of string
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
/* Demonstration of type error exception with diagnostic postions support enabled */
|
/* Demonstration of type error exception with diagnostic positions support enabled */
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
//Invalid json string - housenumber type must be int instead of string
|
//Invalid json string - housenumber type must be int instead of string
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ int main()
|
|||||||
j["address"] = "744 Evergreen Terrace";
|
j["address"] = "744 Evergreen Terrace";
|
||||||
j["age"] = 60;
|
j["age"] = 60;
|
||||||
|
|
||||||
auto p = j.template get<ns::person>();
|
auto p = j.get<ns::person>();
|
||||||
|
|
||||||
std::cout << p.name << " (" << p.age << ") lives in " << p.address << std::endl;
|
std::cout << p.name << " (" << p.age << ") lives in " << p.address << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ int main()
|
|||||||
j["address"] = "744 Evergreen Terrace";
|
j["address"] = "744 Evergreen Terrace";
|
||||||
j["age"] = 60;
|
j["age"] = 60;
|
||||||
|
|
||||||
auto p = j.template get<ns::person>();
|
auto p = j.get<ns::person>();
|
||||||
|
|
||||||
std::cout << p.name << " (" << p.age << ") lives in " << p.address << std::endl;
|
std::cout << p.name << " (" << p.age << ") lives in " << p.address << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ int main()
|
|||||||
json value = 17;
|
json value = 17;
|
||||||
|
|
||||||
// explicitly getting pointers
|
// explicitly getting pointers
|
||||||
auto p1 = value.template get<const json::number_integer_t*>();
|
auto p1 = value.get<const json::number_integer_t*>();
|
||||||
auto p2 = value.template get<json::number_integer_t*>();
|
auto p2 = value.get<json::number_integer_t*>();
|
||||||
auto p3 = value.template get<json::number_integer_t* const>();
|
auto p3 = value.get<json::number_integer_t* const>();
|
||||||
auto p4 = value.template get<const json::number_integer_t* const>();
|
auto p4 = value.get<const json::number_integer_t* const>();
|
||||||
auto p5 = value.template get<json::number_float_t*>();
|
auto p5 = value.get<json::number_float_t*>();
|
||||||
|
|
||||||
// print the pointees
|
// print the pointees
|
||||||
std::cout << *p1 << ' ' << *p2 << ' ' << *p3 << ' ' << *p4 << '\n';
|
std::cout << *p1 << ' ' << *p2 << ' ' << *p3 << ' ' << *p4 << '\n';
|
||||||
|
|||||||
@@ -22,14 +22,14 @@ int main()
|
|||||||
};
|
};
|
||||||
|
|
||||||
// use explicit conversions
|
// use explicit conversions
|
||||||
auto v1 = json_types["boolean"].template get<bool>();
|
auto v1 = json_types["boolean"].get<bool>();
|
||||||
auto v2 = json_types["number"]["integer"].template get<int>();
|
auto v2 = json_types["number"]["integer"].get<int>();
|
||||||
auto v3 = json_types["number"]["integer"].template get<short>();
|
auto v3 = json_types["number"]["integer"].get<short>();
|
||||||
auto v4 = json_types["number"]["floating-point"].template get<float>();
|
auto v4 = json_types["number"]["floating-point"].get<float>();
|
||||||
auto v5 = json_types["number"]["floating-point"].template get<int>();
|
auto v5 = json_types["number"]["floating-point"].get<int>();
|
||||||
auto v6 = json_types["string"].template get<std::string>();
|
auto v6 = json_types["string"].get<std::string>();
|
||||||
auto v7 = json_types["array"].template get<std::vector<short>>();
|
auto v7 = json_types["array"].get<std::vector<short>>();
|
||||||
auto v8 = json_types.template get<std::unordered_map<std::string, json>>();
|
auto v8 = json_types.get<std::unordered_map<std::string, json>>();
|
||||||
|
|
||||||
// print the conversion results
|
// print the conversion results
|
||||||
std::cout << v1 << '\n';
|
std::cout << v1 << '\n';
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// different JSON Pointers
|
||||||
|
json::json_pointer ptr1("/foo");
|
||||||
|
json::json_pointer ptr2("/foo/0");
|
||||||
|
|
||||||
|
// call empty()
|
||||||
|
std::cout << "first reference token of \"" << ptr1 << "\" is \"" << ptr1.front() << "\"\n"
|
||||||
|
<< "first reference token of \"" << ptr2 << "\" is \"" << ptr2.front() << "\"" << std::endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
first reference token of "/foo" is "foo"
|
||||||
|
first reference token of "/foo/0" is "foo"
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// create empty JSON Pointer
|
||||||
|
json::json_pointer ptr("/foo/bar/baz");
|
||||||
|
std::cout << "\"" << ptr << "\"\n";
|
||||||
|
|
||||||
|
// call pop_front()
|
||||||
|
ptr.pop_front();
|
||||||
|
std::cout << "\"" << ptr << "\"\n";
|
||||||
|
|
||||||
|
ptr.pop_front();
|
||||||
|
std::cout << "\"" << ptr << "\"\n";
|
||||||
|
|
||||||
|
ptr.pop_front();
|
||||||
|
std::cout << "\"" << ptr << "\"\n";
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
"/foo/bar/baz"
|
||||||
|
"/bar/baz"
|
||||||
|
"/baz"
|
||||||
|
""
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// create empty JSON Pointer
|
||||||
|
json::json_pointer ptr;
|
||||||
|
std::cout << "\"" << ptr << "\"\n";
|
||||||
|
|
||||||
|
// call push_front()
|
||||||
|
ptr.push_front("foo");
|
||||||
|
std::cout << "\"" << ptr << "\"\n";
|
||||||
|
|
||||||
|
ptr.push_front("0");
|
||||||
|
std::cout << "\"" << ptr << "\"\n";
|
||||||
|
|
||||||
|
ptr.push_front("bar");
|
||||||
|
std::cout << "\"" << ptr << "\"\n";
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
""
|
||||||
|
"/foo"
|
||||||
|
"/0/foo"
|
||||||
|
"/bar/0/foo"
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
"family": "gcc",
|
"family": "gcc",
|
||||||
"version": "12.4.0"
|
"version": "12.4.0"
|
||||||
},
|
},
|
||||||
"copyright": "(C) 2013-2025 Niels Lohmann",
|
"copyright": "(C) 2013-2026 Niels Lohmann",
|
||||||
"name": "JSON for Modern C++",
|
"name": "JSON for Modern C++",
|
||||||
"platform": "apple",
|
"platform": "apple",
|
||||||
"url": "https://github.com/nlohmann/json",
|
"url": "https://github.com/nlohmann/json",
|
||||||
|
|||||||
@@ -47,13 +47,13 @@ int main()
|
|||||||
|
|
||||||
// deserialization: json -> person
|
// deserialization: json -> person
|
||||||
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
||||||
auto p2 = j2.template get<ns::person>();
|
auto p2 = j2.get<ns::person>();
|
||||||
|
|
||||||
// incomplete deserialization:
|
// incomplete deserialization:
|
||||||
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto p3 = j3.template get<ns::person>();
|
auto p3 = j3.get<ns::person>();
|
||||||
}
|
}
|
||||||
catch (const json::exception& e)
|
catch (const json::exception& e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -33,13 +33,13 @@ int main()
|
|||||||
|
|
||||||
// deserialization: json -> person
|
// deserialization: json -> person
|
||||||
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
||||||
auto p2 = j2.template get<ns::person>();
|
auto p2 = j2.get<ns::person>();
|
||||||
|
|
||||||
// incomplete deserialization:
|
// incomplete deserialization:
|
||||||
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto p3 = j3.template get<ns::person>();
|
auto p3 = j3.get<ns::person>();
|
||||||
}
|
}
|
||||||
catch (const json::exception& e)
|
catch (const json::exception& e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -48,10 +48,10 @@ int main()
|
|||||||
|
|
||||||
// deserialization: json -> person
|
// deserialization: json -> person
|
||||||
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
||||||
auto p2 = j2.template get<ns::person>();
|
auto p2 = j2.get<ns::person>();
|
||||||
|
|
||||||
// incomplete deserialization:
|
// incomplete deserialization:
|
||||||
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
||||||
auto p3 = j3.template get<ns::person>();
|
auto p3 = j3.get<ns::person>();
|
||||||
std::cout << "roundtrip: " << json(p3) << std::endl;
|
std::cout << "roundtrip: " << json(p3) << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,10 +33,10 @@ int main()
|
|||||||
|
|
||||||
// deserialization: json -> person
|
// deserialization: json -> person
|
||||||
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
||||||
auto p2 = j2.template get<ns::person>();
|
auto p2 = j2.get<ns::person>();
|
||||||
|
|
||||||
// incomplete deserialization:
|
// incomplete deserialization:
|
||||||
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
||||||
auto p3 = j3.template get<ns::person>();
|
auto p3 = j3.get<ns::person>();
|
||||||
std::cout << "roundtrip: " << json(p3) << std::endl;
|
std::cout << "roundtrip: " << json(p3) << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,13 +40,13 @@ int main()
|
|||||||
|
|
||||||
// deserialization: json -> person
|
// deserialization: json -> person
|
||||||
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
||||||
auto p2 = j2.template get<ns::person>();
|
auto p2 = j2.get<ns::person>();
|
||||||
|
|
||||||
// incomplete deserialization:
|
// incomplete deserialization:
|
||||||
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto p3 = j3.template get<ns::person>();
|
auto p3 = j3.get<ns::person>();
|
||||||
}
|
}
|
||||||
catch (const json::exception& e)
|
catch (const json::exception& e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -26,13 +26,13 @@ int main()
|
|||||||
|
|
||||||
// deserialization: json -> person
|
// deserialization: json -> person
|
||||||
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
||||||
auto p2 = j2.template get<ns::person>();
|
auto p2 = j2.get<ns::person>();
|
||||||
|
|
||||||
// incomplete deserialization:
|
// incomplete deserialization:
|
||||||
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto p3 = j3.template get<ns::person>();
|
auto p3 = j3.get<ns::person>();
|
||||||
}
|
}
|
||||||
catch (const json::exception& e)
|
catch (const json::exception& e)
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-2
@@ -46,10 +46,10 @@ int main()
|
|||||||
|
|
||||||
// deserialization: json -> person
|
// deserialization: json -> person
|
||||||
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
||||||
auto p2 = j2.template get<ns::person>();
|
auto p2 = j2.get<ns::person>();
|
||||||
|
|
||||||
// incomplete deserialization:
|
// incomplete deserialization:
|
||||||
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
||||||
auto p3 = j3.template get<ns::person>();
|
auto p3 = j3.get<ns::person>();
|
||||||
std::cout << "roundtrip: " << json(p3) << std::endl;
|
std::cout << "roundtrip: " << json(p3) << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ int main()
|
|||||||
|
|
||||||
// deserialization: json -> person
|
// deserialization: json -> person
|
||||||
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
|
||||||
auto p2 = j2.template get<ns::person>();
|
auto p2 = j2.get<ns::person>();
|
||||||
|
|
||||||
// incomplete deserialization:
|
// incomplete deserialization:
|
||||||
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
|
||||||
auto p3 = j3.template get<ns::person>();
|
auto p3 = j3.get<ns::person>();
|
||||||
std::cout << "roundtrip: " << json(p3) << std::endl;
|
std::cout << "roundtrip: " << json(p3) << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
using namespace nlohmann::literals;
|
||||||
|
|
||||||
|
namespace ns
|
||||||
|
{
|
||||||
|
struct person
|
||||||
|
{
|
||||||
|
std::string name;
|
||||||
|
std::string address;
|
||||||
|
int age;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0>
|
||||||
|
void to_json(BasicJsonType& nlohmann_json_j, const person& nlohmann_json_t)
|
||||||
|
{
|
||||||
|
nlohmann_json_j["json_name"] = nlohmann_json_t.name;
|
||||||
|
nlohmann_json_j["json_address"] = nlohmann_json_t.address;
|
||||||
|
nlohmann_json_j["json_age"] = nlohmann_json_t.age;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0>
|
||||||
|
void from_json(const BasicJsonType& nlohmann_json_j, person& nlohmann_json_t)
|
||||||
|
{
|
||||||
|
nlohmann_json_j.at("json_name").get_to(nlohmann_json_t.name);
|
||||||
|
nlohmann_json_j.at("json_address").get_to(nlohmann_json_t.address);
|
||||||
|
nlohmann_json_j.at("json_age").get_to(nlohmann_json_t.age);
|
||||||
|
}
|
||||||
|
} // namespace ns
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60};
|
||||||
|
|
||||||
|
// serialization: person -> json
|
||||||
|
json j = p;
|
||||||
|
std::cout << "serialization: " << j << std::endl;
|
||||||
|
|
||||||
|
// deserialization: json -> person
|
||||||
|
json j2 = R"({"json_address": "742 Evergreen Terrace", "json_age": 40, "json_name": "Homer Simpson"})"_json;
|
||||||
|
auto p2 = j2.template get<ns::person>();
|
||||||
|
|
||||||
|
// incomplete deserialization:
|
||||||
|
json j3 = R"({"json_address": "742 Evergreen Terrace", "json_name": "Maggie Simpson"})"_json;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
auto p3 = j3.template get<ns::person>();
|
||||||
|
}
|
||||||
|
catch (const json::exception& e)
|
||||||
|
{
|
||||||
|
std::cout << "deserialization failed: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
serialization: {"json_address":"744 Evergreen Terrace","json_age":60,"json_name":"Ned Flanders"}
|
||||||
|
deserialization failed: [json.exception.out_of_range.403] key 'json_age' not found
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
using namespace nlohmann::literals;
|
||||||
|
|
||||||
|
namespace ns
|
||||||
|
{
|
||||||
|
struct person
|
||||||
|
{
|
||||||
|
std::string name;
|
||||||
|
std::string address;
|
||||||
|
int age;
|
||||||
|
};
|
||||||
|
|
||||||
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_NAMES(person, "json_name", name, "json_address", address, "json_age", age)
|
||||||
|
} // namespace ns
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60};
|
||||||
|
|
||||||
|
// serialization: person -> json
|
||||||
|
json j = p;
|
||||||
|
std::cout << "serialization: " << j << std::endl;
|
||||||
|
|
||||||
|
// deserialization: json -> person
|
||||||
|
json j2 = R"({"json_address": "742 Evergreen Terrace", "json_age": 40, "json_name": "Homer Simpson"})"_json;
|
||||||
|
auto p2 = j2.template get<ns::person>();
|
||||||
|
|
||||||
|
// incomplete deserialization:
|
||||||
|
json j3 = R"({"json_address": "742 Evergreen Terrace", "json_name": "Maggie Simpson"})"_json;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
auto p3 = j3.template get<ns::person>();
|
||||||
|
}
|
||||||
|
catch (const json::exception& e)
|
||||||
|
{
|
||||||
|
std::cout << "deserialization failed: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
serialization: {"json_address":"744 Evergreen Terrace","json_age":60,"json_name":"Ned Flanders"}
|
||||||
|
deserialization failed: [json.exception.out_of_range.403] key 'json_age' not found
|
||||||
@@ -44,16 +44,16 @@ int main()
|
|||||||
// deserialization
|
// deserialization
|
||||||
json j_running = "running";
|
json j_running = "running";
|
||||||
json j_blue = "blue";
|
json j_blue = "blue";
|
||||||
auto running = j_running.template get<ns::TaskState>();
|
auto running = j_running.get<ns::TaskState>();
|
||||||
auto blue = j_blue.template get<ns::Color>();
|
auto blue = j_blue.get<ns::Color>();
|
||||||
std::cout << j_running << " -> " << running
|
std::cout << j_running << " -> " << running
|
||||||
<< ", " << j_blue << " -> " << static_cast<int>(blue) << std::endl;
|
<< ", " << j_blue << " -> " << static_cast<int>(blue) << std::endl;
|
||||||
|
|
||||||
// deserializing undefined JSON value to enum
|
// deserializing undefined JSON value to enum
|
||||||
// (where the first map entry above is the default)
|
// (where the first map entry above is the default)
|
||||||
json j_pi = 3.14;
|
json j_pi = 3.14;
|
||||||
auto invalid = j_pi.template get<ns::TaskState>();
|
auto invalid = j_pi.get<ns::TaskState>();
|
||||||
auto unknown = j_pi.template get<ns::Color>();
|
auto unknown = j_pi.get<ns::Color>();
|
||||||
std::cout << j_pi << " -> " << invalid << ", "
|
std::cout << j_pi << " -> " << invalid << ", "
|
||||||
<< j_pi << " -> " << static_cast<int>(unknown) << std::endl;
|
<< j_pi << " -> " << static_cast<int>(unknown) << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ int main()
|
|||||||
|
|
||||||
// deserialization
|
// deserialization
|
||||||
json j_rot = "rot";
|
json j_rot = "rot";
|
||||||
auto rot = j_rot.template get<ns::Color>();
|
auto rot = j_rot.get<ns::Color>();
|
||||||
auto red = j_red.template get<ns::Color>();
|
auto red = j_red.get<ns::Color>();
|
||||||
std::cout << j_rot << " -> " << static_cast<int>(rot) << std::endl;
|
std::cout << j_rot << " -> " << static_cast<int>(rot) << std::endl;
|
||||||
std::cout << j_red << " -> " << static_cast<int>(red) << std::endl;
|
std::cout << j_red << " -> " << static_cast<int>(red) << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
namespace ns
|
||||||
|
{
|
||||||
|
enum TaskState
|
||||||
|
{
|
||||||
|
TS_STOPPED,
|
||||||
|
TS_RUNNING,
|
||||||
|
TS_COMPLETED,
|
||||||
|
TS_INVALID = -1
|
||||||
|
};
|
||||||
|
|
||||||
|
NLOHMANN_JSON_SERIALIZE_ENUM_STRICT(TaskState,
|
||||||
|
{
|
||||||
|
{ TS_INVALID, nullptr },
|
||||||
|
{ TS_STOPPED, "stopped" },
|
||||||
|
{ TS_RUNNING, "running" },
|
||||||
|
{ TS_COMPLETED, "completed" }
|
||||||
|
})
|
||||||
|
|
||||||
|
enum class Color
|
||||||
|
{
|
||||||
|
red, green, blue, unknown
|
||||||
|
};
|
||||||
|
|
||||||
|
NLOHMANN_JSON_SERIALIZE_ENUM_STRICT(Color,
|
||||||
|
{
|
||||||
|
{ Color::unknown, "unknown" }, { Color::red, "red" },
|
||||||
|
{ Color::green, "green" }, { Color::blue, "blue" }
|
||||||
|
})
|
||||||
|
} // namespace ns
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// serialization
|
||||||
|
json j_stopped = ns::TS_STOPPED;
|
||||||
|
json j_red = ns::Color::red;
|
||||||
|
std::cout << "ns::TS_STOPPED -> " << j_stopped
|
||||||
|
<< ", ns::Color::red -> " << j_red << std::endl;
|
||||||
|
|
||||||
|
// deserialization
|
||||||
|
json j_running = "running";
|
||||||
|
json j_blue = "blue";
|
||||||
|
auto running = j_running.get<ns::TaskState>();
|
||||||
|
auto blue = j_blue.get<ns::Color>();
|
||||||
|
std::cout << j_running << " -> " << running
|
||||||
|
<< ", " << j_blue << " -> " << static_cast<int>(blue) << std::endl;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
ns::TS_STOPPED -> "stopped", ns::Color::red -> "red"
|
||||||
|
"running" -> 1, "blue" -> 2
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
namespace ns
|
||||||
|
{
|
||||||
|
enum class Color
|
||||||
|
{
|
||||||
|
red, green, blue, unknown
|
||||||
|
};
|
||||||
|
|
||||||
|
NLOHMANN_JSON_SERIALIZE_ENUM_STRICT(Color,
|
||||||
|
{
|
||||||
|
{ Color::unknown, "unknown" }, { Color::red, "red" },
|
||||||
|
{ Color::green, "green" }, { Color::blue, "blue" },
|
||||||
|
{ Color::red, "rot" } // a second conversion for Color::red
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// serialization
|
||||||
|
json j_red = ns::Color::red;
|
||||||
|
std::cout << static_cast<int>(ns::Color::red) << " -> " << j_red << std::endl;
|
||||||
|
|
||||||
|
// deserialization
|
||||||
|
json j_rot = "rot";
|
||||||
|
auto rot = j_rot.get<ns::Color>();
|
||||||
|
auto red = j_red.get<ns::Color>();
|
||||||
|
std::cout << j_rot << " -> " << static_cast<int>(rot) << std::endl;
|
||||||
|
std::cout << j_red << " -> " << static_cast<int>(red) << std::endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
0 -> "red"
|
||||||
|
"rot" -> 0
|
||||||
|
"red" -> 0
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
namespace ns
|
||||||
|
{
|
||||||
|
|
||||||
|
enum class Color
|
||||||
|
{
|
||||||
|
red,
|
||||||
|
green,
|
||||||
|
blue,
|
||||||
|
unknown // not mapped in JSON_SERIALIZE_ENUM_STRICT
|
||||||
|
};
|
||||||
|
|
||||||
|
NLOHMANN_JSON_SERIALIZE_ENUM_STRICT(Color,
|
||||||
|
{
|
||||||
|
{Color::red, "red"},
|
||||||
|
{Color::green, "green"},
|
||||||
|
{Color::blue, "blue"}
|
||||||
|
})
|
||||||
|
|
||||||
|
} // namespace ns
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// invalid serialization
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// ns::color::unknown was not mapped in macro
|
||||||
|
json invalid_serialization = ns::Color::unknown;
|
||||||
|
}
|
||||||
|
catch (const json::exception e)
|
||||||
|
{
|
||||||
|
std::cout << "deserialization failed: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// invalid deserialization
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// what does not map to an enum
|
||||||
|
json invalid_deserialization("what");
|
||||||
|
ns::Color color = invalid_deserialization.get<ns::Color>();
|
||||||
|
}
|
||||||
|
catch (const json::exception e)
|
||||||
|
{
|
||||||
|
std::cout << "deserialization failed: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
deserialization failed: [json.exception.out_of_range.410] enum value out of range for Color
|
||||||
|
deserialization failed: [json.exception.out_of_range.410] enum value out of range for Color: "what"
|
||||||
@@ -5,7 +5,7 @@ using json = nlohmann::json;
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// create JSON poiner
|
// create JSON pointer
|
||||||
json::json_pointer ptr("/foo/bar/baz");
|
json::json_pointer ptr("/foo/bar/baz");
|
||||||
|
|
||||||
// write string representation to stream
|
// write string representation to stream
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::string s = R"(
|
||||||
|
{
|
||||||
|
"planets": [
|
||||||
|
"Mercury",
|
||||||
|
"Venus",
|
||||||
|
"Earth",
|
||||||
|
"Mars",
|
||||||
|
"Jupiter",
|
||||||
|
"Uranus",
|
||||||
|
"Neptune",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
json j = json::parse(s);
|
||||||
|
}
|
||||||
|
catch (json::exception& e)
|
||||||
|
{
|
||||||
|
std::cout << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
json j = json::parse(s,
|
||||||
|
/* callback */ nullptr,
|
||||||
|
/* allow exceptions */ true,
|
||||||
|
/* ignore_comments */ false,
|
||||||
|
/* ignore_trailing_commas */ true);
|
||||||
|
std::cout << j.dump(2) << '\n';
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
[json.exception.parse_error.101] parse error at line 11, column 9: syntax error while parsing value - unexpected ']'; expected '[', '{', or a literal
|
||||||
|
{
|
||||||
|
"planets": [
|
||||||
|
"Mercury",
|
||||||
|
"Venus",
|
||||||
|
"Earth",
|
||||||
|
"Mars",
|
||||||
|
"Jupiter",
|
||||||
|
"Uranus",
|
||||||
|
"Neptune"
|
||||||
|
]
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user