JSON to Array of DataFrames

Hi all-

I am trying to store an array of DataFrames as a JSON file and read the JSON file back as the same array of DataFrames. As far as I can tell, the best approach currently is to use JSONTables. Unfortunately, I am having some trouble. Here is my attempt:

using JSON, JSONTables, DataFrames
dfs = DataFrame[]
df = DataFrame(a = ["a","b","c"], b = [.3,.4,.5], c = [1,2,3])
push!(dfs, df, df)
str = JSON.json(dfs)
jtable = jsontable(str)
new_dfs = DataFrame(jtable)

The output is

2×2 DataFrame. Omitted printing of 1 columns
│ Row │ columns                                       │
│     │ JSON3…                                        │
├─────┼───────────────────────────────────────────────┤
│ 1   │ [["a", "b", "c"], [0.3, 0.4, 0.5], [1, 2, 3]] │
│ 2   │ [["a", "b", "c"], [0.3, 0.4, 0.5], [1, 2, 3]] │

I tried using JSON3 instead of JSON but had no success. How can I modify the code above to reconstruct the array of DataFrames? Thank you.

I don’t know about the JSON packages, but I you don’t want to create a DataFrame from table objects. Rather, you want to vcat them in a loop or using reduce(vcat, ...).

Thanks for your reply. Can you elaborate? I tried DataFrame(reduce(vcat, jtable)), but it produced the same result.

I added the packages and tested out your code. I think i understand what you are trying to do but I can’t figure out a way to do it either. sorry.

No problem. Thanks for giving it a shot.