diff --git a/api/basic_json_document/accept.md b/api/basic_json_document/accept.md index eb6f9d197..cdb4c4927 100644 --- a/api/basic_json_document/accept.md +++ b/api/basic_json_document/accept.md @@ -13,9 +13,15 @@ function never throws an exception for invalid input, and the returned `#!cpp bo is returned. The result is the same as that of `BasicJsonType::accept()` by design; the difference is how the check is made. This -function runs the document's index builder (and discards the index), while `BasicJsonType::accept()` runs the SAX -parser with a handler that ignores every event. Use this one if you go on to parse the same input with -[`parse()`](parse.md) anyway, so that both use the same code; either is fine for a plain yes/no answer. +function runs the document's builder, which checks the text as [`parse()`](parse.md) does, while +`BasicJsonType::accept()` runs the SAX parser with a handler that ignores every event. Use this one if you go on to +parse the same input with [`parse()`](parse.md) anyway, so that both use the same code; either is fine for a plain +yes/no answer. + +When both `ignore_comments` and `ignore_trailing_commas` are `#!cpp false` (the default), the builder writes no index. +With either option set, it builds the index as [`parse()`](parse.md) does and discards it: the result is the same, only +the time differs. (Neither option needs the index; the variant that skips it exists only for the default options to +keep the code size down.) ## Template parameters diff --git a/api/basic_json_document/accept/index.html b/api/basic_json_document/accept/index.html index b624f6339..b3cc30411 100644 --- a/api/basic_json_document/accept/index.html +++ b/api/basic_json_document/accept/index.html @@ -2,7 +2,7 @@ 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 bool is the only result — no document is returned.
The result is the same as that of BasicJsonType::accept() by design; the difference is how the check is made. This function runs the document's index builder (and discards the index), while BasicJsonType::accept() runs the SAX parser with a handler that ignores every event. Use this one if you go on to parse the same input with parse() anyway, so that both use the same code; either is fine for a plain yes/no answer.
InputTypeparse.input (in)ignore_comments (in)true) or yield a parse error (false); (optional, false by default)ignore_trailing_commas (in)true) or yield a parse error (false); (optional, false by default)Whether the input is valid JSON.
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.
Linear in the length of the input.
An integer argument that is not a bool where the flags are expected, such as accept(ptr, len), does not compile; see parse.
#include <iostream>
+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 bool is the only result — no document is returned.
The result is the same as that of BasicJsonType::accept() by design; the difference is how the check is made. This function runs the document's builder, which checks the text as parse() does, while BasicJsonType::accept() runs the SAX parser with a handler that ignores every event. Use this one if you go on to parse the same input with parse() anyway, so that both use the same code; either is fine for a plain yes/no answer.
When both ignore_comments and ignore_trailing_commas are false (the default), the builder writes no index. With either option set, it builds the index as parse() does and discards it: the result is the same, only the time differs. (Neither option needs the index; the variant that skips it exists only for the default options to keep the code size down.)
InputTypeparse.input (in)ignore_comments (in)true) or yield a parse error (false); (optional, false by default)ignore_trailing_commas (in)true) or yield a parse error (false); (optional, false by default)Whether the input is valid JSON.
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.
Linear in the length of the input.
An integer argument that is not a bool where the flags are expected, such as accept(ptr, len), does not compile; see parse.
#include <iostream>
#include <nlohmann/json.hpp>
#include <nlohmann/json_view.hpp>
@@ -25,4 +25,4 @@
false
true
true
-parse - deserialize from a compatible inputBasicJsonType::accept - the corresponding function of basic_json