Skip to content

Distinguishing between different null types #143

@kskyten

Description

@kskyten

Currently, these is only one type of null in the code generator. The following code

json = """
[
    {"a": null, "b": 1},
    {"a": null, "b": null}
]
"""

JSON3.generate_exprs(JSON3.generate_type(JSON3.read(json)), mutable=false)

produces this struct

struct Root
    a::Nothing
    b::Union{Nothing, Int64}
end

This is only because the field a does not have enough samples to produce a meaningful type. On the other hand, the values in b are typical in JSON and would be nice to represent with "the software engineer's null" (JuliaLang/julia#22682). I would like the code generator to output something like

const Maybe{T} = Union{Some{T}, Nothing}

struct Root
    a::Missing
    b::Maybe{Int64}
end

or

const Maybe{T} = Union{Some{T}, Nothing}

struct Root
    a::Any
    b::Maybe{Int64}
end

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions