isValidJSON

fnbool isValidJSON(const(char)[] input, out JsonError err, JsonPolicy policy = JsonPolicy.init) @safe

Validate JSON text without building a value tree.

This function performs lexer-based validation of JSON syntax, checking for:

  • Valid tokens (strings, numbers, keywords, punctuators)
  • Proper structure (matching braces/brackets, correct comma placement)
  • No trailing content after the root value

This is faster than full parsing when you only need to verify syntax.

Parameters

inputJSON text to validate.
errOutput parameter for error information on failure.
policyPolicy controlling validation behavior (only maxDepth is used).

Returns

true if the input is valid JSON; false with err populated otherwise.

Examples

import ddn.data.json : isValidJSON, JsonError;

JsonError err;
assert(isValidJSON(`{"a":1,"b":[2,3]}`, err));
assert(!isValidJSON(`{invalid}`, err));
fnbool isValidJSON(const(char)[] input) @safe

Convenience overload that validates JSON without returning error details.

Parameters

inputJSON text to validate.

Returns

true if the input is valid JSON; false otherwise.