# Read a JSON file dumped by python

**URL:** <https://discourse.julialang.org/t/read-a-json-file-dumped-by-python/56968>\
**Category:** General Usage\
**Tags:** json, dictionary\
**Created:** [March 11, 2021, 7:12pm UTC](https://discourse.julialang.org/t/read-a-json-file-dumped-by-python/56968 "2021-03-11T19:12:05Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sebastian\_Mena](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sebastian_mena/32/22819_2.png) [@Sebastian\_Mena](https://discourse.julialang.org/u/Sebastian_Mena)\
**Post date:** [March 11, 2021, 7:12pm UTC](https://discourse.julialang.org/t/read-a-json-file-dumped-by-python/56968/1 "2021-03-11T19:12:06Z")

</div>

Hi,

I save a pyhton dictionary in a JSON file (.json) and now i would like to import this dictionary in julia. Which is the best option?

I save my dictionary in pyhton as follow,

```python
a_file = open('path/dict_name.json', 'w')
json.dump(my_dict, a_file)
a_file.close()

```

Thanks.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [March 11, 2021, 7:13pm UTC](https://discourse.julialang.org/t/read-a-json-file-dumped-by-python/56968/2 "2021-03-11T19:13:19Z")

</div>

if it’s a valid json file, use `JSON3.jl` or `JSON.jl` package

---

<div class="post-metadata">

**Author:** ![Sebastian\_Mena](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sebastian_mena/32/22819_2.png) [@Sebastian\_Mena](https://discourse.julialang.org/u/Sebastian_Mena)\
**Post date:** [March 11, 2021, 7:16pm UTC](https://discourse.julialang.org/t/read-a-json-file-dumped-by-python/56968/3 "2021-03-11T19:16:56Z")

</div>

Thanks @jling, Could you help me with the import code?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [March 11, 2021, 7:19pm UTC](https://discourse.julialang.org/t/read-a-json-file-dumped-by-python/56968/4 "2021-03-11T19:19:04Z")

</div>

> **[GitHub - quinnj/JSON3.jl](https://github.com/quinnj/JSON3.jl#basic)**
>
> Contribute to quinnj/JSON3.jl development by creating an account on GitHub.

```julia
JSON3.read(read("path/dict_name.json", String))

```

---

<div class="post-metadata">

**Author:** ![Sebastian\_Mena](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sebastian_mena/32/22819_2.png) [@Sebastian\_Mena](https://discourse.julialang.org/u/Sebastian_Mena)\
**Post date:** [March 11, 2021, 7:36pm UTC](https://discourse.julialang.org/t/read-a-json-file-dumped-by-python/56968/5 "2021-03-11T19:36:19Z")

</div>

> [@jling](#):
>
> `JSON3.read(read("path/dict_name.json", String))`

It didn’t work for me, I installed the “JSON” package and then imported my file like this:

```julia
dict_name = JSON.read(read("path/dict_name.json", String))

```

but, throw this error:

```julia
SystemError: opening file "": No such file or directory

```

Then, i tried installing “JSON3” package, but threw errors:

```julia
> Pkg.add("JSON3")
Resolving package versions...
No Changes to `C:\Users\semed\.julia\environments\v1.5\Project.toml`
No Changes to `C:\Users\semed\.julia\environments\v1.5\Manifest.toml`

```

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [March 11, 2021, 7:37pm UTC](https://discourse.julialang.org/t/read-a-json-file-dumped-by-python/56968/6 "2021-03-11T19:37:42Z")

</div>

JSON3 and JSON are two different packages. I don’t see error, just no changes.

---

<div class="post-metadata">

**Author:** ![Sebastian\_Mena](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sebastian_mena/32/22819_2.png) [@Sebastian\_Mena](https://discourse.julialang.org/u/Sebastian_Mena)\
**Post date:** [March 11, 2021, 7:42pm UTC](https://discourse.julialang.org/t/read-a-json-file-dumped-by-python/56968/7 "2021-03-11T19:42:40Z")

</div>

I know, but when i run, throw this:

```julia
> using JSON3

 Info: Precompiling JSON3 [0f8b85d8-7281-11e9-16c2-39a750bddbf1]
└ @ Base loading.jl:1278
WARNING: could not import StructTypes.OrderedStruct into JSON3
ERROR: LoadError: LoadError: UndefVarError: OrderedStruct not defined
Stacktrace:
 [1] top-level scope at C:\Users\semed\.julia\packages\JSON3\IvnMR\src\structs.jl:591
 [2] include(::Function, ::Module, ::String) at .\Base.jl:380
 [3] include at .\Base.jl:368 [inlined]
 [4] include(::String) at C:\Users\semed\.julia\packages\JSON3\IvnMR\src\JSON3.jl:1
 [5] top-level scope at C:\Users\semed\.julia\packages\JSON3\IvnMR\src\JSON3.jl:163
 [6] include(::Function, ::Module, ::String) at .\Base.jl:380
 [7] include(::Module, ::String) at .\Base.jl:368
 [8] top-level scope at none:2
 [9] eval at .\boot.jl:331 [inlined]
 [10] eval(::Expr) at .\client.jl:467
 [11] top-level scope at .\none:3
in expression starting at C:\Users\semed\.julia\packages\JSON3\IvnMR\src\structs.jl:591
in expression starting at C:\Users\semed\.julia\packages\JSON3\IvnMR\src\JSON3.jl:163

Failed to precompile JSON3 [0f8b85d8-7281-11e9-16c2-39a750bddbf1] to C:\Users\semed\.julia\compiled\v1.5\JSON3\1p699_kXwKq.ji.

```

And, if i ried with “JSON” package (that I could install and use), throw this error:

```julia
SystemError: opening file "": No such file or directory

```

And, i have the file in this directory.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [March 11, 2021, 7:53pm UTC](https://discourse.julialang.org/t/read-a-json-file-dumped-by-python/56968/8 "2021-03-11T19:53:26Z")

</div>

what version of JSON3 is this?

---

<div class="post-metadata">

**Author:** ![Sebastian\_Mena](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sebastian_mena/32/22819_2.png) [@Sebastian\_Mena](https://discourse.julialang.org/u/Sebastian_Mena)\
**Post date:** [March 11, 2021, 8:05pm UTC](https://discourse.julialang.org/t/read-a-json-file-dumped-by-python/56968/9 "2021-03-11T20:05:32Z")

</div>

```julia
JSON -> JSON v0.21.1
JSON3 -> JSON3 v1.7.2

```

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [March 11, 2021, 11:35pm UTC](https://discourse.julialang.org/t/read-a-json-file-dumped-by-python/56968/10 "2021-03-11T23:35:56Z")

</div>

the precompile leading to error looks weird, maybe your environment is messed up somehow.

[https://github.com/quinnj/JSON3.jl/issues/126](https://github.com/quinnj/JSON3.jl/issues/126)

seems related
