Skip to content

JSON3.Object and Symbol keys #62

@DatName

Description

@DatName

I think there is a bit of inconsistency in how JSONSchema handles Symbol keys:

my_schema = Schema(
    Dict(
        "properties" => Dict(
            "foo" => Dict(),
            "bar" => Dict()
        ),
        "required" => ["foo"]
    )
)

# works as expected
data = Dict{String, Any}("foo" => 1)
isvalid(my_schema, data) # true

# works despite having Symbol keys
data_json3 = JSON3.read("""{"foo": 1}""")
isvalid(my_schema, data_json3) # true

# fails unexpectedly
data_symbol = Dict{Symbol, Any}(:foo => 1)
isvalid(my_schema, data_symbol) # false, type of keys do not match (String vs Symbol).

data_json3 has Symbol keys, but passes validation because JSONSchema automatically converts it to Dict with String keys.

However, from a user's perspective, data_symbol and data_json3 are semantically equivalent - both represent the same data structure and can be used interchangeably. One would reasonably expect both of them two work, I guess.

My particular issue is that it's way more convenient (and still correct for my use case) to create a Dict with Symbols instead of a JSON3.Object. I would need to repeat _to_base_julia() in my code. Which is not a big deal, but still.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions