From 94266582b71d0bc7f1fd9dfe9b01e4f6fe389a06 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Thu, 13 May 2021 09:03:00 -0700 Subject: [PATCH] allow unknown struct fields --- src/json.zig | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/json.zig b/src/json.zig index 48b88f5..3687252 100644 --- a/src/json.zig +++ b/src/json.zig @@ -1590,6 +1590,21 @@ fn parseInternal(comptime T: type, token: Token, tokens: *TokenStream, options: } if (!found and !options.allow_unknown_fields) return error.UnknownField; }, + .ObjectBegin => { + if (!options.allow_unknown_fields) return error.UnknownField; + // At this point, we are in a struct that we do not care about. Fast forward + var objects: u64 = 1; + while (true) { + switch ((try tokens.next()) orelse return error.UnexpectedEndOfJson) { + .ObjectBegin => objects = objects + 1, + .ObjectEnd => { + objects = objects - 1; + if (objects == 0) break; + }, + else => {}, + } + } + }, else => return error.UnexpectedToken, } }