-
Notifications
You must be signed in to change notification settings - Fork 56
Description
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)