Reading a nested JSON file into a predefined type with JSON3

Lets say with have this JSON file :

{
    "A": "String",
    "B": [
        {
            "B1": "String",
            "B2": "String",
        },
        {
            "B1": "String",
            "B2": "String",
        },
        {
            "B1": "String",
            "B2": "String",
        }
    ]
}

The B key has a nested list of sub keys. The problem I’m running into is I can’t make a predefined type to read the whole thing into it and return (as in this case) 3 entries. The nested files I define like this:

struct nested
B1::String
B2::String
end

I ran into problem defining the whole thing in the next step.

Struct Json
A::String
B:: ?
end

JSON3.jl documentation uses a StructTypes.CustomStruct to wrap different structs but I can’t get it to work. How should I define the ‘B’ parameter in the Struct Json? (The goal of the whole thing is to reduce allocation of JSON3.read)

Looks like B::Vector{nested}, although I would capitalize it to Nested

2 Likes

Thanks for the reply. That was much simpler than I thought.

Interestingly, Im seeing performance regression. Imma post in performance section to find out why.