# JSON to Array of DataFrames

**URL:** <https://discourse.julialang.org/t/json-to-array-of-dataframes/31391>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 22, 2019, 3:08pm UTC](https://discourse.julialang.org/t/json-to-array-of-dataframes/31391 "2019-11-22T15:08:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [November 22, 2019, 3:08pm UTC](https://discourse.julialang.org/t/json-to-array-of-dataframes/31391/1 "2019-11-22T15:08:16Z")

</div>

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:

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

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

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [November 22, 2019, 4:43pm UTC](https://discourse.julialang.org/t/json-to-array-of-dataframes/31391/2 "2019-11-22T16:43:56Z")

</div>

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, ...)`.

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [November 22, 2019, 6:00pm UTC](https://discourse.julialang.org/t/json-to-array-of-dataframes/31391/3 "2019-11-22T18:00:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [November 22, 2019, 7:17pm UTC](https://discourse.julialang.org/t/json-to-array-of-dataframes/31391/4 "2019-11-22T19:17:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [November 22, 2019, 8:30pm UTC](https://discourse.julialang.org/t/json-to-array-of-dataframes/31391/5 "2019-11-22T20:30:03Z")

</div>

No problem. Thanks for giving it a shot.
