# JSON3 loading recursive structures

**URL:** <https://discourse.julialang.org/t/json3-loading-recursive-structures/37283>\
**Category:** Data\
**Created:** [April 9, 2020, 3:08pm UTC](https://discourse.julialang.org/t/json3-loading-recursive-structures/37283 "2020-04-09T15:08:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![racinmat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/racinmat/32/11715_2.png) [@racinmat](https://discourse.julialang.org/u/racinmat)\
**Post date:** [April 9, 2020, 3:08pm UTC](https://discourse.julialang.org/t/json3-loading-recursive-structures/37283/1 "2020-04-09T15:08:36Z")

</div>

Hi, I see that [GitHub - quinnj/JSON3.jl](https://github.com/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](https://github.com/pevnak/JsonGrinder.jl/tree/master/src/extractors).  
I want to use it, but I have recursive structures which look like this

```julia
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:

```julia
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.
