Skip to content

JSON stringify returning invalid token inf #23253

Open
@richard-powers

Description

@richard-powers

Zig Version

0.14.0

Steps to Reproduce and Observed Behavior

Min. repro:

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}

inf is not a valid token in JSON. In my opinion, a parsing error should be thrown in cases with infinite values.

Expected Behavior

An error should be returned, instead of malformed json.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorcontributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.standard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions