authorgravatar for techatrix@mailbox.orgTechatrix <techatrix@mailbox.org> 2023-07-08 05:33:47+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-07-07 23:33:47-04:00
log89396ff02ba235592641fb388e3958c2c047e728
tree69ad7fc9a7da265e1fefbed2271f81679f86e0a8
parentb9fc0d2908371dc4f7c95c03972d42e290d6e1e0
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

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


2 files changed, 23 insertions(+), 0 deletions(-)

lib/std/json/dynamic.zig+6
......@@ -147,6 +147,12 @@ pub const Value = union(enum) {
147147 }
148148 }
149149 }
150
151 pub fn jsonParseFromValue(allocator: Allocator, source: Value, options: ParseOptions) !@This() {
152 _ = allocator;
153 _ = options;
154 return source;
155 }
150156};
151157
152158fn handleCompleteValue(stack: *Array, allocator: Allocator, source: anytype, value_: Value) !?Value {
lib/std/json/dynamic_test.zig+17
......@@ -245,6 +245,23 @@ test "Value.jsonStringify" {
245245 }
246246}
247247
248test "parseFromValue(std.json.Value,...)" {
249 const str =
250 \\{
251 \\ "int": 32,
252 \\ "float": 3.2,
253 \\ "str": "str",
254 \\ "array": [3, 2],
255 \\ "object": {}
256 \\}
257 ;
258
259 const parsed_tree = try parseFromSlice(Value, testing.allocator, str, .{});
260 defer parsed_tree.deinit();
261 const tree = try parseFromValueLeaky(Value, parsed_tree.arena.allocator(), parsed_tree.value, .{});
262 try testing.expect(std.meta.eql(parsed_tree.value, tree));
263}
264
248265test "polymorphic parsing" {
249266 if (true) return error.SkipZigTest; // See https://github.com/ziglang/zig/issues/16108
250267 const doc =