Skip to content

Commit 6429ada

Browse files
authored
support Arrow on 1.9+ via pkg extension (#274)
* support Arrow on 1.9+ via pkg extension * bump Julia compat to 1.9 * Revert "bump Julia compat to 1.9" This reverts commit 13dfdc9. * 1.6 compat
1 parent 0480e3f commit 6429ada

File tree

4 files changed

+78
-3
lines changed

4 files changed

+78
-3
lines changed

Project.toml

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "JSON3"
22
uuid = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
33
authors = ["Jacob Quinn <[email protected]>"]
4-
version = "1.13.2"
4+
version = "1.14.0"
55

66
[deps]
77
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
@@ -12,13 +12,22 @@ StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"
1212
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
1313

1414
[compat]
15+
ArrowTypes = "2.2"
1516
Parsers = "0.3, 1, 2"
17+
PrecompileTools = "1"
1618
StructTypes = "1.10"
1719
julia = "1.6"
18-
PrecompileTools = "1"
20+
21+
[extensions]
22+
JSON3ArrowExt = ["ArrowTypes"]
1923

2024
[extras]
25+
Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45"
26+
ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd"
2127
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2228

2329
[targets]
24-
test = ["Test"]
30+
test = ["Arrow", "Test"]
31+
32+
[weakdeps]
33+
ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd"

ext/JSON3ArrowExt.jl

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module JSON3ArrowExt
2+
3+
using JSON3
4+
using ArrowTypes
5+
6+
const JSON3_ARROW_NAME = Symbol("JuliaLang.JSON3.Object")
7+
8+
# It might looks strange to have this as a StructKind when JSON objects are
9+
# very dict-like, but the valtype is Any, which Arrow.jl really not like
10+
# and even if we add a
11+
# toarrow(d::JSON3.Object) d = Dict{String, Union{typeof.(values(d))...}
12+
# that does not seem to solve the problem.
13+
ArrowTypes.ArrowKind(::Type{<:JSON3.Object}) = ArrowTypes.StructKind()
14+
ArrowTypes.arrowname(::Type{<:JSON3.Object}) = JSON3_ARROW_NAME
15+
ArrowTypes.JuliaType(::Val{JSON3_ARROW_NAME}) = JSON3.Object
16+
17+
end # module

test/arrow.jl

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using Arrow
2+
3+
obj1 = JSON3.read("""
4+
{
5+
"int": 1,
6+
"float": 2.1
7+
}
8+
""")
9+
10+
obj2 = JSON3.read("""
11+
{
12+
"int": 1,
13+
"float": 2.1,
14+
"bool1": true,
15+
"bool2": false,
16+
"none": null,
17+
"str": "\\"hey there sailor\\"",
18+
"arr": [null, 1, "hey"],
19+
"arr2": [1.2, 3.4, 5.6]
20+
}
21+
""")
22+
23+
obj3 = JSON3.read("""
24+
{
25+
"int": 1,
26+
"float": 2.1,
27+
"bool1": true,
28+
"bool2": false,
29+
"none": null,
30+
"str": "\\"hey there sailor\\"",
31+
"obj": {
32+
"a": 1,
33+
"b": null,
34+
"c": [null, 1, "hey"],
35+
"d": [1.2, 3.4, 5.6]
36+
},
37+
"arr": [null, 1, "hey"],
38+
"arr2": [1.2, 3.4, 5.6]
39+
}
40+
""")
41+
42+
tbl = (; json=[obj1, obj2, obj3])
43+
44+
arrow = Arrow.Table(Arrow.tobuffer(tbl))
45+
@test tbl.json == arrow.json

test/runtests.jl

+4
Original file line numberDiff line numberDiff line change
@@ -1103,4 +1103,8 @@ y = Vector{UndefGuy}(undef, 2)
11031103
y[1] = x
11041104
@test JSON3.write(y) == "[{\"id\":10},null]"
11051105

1106+
@static if isdefined(Base, :get_extension)
1107+
@testset "Arrow" include("arrow.jl")
1108+
end
1109+
11061110
end # @testset "JSON3"

0 commit comments

Comments
 (0)