# Bug on JSON3 serialization?

**URL:** https://discourse.julialang.org/t/bug-on-json3-serialization/128193
**Category:** General Usage
**Created:** [April 18, 2025, 9:21pm UTC](https://discourse.julialang.org/t/bug-on-json3-serialization/128193 "2025-04-18T21:21:58Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![freeman](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@freeman](https://discourse.julialang.org/u/freeman)
#### Post date: [April 18, 2025, 9:21pm UTC](https://discourse.julialang.org/t/bug-on-json3-serialization/128193/1 "2025-04-18T21:21:58Z")

</div>

Could someone clarify whether this is a bug or I’m doing something wrong?

```julia
import JSON3
d = Dict{Tuple{Int,String},Float64}()
d[(10,"a")] = 1.
d[(20,"b")] = 2.
JSON3.write("/tmp/temp.json", d)
JSON3.read("/tmp/temp.json", Dict{Tuple{Int,String},Float64})

```

The last line throws

```julia
ERROR: MethodError: Cannot `convert` an object of type Char to an object of type String
The function `convert` exists, but no method is defined for this combination of argument types.

```

That object is serialized in the following way:

```julia
{"(10, \"a\")":1.0,"(20, \"b\")":2.0}

```

What’s happening is that JSON3 sees the key `"(10, \"a\")"` and tries pass it to the dictionary key type:

```julia
Tuple{Int,String}("(10, \"a\")") # ERROR: MethodError: Cannot `convert` an object of type Char to an object of type String

```

@quinnj

---

<div class="post-metadata">

### Author: ![freeman](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@freeman](https://discourse.julialang.org/u/freeman)
#### Post date: [April 18, 2025, 9:25pm UTC](https://discourse.julialang.org/t/bug-on-json3-serialization/128193/2 "2025-04-18T21:25:08Z")

</div>

Ok as soon as I posted this I’ve found that this is known and someone posted a workaround using wrappers.

> <https://github.com/quinnj/JSON3.jl/issues/297>
>
> A dictionary that takes dictionaries as keys (very stupid, I know, but it's a qu…ick-and-dirty solution I'm testing), results in improper serialization when writing to file:
> "(Dict{String, BigFloat}("lat" =\> \<int omitted\>, "lon" =\> \<int omitted\>), Dict{String, BigFloat}("lat" =\> \<int omitted\>, "lon" =\> \<int omitted\>))"
>  
> Where "lat" and "lon" are originally strings.

---

<div class="post-metadata">

### Author: ![quinnj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quinnj/32/11_2.png) [@quinnj](https://discourse.julialang.org/u/quinnj)
#### Post date: [April 18, 2025, 10:08pm UTC](https://discourse.julialang.org/t/bug-on-json3-serialization/128193/3 "2025-04-18T22:08:31Z")

</div>

Yeah, non-string keys were never officially supported or thought about, so no official work-around or support currently.

---

<div class="post-metadata">

### Author: ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)
#### Post date: [April 18, 2025, 10:38pm UTC](https://discourse.julialang.org/t/bug-on-json3-serialization/128193/4 "2025-04-18T22:38:26Z")

</div>

I think that should probably error on `write` rather than on `read`, though, since it shouldn’t be able to do that.
