Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad handling of large amounts of fields #291

Open
stensmo opened this issue Sep 9, 2024 · 4 comments
Open

Bad handling of large amounts of fields #291

stensmo opened this issue Sep 9, 2024 · 4 comments

Comments

@stensmo
Copy link

stensmo commented Sep 9, 2024

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
Copy link
Contributor

Naunet commented Oct 16, 2024

Hi stensmo, I ran into exactly this problem a couple of months back and have proposed a PR: #284

@Naunet
Copy link
Contributor

Naunet commented Oct 17, 2024

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

@stensmo
Copy link
Author

stensmo commented Oct 17, 2024

Yes, this bug is solved now

@stensmo
Copy link
Author

stensmo commented Oct 17, 2024

This however, still does not work:

using JSON3

#=

Put this content in the file test.json

{
"objects": [
{
"a": 1,
"b": "here is a sting"
},
{
"b": "here is a string with a quote "",
"a": 1
}
]
}

=#

#json_string = """{"objects":[{"a":1,"b":"here is a sting"},{"b":"here is a string with a quote -insert backslash here-"","a":1}]}"""
json_string = read("test.json", String)

!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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants