diff --git a/Project.toml b/Project.toml index 94d93d2..1462d62 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "JSON3" uuid = "0f8b85d8-7281-11e9-16c2-39a750bddbf1" authors = ["Jacob Quinn "] -version = "1.13.2" +version = "1.14.0" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" @@ -12,13 +12,22 @@ StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4" UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [compat] +ArrowTypes = "2.2" Parsers = "0.3, 1, 2" +PrecompileTools = "1" StructTypes = "1.10" julia = "1.6" -PrecompileTools = "1" + +[extensions] +JSON3ArrowExt = ["ArrowTypes"] [extras] +Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45" +ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test"] +test = ["Arrow", "Test"] + +[weakdeps] +ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd" diff --git a/ext/JSON3ArrowExt.jl b/ext/JSON3ArrowExt.jl new file mode 100644 index 0000000..d2c0b88 --- /dev/null +++ b/ext/JSON3ArrowExt.jl @@ -0,0 +1,17 @@ +module JSON3ArrowExt + +using JSON3 +using ArrowTypes + +const JSON3_ARROW_NAME = Symbol("JuliaLang.JSON3.Object") + +# It might looks strange to have this as a StructKind when JSON objects are +# very dict-like, but the valtype is Any, which Arrow.jl really not like +# and even if we add a +# toarrow(d::JSON3.Object) d = Dict{String, Union{typeof.(values(d))...} +# that does not seem to solve the problem. +ArrowTypes.ArrowKind(::Type{<:JSON3.Object}) = ArrowTypes.StructKind() +ArrowTypes.arrowname(::Type{<:JSON3.Object}) = JSON3_ARROW_NAME +ArrowTypes.JuliaType(::Val{JSON3_ARROW_NAME}) = JSON3.Object + +end # module diff --git a/test/arrow.jl b/test/arrow.jl new file mode 100644 index 0000000..c9f0bf5 --- /dev/null +++ b/test/arrow.jl @@ -0,0 +1,45 @@ +using Arrow + +obj1 = JSON3.read(""" +{ + "int": 1, + "float": 2.1 +} +""") + +obj2 = JSON3.read(""" +{ + "int": 1, + "float": 2.1, + "bool1": true, + "bool2": false, + "none": null, + "str": "\\"hey there sailor\\"", + "arr": [null, 1, "hey"], + "arr2": [1.2, 3.4, 5.6] +} +""") + +obj3 = JSON3.read(""" +{ + "int": 1, + "float": 2.1, + "bool1": true, + "bool2": false, + "none": null, + "str": "\\"hey there sailor\\"", + "obj": { + "a": 1, + "b": null, + "c": [null, 1, "hey"], + "d": [1.2, 3.4, 5.6] + }, + "arr": [null, 1, "hey"], + "arr2": [1.2, 3.4, 5.6] +} +""") + +tbl = (; json=[obj1, obj2, obj3]) + +arrow = Arrow.Table(Arrow.tobuffer(tbl)) +@test tbl.json == arrow.json diff --git a/test/runtests.jl b/test/runtests.jl index 511a14b..8f7b0b1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1103,4 +1103,8 @@ y = Vector{UndefGuy}(undef, 2) y[1] = x @test JSON3.write(y) == "[{\"id\":10},null]" +@static if isdefined(Base, :get_extension) + @testset "Arrow" include("arrow.jl") +end + end # @testset "JSON3"