Closed DUOLabs333 closed 4 months ago
This is considered an error by the parser.
Is there a way to turn it off? I have some JSON with some extra keys I use for logging purposes, but shouldn't matter to the underlying struct, as it could change. As far as I can tell, both glaze and daw_json_link support this, but I would like to not have to add another dependency (I'm only direct parsing for some of the JSON strings).
The way to allow missing keys is to use an optional as the member's type. E.g.
struct S {
int n; // required
std::optional<std::string> s; // not required
};
If that doesn't work for you, you can write a tag_invoke
overload and convert with value_to
.
As it turns out, I can rework my system to not have any unused keys, but that could be useful if it later becomes a hard dependency. Thanks.
Let's say we have struct B. B has three attributes. Now let's say I want to parse_into a string s with 4 keys, and 3 of them are attributes of B. Will the parsing succeed?