quinnj / JSON3.jl

Other
214 stars 47 forks source link

Bad handling of large amounts of fields #291

Open stensmo opened 1 month ago

stensmo commented 1 month ago

using JSON3

=

Note that the fields d8 and d9 are swapped, which is OK according to the JSON specification. This example errors. ERROR: LoadError: MethodError: Cannot convert an object of type String to an object of type Int64 The function convert exists, but no method is defined for this combination of argument types.

{ "objects": [ { "a1": 1, "a2": 2, "a3": 3, "a4": 4, "a5": 5, "a6": 6, "a7": 7, "a8": 8, "a9": 9, "b1": 11, "b2": 12, "b3": 13, "b4": 14, "b5": 15, "b6": 16, "b7": 17, "b8": 18, "b9": 19, "c1": 21, "c2": 22, "c3": 23, "c4": 24, "c5": 25, "c6": 26, "c7": 27, "c8": 28, "c9": 29, "d1": 31, "d2": 32, "d3": 33, "d4": 34, "d5": 35, "d6": 36, "d7": 37, "d8": 38, "d9": "39" }, { "a1": 1, "a2": 2, "a3": 3, "a4": 4, "a5": 5, "a6": 6, "a7": 7, "a8": 8, "a9": 9, "b1": 11, "b2": 12, "b3": 13, "b4": 14, "b5": 15, "b6": 16, "b7": 17, "b8": 18, "b9": 19, "c1": 21, "c2": 22, "c3": 23, "c4": 24, "c5": 25, "c6": 26, "c7": 27, "c8": 28, "c9": 29, "d1": 31, "d2": 32, "d3": 33, "d4": 34, "d5": 35, "d6": 36, "d7": 37, "d9": "39", "d8": 38 } ] }

=#

json_string="""{"objects":[{"a1":1,"a2":2,"a3":3,"a4":4,"a5":5,"a6":6,"a7":7,"a8":8,"a9":9,"b1":11,"b2":12,"b3":13,"b4":14,"b5":15,"b6":16,"b7":17,"b8":18,"b9":19,"c1":21,"c2":22,"c3":23,"c4":24,"c5":25,"c6":26,"c7":27,"c8":28,"c9":29,"d1":31,"d2":32,"d3":33,"d4":34,"d5":35,"d6":36,"d7":37,"d8":38,"d9":"39"},{"a1":1,"a2":2,"a3":3,"a4":4,"a5":5,"a6":6,"a7":7,"a8":8,"a9":9,"b1":11,"b2":12,"b3":13,"b4":14,"b5":15,"b6":16,"b7":17,"b8":18,"b9":19,"c1":21,"c2":22,"c3":23,"c4":24,"c5":25,"c6":26,"c7":27,"c8":28,"c9":29,"d1":31,"d2":32,"d3":33,"d4":34,"d5":35,"d6":36,"d7":37,"d9":"39","d8":38}]}"""

!isfile("types.jl") && JSON3.writetypes(json_string, "types.jl"; module_name=:MyModule, root_name=:Root, mutable=false)

!isdefined(Main, :MyModule) && include("types.jl")

rootObject =JSON3.read(json_string, MyModule.Root)

Naunet commented 1 day ago

Hi stensmo, I ran into exactly this problem a couple of months back and have proposed a PR: https://github.com/quinnj/JSON3.jl/pull/284

Naunet commented 4 hours ago

Try bumping to the latest version 1.14.1 and this behaviour should be fixed.