zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 89396ff02ba235592641fb388e3958c2c047e728 (tree)
parent b9fc0d2908371dc4f7c95c03972d42e290d6e1e0
Author: Techatrix <19954306+Techatrix@users.noreply.github.com>
Date:   Sat,  8 Jul 2023 05:33:47 +0200

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


Diffstat:
Mlib/std/json/dynamic.zig | 6++++++
Mlib/std/json/dynamic_test.zig | 17+++++++++++++++++
2 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/lib/std/json/dynamic.zig b/lib/std/json/dynamic.zig @@ -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 { diff --git a/lib/std/json/dynamic_test.zig b/lib/std/json/dynamic_test.zig @@ -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 =