File: err_handler.md

package info (click to toggle)
jsoncons 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 17,584 kB
  • sloc: cpp: 136,382; sh: 33; makefile: 5
file content (29 lines) | stat: -rw-r--r-- 1,035 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
### JSON Parsing Error Handling

```cpp
#include <jsoncons/json_parser.hpp>     // (until 0.171.0)
#include <jsoncons/json_options.hpp>    // (since 0.171.0)

std::function<bool(json_errc,const ser_context&)>
```

<br>

JSON parsing error handling is defined by a function object that receives arguments 
`std::error_code` and const `ser_context&`, and returns a `bool`. The JSON parser will report all errors
through the function object. If the function object returns `true`, the parser
will make an attempt to recover from recoverable errors. If the error is non-recoverable of if the function object
returns `false`, the parser will stop. 

The jsoncons library comes with three built-in function objects for JSON parsing error handling:

- `default_json_parsing`, which returns `true` if the error code indicates a comment, otherwise `false`

- `strict_json_parsing`, which always returns `false`

- `allow_trailing_commas`, which returns `true` if the error code indicates a comment or an extra comma, otherwise `false`