Skip to content

Commit ade3b28

Browse files
committed
Allow passing a JSON3.Object or JSON3.Array to jsontable
1 parent e63a1bb commit ade3b28

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/JSONTables.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,18 @@ struct Table{columnar, T}
1111
end
1212

1313
function jsontable(source)
14-
x = JSON3.read(source)
14+
x = !(source isa JSON3.Object || source isa JSON3.Array) ? JSON3.read(source) : source
1515
columnar = x isa JSON3.Object && first(x)[2] isa AbstractArray
1616
columnar || x isa JSON3.Array || throw(ArgumentError("input json source is not a table"))
1717
return Table{columnar, typeof(x)}(x)
1818
end
1919

20+
function jsontable(x::JSON3.Object)
21+
columnar = first(x)[2] isa AbstractArray
22+
columnar || x isa JSON3.Array || throw(ArgumentError("input json source is not a table"))
23+
return Table{columnar, typeof(x)}(x)
24+
end
25+
2026
Tables.istable(::Type{<:Table}) = true
2127

2228
# columnar source

0 commit comments

Comments
 (0)