mirror of
https://github.com/nlohmann/json.git
synced 2026-09-30 22:15:19 +00:00
- API pages for basic_json_document and basic_json_view, one per member, and for the four aliases, each with an example - features/json_view.md: the problem the view solves, ownership and lifetime, what matches basic_json::parse() and what differs, and when to choose json, ordered_json, SAX, or the view - the examples show why one would use the view, not only how: borrowed vs. owned input, reading a few fields and materializing one subtree, reusing a document across many messages - registered in the mkdocs navigation, llms.txt, the docset, the exceptions page (out_of_range.416), architecture.md, the integration page, and the README; the yyjson credit is added to the README and license.md Signed-off-by: Niels Lohmann <mail@nlohmann.me>
1.8 KiB
1.8 KiB
nlohmann::basic_json_document::accept
template<typename InputType>
static bool accept(InputType&& input,
const bool ignore_comments = false,
const bool ignore_trailing_commas = false);
Checks whether the input is valid JSON, accepting and rejecting exactly what
BasicJsonType::accept() does, with the same options. Unlike parse(), this
function never throws an exception for invalid input, and the returned #!cpp bool is the only result -- no document
is returned.
Template parameters
InputType- A compatible input; see
parse.
Parameters
input(in)- Input to check.
ignore_comments(in)- whether comments should be ignored and treated like whitespace (
#!cpp true) or yield a parse error (#!cpp false); (optional,#!cpp falseby 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 falseby default)
Return value
Whether the input is valid JSON.
Exception safety
Strong guarantee: this function itself never throws for an invalid input; it can only throw what allocating the input's own copy (for inputs that are always read into a buffer) throws.
Complexity
Linear in the length of the input.
Examples
??? example
```cpp
--8<-- "examples/basic_json_document__accept.cpp"
```
Output:
```json
--8<-- "examples/basic_json_document__accept.output"
```
See also
- parse - deserialize from a compatible input
BasicJsonType::accept- the corresponding function ofbasic_json
Version history
- Added in version 3.13.0.