quinnj / JSON3.jl

Other
214 stars 47 forks source link

Error generating types when same name appears multiple times #207

Closed sethaxen closed 2 years ago

sethaxen commented 2 years ago

When the same name appears multiple times in a JSON string with values of different structure, @generatetypes fails with an error invalid redefinition of constant. A minimal example:

using JSON3, StructTypes

json_string = """
{
    "label": {
        "type": "alert",
        "label": [
            {
                "type": "text",
                "text": {
                    "content": "Open New"
                }
            }
        ]
    }
}
"""
JSON3.@generatetypes json_string
ERROR: invalid redefinition of constant Label
Stacktrace:
 [1] top-level scope
   @ none:1
 [2] eval(m::Module, e::Any)
   @ Core ./boot.jl:373
 [3] top-level scope
   @ REPL[8]:1

I wonder if the second label should named something like Label_2 instead to prevent this case from erroring.