Hi, I see that GitHub - quinnj/JSON3.jl can be used for writing and reading data to custom structures, specifically from this package https://github.com/pevnak/JsonGrinder.jl/tree/master/src/extractors.
I want to use it, but I have recursive structures which look like this
Dict
├── a: Array of
│ └── Dict
│ ├── a: Array of
│ │ └── Float64
│ └── b: Array of
│ └── Float64
└── b: Float64
with type looking like ExtractDict{Nothing,Dict{String,JsonGrinder.AbstractExtractor}}
I tried to add support for those types, but it needs to know the type, which is not known in advance, and is inferred from data, so using this:
using JsonGrinder
j1 = JSON.parse("""{"a": "1", "b": [1, 2, 3], "c": [1, 2, 3]}""")
j2 = JSON.parse("""{"a": "2", "b": [2, 2, 3], "c": [1, 2, 3, 4]}""")
j3 = JSON.parse("""{"a": "3", "b": [3, 2, 3], "c": [1, 2, 3, 4, 5]}""")
j4 = JSON.parse("""{"a": "4", "b": [2, 3, 4], "c": [1, 2, 3]}""")
sch = JsonGrinder.schema([j1, j2, j3, j4])
ext = suggestextractor(sch)
using StructTypes
using JSON3
StructTypes.StructType(::Type{<:ExtractArray}) = StructTypes.Struct()
StructTypes.StructType(::Type{<:ExtractCategorical}) = StructTypes.Struct()
StructTypes.StructType(::Type{<:ExtractDict}) = StructTypes.Struct()
StructTypes.StructType(::Type{<:ExtractOneHot}) = StructTypes.Struct()
StructTypes.StructType(::Type{<:ExtractScalar}) = StructTypes.Struct()
StructTypes.StructType(::Type{<:ExtractString}) = StructTypes.Struct()
StructTypes.StructType(::Type{<:ExtractVector}) = StructTypes.Struct()
StructTypes.StructType(::Type{<:MultipleRepresentation}) = StructTypes.Struct()
ext_json = JSON3.write(ext)
ext2 = JSON3.read(ext_json, ExtractDict)
but ext2 is not same as ext, and I don’t know how to properly add support for recursive structures like this.
Is there anything documented?
These extractors are immutable, but I didn’t find anywhere in JSON3 doc how to handle such cases.
Thanks.