Skip to content

Commit de7c551

Browse files
committed
Add parseFloat support to json.zig
1 parent c34ce68 commit de7c551

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

std/json.zig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,7 @@ pub const Parser = struct {
13451345
return if (token.number_is_integer)
13461346
Value{ .Integer = try std.fmt.parseInt(i64, token.slice(input, i), 10) }
13471347
else
1348-
@panic("TODO: fmt.parseFloat not yet implemented");
1348+
Value{ .Float = std.fmt.parseFloat(f64, token.slice(input, i)) };
13491349
}
13501350
};
13511351

@@ -1366,7 +1366,8 @@ test "json.parser.dynamic" {
13661366
\\ },
13671367
\\ "Animated" : false,
13681368
\\ "IDs": [116, 943, 234, 38793],
1369-
\\ "ArrayOfObject": [{"n": "m"}]
1369+
\\ "ArrayOfObject": [{"n": "m"}],
1370+
\\ "double": 1.3412
13701371
\\ }
13711372
\\}
13721373
;
@@ -1395,4 +1396,7 @@ test "json.parser.dynamic" {
13951396

13961397
const obj0 = array_of_object.Array.at(0).Object.get("n").?.value;
13971398
testing.expect(mem.eql(u8, obj0.String, "m"));
1399+
1400+
const double = image.Object.get("double").?.value;
1401+
testing.expect(double.Float == 1.3412);
13981402
}

0 commit comments

Comments
 (0)