Function validate [src]
Alias for std.json.scanner.validate
Scan the input and check for malformed JSON.
On SyntaxError or UnexpectedEndOfInput, returns false.
Returns any errors from the allocator as-is, which is unlikely,
but can be caused by extreme nesting depth in the input.
Prototype
pub fn validate(allocator: Allocator, s: []const u8) Allocator.Error!bool
Parameters
allocator: Allocator
s: []const u8
Source
pub fn validate(allocator: Allocator, s: []const u8) Allocator.Error!bool {
var scanner = Scanner.initCompleteInput(allocator, s);
defer scanner.deinit();
while (true) {
const token = scanner.next() catch |err| switch (err) {
error.SyntaxError, error.UnexpectedEndOfInput => return false,
error.OutOfMemory => return error.OutOfMemory,
error.BufferUnderrun => unreachable,
};
if (token == .end_of_document) break;
}
return true;
}