How to create a dictionary of dictionaries from an n-dimensional array?

Thanks for your help!

I need to create a nested JSON file and the first step is to create a dictionary of dictionaries. The below should provide a minimum working example.


#Sample of desired keys and categories randomly generated
investmentkeys = string.(zeros(110))
yearkeys = string.(collect(1:12))
valuekeys = string.(zeros(13))

for i in 1:length(investmentkeys)
    investmentkeys[i] = randstring(5)

for i in 1:length(valuekeys)
    valuekeys[i] = randstring(3)

#Generating sample data
data = rand(length(investmentkeys), length(yearkeys), 

#Create the first level dictionary
dictdata = Dict(agekeys[i] => data[i,:,:] for i=1:length(investmentkeys)
Dict{String, Matrix{Float64}}

The highest level of the dictionary should be the 110 investment names; each contain a 12x13 matrix.
I’d like to then use the yearkeys to split each matrix into a subset dictionary, which contrains a vector of values. I think the result would be:

Dict{String, Dict(String, Vector{Float64}}

How can I create a dictionary of dictionaries with a for loop?

Thank you!

JSON is a pretty terrible format for multidimensional arrays, in my opinion — something like HDF5 (or VTK or NetCDF) would be much better because it can directly represent multidimensional arrays (rather than nested lists of lists etc.). However, I don’t know anything about PowerBI or what formats it supports.

1 Like

If you can post a small example of what your input data looks like and then an example of what the desired output is, it’s more likely that someone will be able to help. I use Julia to write JSON objects fairly regularly but it’s easiest to just see what your data looks like and what the JSON object should look like rather than describing it.

1 Like

Hey @mthelm85, I think I’ve edited the post to include something resembling a minimum working example; thanks for your help and let me know if there’s anything else I can clarify!

Thanks for the suggestion! I’ve Googled around and it looks like PowerBI doesn’t support those formats, unfortunately. I might be wrong though!