mirror of
https://github.com/nlohmann/json.git
synced 2026-02-19 18:06:25 +00:00
Added examples and modified the corresponding documents and unit tests. Signed-off-by: chirsz-ever <chirsz-ever@outlook.com> Co-authored-by: Niels Lohmann <niels.lohmann@gmail.com>
1.3 KiB
1.3 KiB
Trailing Commas
Like comments, this library does not support trailing commas in arrays and objects by default.
You can set parameter ignore_trailing_commas to #!cpp true in the parse function to allow 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).
!!! example
Consider the following JSON with trailing commas.
```json
{
"planets": [
"Mercury",
"Venus",
"Earth",
"Mars",
"Jupiter",
"Uranus",
"Neptune",
]
}
```
When calling `parse` without additional argument, a parse error exception is thrown. If `ignore_trailing_commas` is set to `#! true`, the trailing commas are ignored during parsing:
```cpp
--8<-- "examples/trailing_commas.cpp"
```
Output:
```
--8<-- "examples/trailing_commas.output"
```