pub fn validate(allocator: Allocator, s: []const u8) Allocator.Error!bool allocator: Allocators: []const u81397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411pub 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 => |e| return e,
error.BufferUnderrun => unreachable,
};
if (token == .end_of_document) break;
}
return true;
}
Scan the input and check for malformed JSON. On
SyntaxErrororUnexpectedEndOfInput, returnsfalse. Returns any errors from the allocator as-is, which is unlikely, but can be caused by extreme nesting depth in the input.