mirror of
https://github.com/nlohmann/json.git
synced 2025-07-28 12:02:00 +03:00
Add documentation for comparing json and ordered_json (#3599)
* 📝 add documentation for #3443 * Apply suggestions from code review Co-authored-by: Florian Albrechtskirchinger <falbrechtskirchinger@gmail.com>
This commit is contained in:
16
docs/examples/operator__equal__specializations.cpp
Normal file
16
docs/examples/operator__equal__specializations.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
nlohmann::json uj1 = {{"version", 1}, {"type", "integer"}};
|
||||||
|
nlohmann::json uj2 = {{"type", "integer"}, {"version", 1}};
|
||||||
|
|
||||||
|
nlohmann::ordered_json oj1 = {{"version", 1}, {"type", "integer"}};
|
||||||
|
nlohmann::ordered_json oj2 = {{"type", "integer"}, {"version", 1}};
|
||||||
|
|
||||||
|
std::cout << std::boolalpha << (uj1 == uj2) << '\n' << (oj1 == oj2) << std::endl;
|
||||||
|
}
|
2
docs/examples/operator__equal__specializations.output
Normal file
2
docs/examples/operator__equal__specializations.output
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
true
|
||||||
|
false
|
@ -99,6 +99,39 @@ Linear.
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
!!! note "Comparing different `basic_json` specializations"
|
||||||
|
|
||||||
|
Comparing different `basic_json` specializations can have surprising effects. For instance, the result of comparing
|
||||||
|
the JSON objects
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"version": 1,
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
and
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"version": 1
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
depends on whether [`nlohmann::json`](../json.md) or [`nlohmann::ordered_json`](../ordered_json.md) is used:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/operator__equal__specializations.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```json
|
||||||
|
--8<-- "examples/operator__equal__specializations.output"
|
||||||
|
```
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
??? example
|
??? example
|
||||||
|
Reference in New Issue
Block a user