# JSON write and read back Arrays

**URL:** <https://discourse.julialang.org/t/json-write-and-read-back-arrays/43283>\
**Category:** General Usage\
**Tags:** json\
**Created:** [July 18, 2020, 11:11am UTC](https://discourse.julialang.org/t/json-write-and-read-back-arrays/43283 "2020-07-18T11:11:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sz1992](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sz1992/32/19219_2.png) [@sz1992](https://discourse.julialang.org/u/sz1992)\
**Post date:** [July 18, 2020, 11:11am UTC](https://discourse.julialang.org/t/json-write-and-read-back-arrays/43283/1 "2020-07-18T11:11:59Z")

</div>

I would like to write some multi-D Array into JSON and parse it back.  
I tried using JSON.jl :

> julia\> using JSON
> 
> julia\> ar=rand(2,2,2)  
> 2×2×2 Array{Float64,3}:  
> [:, :, 1] =  
> 0.238296 0.813746  
> 0.156503 0.953343
> 
> [:, :, 2] =  
> 0.518232 0.185695  
> 0.644104 0.820459
> 
> julia\> ar\_json=JSON.json(ar)  
> “[[[0.23829646658262904,0.15650270743089711],[0.8137457610137939,0.9533428752270887]],[[0.5182318303002098,0.6441044583930384],[0.18569459908985997,0.8204588699553217]]]”
> 
> julia\> ar\_decode=JSON.parse(ar\_json)  
> 2-element Array{Any,1}:  
> Any[Any[0.23829646658262904, 0.15650270743089711], Any[0.8137457610137939, 0.9533428752270887]]  
> Any[Any[0.5182318303002098, 0.6441044583930384], Any[0.18569459908985997, 0.8204588699553217]]

As you can see decoded variable **ar\_decode** is not of the some data type as my source variable **ar**.  
What am I missing?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 18, 2020, 12:35pm UTC](https://discourse.julialang.org/t/json-write-and-read-back-arrays/43283/2 "2020-07-18T12:35:12Z")

</div>

JSON does not have matrices, only vectors, so your data was represented as vectors of vectors. Also, you may want to change the element type when read. For this particular library, see

[https://github.com/JuliaIO/JSON.jl#serialization](https://github.com/JuliaIO/JSON.jl#serialization)

but note that other JSON libraries in Julia may have different ways of approaching this problem, so you could consider exploring those too.

---

<div class="post-metadata">

**Author:** ![sz1992](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sz1992/32/19219_2.png) [@sz1992](https://discourse.julialang.org/u/sz1992)\
**Post date:** [July 18, 2020, 12:38pm UTC](https://discourse.julialang.org/t/json-write-and-read-back-arrays/43283/3 "2020-07-18T12:38:21Z")

</div>

After some additional discovering. Using Unmarshaling.jl to map decoded JSON to predefined Julia structure does the trick.
