#Json stringify bug with invalid values

1 messages · Page 1 of 1 (latest)

icy relic
#

I expect the following code to throw a json parsing error:

const std = @import("std");

test {
    const foo = .{
        .a = std.math.inf(f32),
    };
    const str = try std.json.stringifyAlloc(std.testing.allocator, foo, .{});
    defer std.testing.allocator.free(str);
    std.log.warn("{s}", .{str});
}

The output:
{"a":inf}

Which is not valid json - inf is not a keyword valid in json. Is this just a bug in the std library, or is there another way to represent infinite values?

median mesa
#

tho whether it's in std or in your code depends on what guarantees std.json provides

#

it may require you to provide valid data

icy relic
#

I'd hope the api would return an error if the data I passed was invalid, I'll open an issue on GitHub

median mesa
#

sure, worth asking at least :)

lilac kite
#

seems like a good error to have (we could also offer a json5 mode which does allow encoding infinity, and error if you pass inf while not in that mode)