Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

JSON.json writes an empty `Vector{Union{}}` as `{}` instead of `[]`

Open Beginner friendly
#499 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@krynju is already working on this.

Since Oct 7, 2026.

  • #500 by @krynju — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
julia
Domain
backend

Research direction

Read the arraylike method in src/write.jl and find the tests for JSON serialization of vectors. Check how empty Vector{Union{}} values are classified, then verify they serialize as [] and nested empty vectors as [[]] while vectors of Pairs still serialize as objects.

Written by the indexing model from the issue text.

Description

An empty vector whose element type is Union{} is written as a JSON object instead of an array:

julia> using JSON  # v1.10.0

julia> JSON.json(Union{}[])
"{}"

julia> JSON.json([Union{}[]])
"[{}]"

julia> JSON.json(Any[])   # for comparison
"[]"

Expected: "[]" and "[[]]".

In practice this shows up when serializing values parsed by JSON3.jl, which types every empty array as JSON3.Array{Union{}, …}, so a JSON3 → JSON.jl round trip turns empty arrays into objects:

julia> using JSON3

julia> JSON.json(JSON3.read("""{"a":[],"b":[[]],"c":[1]}"""))
"{\"a\":{},\"b\":[{}],\"c\":[1]}"

JSON 0.21.4 writes [] in all of these cases. I see the new behaviour on 1.8.0, 1.9.0 and 1.10.0 (Julia 1.13.1).

Cause

src/write.jl writes vectors of Pairs as objects:

StructUtils.arraylike(::JSONStyle, x::AbstractVector{<:Pair}) = false

Union{} is a subtype of every type, so Vector{Union{}} <: AbstractVector{<:Pair} is true, and empty Union{}-element vectors dispatch to this method:

julia> Vector{Union{}} <: AbstractVector{<:Pair}
true

julia> which(JSON.StructUtils.arraylike, (JSON.JSONWriteStyle, Vector{Union{}}))
arraylike(::JSON.JSONStyle, x::AbstractVector{<:Pair}) @ JSON src/write.jl:140
Possible fix

A more specific method restores array output and leaves the Pair behaviour alone:

StructUtils.arraylike(::JSONStyle, ::AbstractVector{Union{}}) = true

With that defined:

julia> JSON.json(Union{}[]), JSON.json([Union{}[]]), JSON.json([:a => 1])
("[]", "[[]]", "{\"a\":1}")
Dominant language
Julia
Stars
359
Forks
116
Avg merge
1d 8h
Merged PRs (30d)
11

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from JuliaIO/JSON.jl

All issues in JuliaIO/JSON.jl

Similar issues

More Julia issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.