add jsonParseFromValue to std.json.Value (#16324)

This commit is contained in:
Techatrix 2023-07-08 05:33:47 +02:00 committed by GitHub
parent b9fc0d2908
commit 89396ff02b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View File

@ -147,6 +147,12 @@ pub const Value = union(enum) {
}
}
}
pub fn jsonParseFromValue(allocator: Allocator, source: Value, options: ParseOptions) !@This() {
_ = allocator;
_ = options;
return source;
}
};
fn handleCompleteValue(stack: *Array, allocator: Allocator, source: anytype, value_: Value) !?Value {

View File

@ -245,6 +245,23 @@ test "Value.jsonStringify" {
}
}
test "parseFromValue(std.json.Value,...)" {
const str =
\\{
\\ "int": 32,
\\ "float": 3.2,
\\ "str": "str",
\\ "array": [3, 2],
\\ "object": {}
\\}
;
const parsed_tree = try parseFromSlice(Value, testing.allocator, str, .{});
defer parsed_tree.deinit();
const tree = try parseFromValueLeaky(Value, parsed_tree.arena.allocator(), parsed_tree.value, .{});
try testing.expect(std.meta.eql(parsed_tree.value, tree));
}
test "polymorphic parsing" {
if (true) return error.SkipZigTest; // See https://github.com/ziglang/zig/issues/16108
const doc =