# Why does Julia not support JSON syntax to create a Dict?

**URL:** <https://discourse.julialang.org/t/why-does-julia-not-support-json-syntax-to-create-a-dict/42873>\
**Category:** Internals & Design\
**Tags:** json\
**Created:** [July 10, 2020, 9:32pm UTC](https://discourse.julialang.org/t/why-does-julia-not-support-json-syntax-to-create-a-dict/42873 "2020-07-10T21:32:04Z")\
**Posts on this page:** 1\
**Showing post:** 29

<div class="post-metadata">

**Author:** ![dodoplus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dodoplus/32/30148_2.png) [@dodoplus](https://discourse.julialang.org/u/dodoplus)\
**Post date:** [April 25, 2022, 3:27pm UTC](https://discourse.julialang.org/t/why-does-julia-not-support-json-syntax-to-create-a-dict/42873/29 "2022-04-25T15:27:55Z")

</div>

Joining late…  
I’ve asked about [this](https://discourse.julialang.org/t/json-bson-dsl/79940) separately.

This is the code I can up with. Maybe it’s of use to someone…

```julia

json(n) = n
json(n::Symbol) = esc(n)

function json(n::Expr)
    if n.head == :vect
        return Expr(:vect, map(json, n.args)...)
    elseif n.head == :braces
        kv = []
        for f in n.args
            f isa Expr || error("not a valid JSON")
            f.args[1] == :(:) || error("not a valid JSON")
            k = f.args[2]

            typeof(k) ∈ (Symbol, String) || error("not a valid JSON")
            k = string(k)
            v = json(f.args[3])
            push!(kv, :($k=>$v))
        end
        return :(Dict{String, Any}($(kv...)))
    else
        return esc(n)
    end
end

macro json(n)
    return json(n)
end

function aa()
    i = 2
    j = 3
    return @json({
                a : { # recursive...
                    b : i, # accessing local variable
                    e : nothing,
                }, "c": [1, 2.0, "mixed types"], # array
                "d": i + j # expression
            })
end

aa()
#Dict{String, Any} with 3 entries:
# "c" => Any[1, 2.0, "mixed types"]
# "a" => Dict{String, Any}("e"=>nothing, "b"=>2)
# "d" => 5

```

Thanks,  
DD

---

_[View the full topic](https://discourse.julialang.org/t/why-does-julia-not-support-json-syntax-to-create-a-dict/42873)._
