diff --git a/reference/json/functions/json-validate.xml b/reference/json/functions/json-validate.xml new file mode 100644 index 000000000000..f45929ae944a --- /dev/null +++ b/reference/json/functions/json-validate.xml @@ -0,0 +1,159 @@ + + + + + json_validate + Checks if a string contains valid JSON + + + + &reftitle.description; + + booljson_validate + stringjson + intdepth512 + intflags0 + + + Returns whether the given &string; is syntactically valid JSON. + If json_validate returns &true;, json_decode + will successfully decode the given string when using the same + depth and flags. + + + If json_validate returns &false;, the cause + can be retrieved using json_last_error and + json_last_error_msg. + + + json_validate uses less memory than + json_decode if the decoded JSON payload is + not used, because it does not need to build the array or + object structure containing the payload. + + + + Calling json_validate immediately before + json_decode will unnecessarily parse the string + twice, as json_decode implicitly performs + validation during decoding. + + + json_validate should therefore only be used + if the decode JSON payload is not immediately used and knowing whether + the string contains valid JSON is needed. + + + + + + &reftitle.parameters; + + + + json + + + The string to validate. + + + This function only works with UTF-8 encoded strings. + + &json.implementation.superset; + + + + depth + + + Maximum nesting depth of the structure being decoded. + The value must be greater than 0, + and less than or equal to 2147483647. + + + + + flags + + + Currently only + JSON_INVALID_UTF8_IGNORE + is accepted. + + + + + + + + + &reftitle.returnvalues; + + Returns &true; if the given string is syntactically valid JSON, otherwise + returns &false;. + + + + + &reftitle.errors; + + If depth is outside the allowed range, + a ValueError is thrown. + + + + + &reftitle.examples; + + + <function>json_validate</function> examples + + +]]> + + &example.outputs; + + + + + + + + + &reftitle.seealso; + + + json_decode + json_last_error + json_last_error_msg + + + + + diff --git a/reference/json/versions.xml b/reference/json/versions.xml index 061749a6b23d..1fbb43574adb 100644 --- a/reference/json/versions.xml +++ b/reference/json/versions.xml @@ -6,6 +6,7 @@ +