Skip to content

Commit 8f53dc0

Browse files
0x005cTotalVerb
authored andcommitted
Fix show_json to serialize empty NamedTuple
1 parent 5054414 commit 8f53dc0

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/Writer.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ CompositeTypeWrapper(x) = CompositeTypeWrapper(x, propertynames(x))
2626
lower(x)
2727
2828
Return a value of a JSON-encodable primitive type that `x` should be lowered
29-
into before encoding as JSON. Supported types are: `AbstractDict` to JSON
30-
objects, `Tuple` and `AbstractVector` to JSON arrays, `AbstractArray` to nested
31-
JSON arrays, `AbstractString`, `Symbol`, `Enum`, or `Char` to JSON string,
29+
into before encoding as JSON. Supported types are: `AbstractDict` and `NamedTuple`
30+
to JSON objects, `Tuple` and `AbstractVector` to JSON arrays, `AbstractArray` to
31+
nested JSON arrays, `AbstractString`, `Symbol`, `Enum`, or `Char` to JSON string,
3232
`Integer` and `AbstractFloat` to JSON number, `Bool` to JSON boolean, and
3333
`Nothing` to JSON null, or any other types with a `show_json` method defined.
3434
@@ -265,9 +265,9 @@ end
265265
show_json(io::SC, ::CS, ::Nothing) = show_null(io)
266266
show_json(io::SC, ::CS, ::Missing) = show_null(io)
267267

268-
function show_json(io::SC, s::CS, a::AbstractDict)
268+
function show_json(io::SC, s::CS, x::Union{AbstractDict, NamedTuple})
269269
begin_object(io)
270-
for kv in a
270+
for kv in pairs(x)
271271
show_pair(io, s, kv)
272272
end
273273
end_object(io)

0 commit comments

Comments
 (0)