From 99895c7b2e968040ff7d5057ec2cb402ed5c4662 Mon Sep 17 00:00:00 2001 From: Jacob Quinn Date: Thu, 16 Oct 2025 18:05:03 -0600 Subject: [PATCH] Restore pre-1.0 compat for object Tuple keys --- src/write.jl | 3 +++ test/json.jl | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/write.jl b/src/write.jl index 7a5c9c1..775ab49 100644 --- a/src/write.jl +++ b/src/write.jl @@ -16,6 +16,9 @@ StructUtils.lower(::JSONStyle, x::AbstractArray{<:Any,0}) = x[1] StructUtils.lower(::JSONStyle, x::AbstractArray{<:Any, N}) where {N} = (view(x, ntuple(_ -> :, N - 1)..., j) for j in axes(x, N)) StructUtils.lower(::JSONStyle, x::AbstractVector) = x +# for pre-1.0 compat, which serialized Tuple object keys by default +StructUtils.lowerkey(::JSONStyle, x::Tuple) = string(x) + """ JSON.omit_null(::Type{T})::Bool JSON.omit_null(::JSONStyle, ::Type{T})::Bool diff --git a/test/json.jl b/test/json.jl index 2564ff8..4af4b64 100644 --- a/test/json.jl +++ b/test/json.jl @@ -588,6 +588,10 @@ end @test result == expected end end + + @testset "Test pre-1.0 compat for object Tuple keys" begin + @test JSON.json(Dict(("a", "b") => 1)) == "{\"(\\\"a\\\", \\\"b\\\")\":1}" + end end end # @testset "JSON.json"