Skip to content

Commit 9b9fd02

Browse files
authored
Replace JSON3 with JSON v1 (#19)
* Replace JSON3 with JSON v1 * Update CI
1 parent 861a07f commit 9b9fd02

5 files changed

Lines changed: 45 additions & 26 deletions

File tree

.github/dependabot.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Please see the documentation for all configuration options:
2+
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
3+
4+
version: 2
5+
enable-beta-ecosystems: true
6+
updates:
7+
- package-ecosystem: "julia" # See documentation for possible values
8+
directory: "/" # Location of package manifests
9+
schedule:
10+
interval: "weekly"
11+
- package-ecosystem: "github-actions"
12+
directory: "/"
13+
schedule:
14+
interval: "weekly"
15+
groups:
16+
actions:
17+
patterns:
18+
- "*"

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
matrix:
1717
version:
18-
- '1.0'
18+
- '1.9'
1919
- '1'
2020
- 'nightly'
2121
os:
@@ -26,13 +26,13 @@ jobs:
2626
- os: macOS-latest
2727
version: '1'
2828
steps:
29-
- uses: actions/checkout@v2
30-
- uses: julia-actions/setup-julia@v1
29+
- uses: actions/checkout@v6
30+
- uses: julia-actions/setup-julia@v2
3131
with:
3232
version: ${{ matrix.version }}
33-
- uses: julia-actions/julia-buildpkg@v1
3433
- uses: julia-actions/julia-runtest@v1
3534
- uses: julia-actions/julia-processcoverage@v1
36-
- uses: codecov/codecov-action@v1
35+
- uses: codecov/codecov-action@v5
3736
with:
3837
file: lcov.info
38+
token: ${{ secrets.CODECOV_TOKEN }}

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ uuid = "98105f81-4425-4516-93fd-1664fb551ab6"
33
version = "1.5.0"
44

55
[deps]
6-
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
6+
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
77
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
88

99
[compat]
10-
JSON3 = "1"
11-
julia = "1"
10+
JSON = "1"
11+
julia = "1.9"
1212

1313
[extras]
1414
LoggingExtras = "e6f89c97-d47a-5376-807f-9c37f3926c36"

src/LoggingFormats.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module LoggingFormats
22

3-
import Logging, JSON3
3+
import Logging
4+
import JSON as JSONLib
45

56
const STANDARD_KEYS = (:level, :msg, :module, :file, :line, :group, :id)
67

@@ -124,19 +125,19 @@ function (j::JSON)(io, args)
124125
if j.recursive
125126
logmsg = to_namedtuple(Any, args; nest_kwargs=j.nest_kwargs)
126127
try
127-
JSON3.write(io, logmsg)
128+
JSONLib.json(io, logmsg)
128129
catch e
129130
if j.nest_kwargs
130131
fallback_msg = to_namedtuple(String, args; nest_kwargs=true)
131132
fallback_msg.kwargs["LoggingFormats.FormatError"] = sprint(showerror, e)
132133
else
133134
fallback_msg = (; to_namedtuple(String, args; nest_kwargs=false)..., Symbol("LoggingFormats.FormatError") => sprint(showerror, e))
134135
end
135-
JSON3.write(io, fallback_msg)
136+
JSONLib.json(io, fallback_msg)
136137
end
137138
else
138139
logmsg = to_namedtuple(String, args; nest_kwargs=j.nest_kwargs)
139-
JSON3.write(io, logmsg)
140+
JSONLib.json(io, logmsg)
140141
end
141142
println(io)
142143
return nothing

test/runtests.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using Test: @test, @testset, @test_throws
22
using Logging: Logging, with_logger
33
using LoggingExtras: FormatLogger
44
using LoggingFormats: LoggingFormats, Truncated, JSON, LogFmt
5-
import JSON3
5+
import JSON as JSONLib
66

77
function my_throwing_function()
88
throw(ArgumentError("no"))
@@ -70,7 +70,7 @@ end
7070
@warn "warn msg"
7171
@error "error msg"
7272
end
73-
json = [JSON3.read(x) for x in eachline(seekstart(io))]
73+
json = [JSONLib.parse(x) for x in eachline(seekstart(io))]
7474
@test json[1].level == "debug"
7575
@test json[1].msg == "debug msg"
7676
@test json[2].level == "info"
@@ -90,7 +90,7 @@ end
9090
y = (1, 2)
9191
@info "info msg" x = [1, 2, 3] y
9292
end
93-
json = JSON3.read(seekstart(io))
93+
json = JSONLib.parse(seekstart(io))
9494
@test json.level == "info"
9595
@test json.msg == "info msg"
9696
@test json.module == "Main"
@@ -105,7 +105,7 @@ end
105105
y = (1, 2)
106106
@info "info msg" x = [1, 2, 3] y
107107
end
108-
json = JSON3.read(seekstart(io))
108+
json = JSONLib.parse(seekstart(io))
109109
@test json.level == "info"
110110
@test json.msg == "info msg"
111111
@test json.module == "Main"
@@ -120,7 +120,7 @@ end
120120
with_logger(FormatLogger(JSON(; nest_kwargs=false), io)) do
121121
@info "info msg" line = [1, 2, 3]
122122
end
123-
json = JSON3.read(seekstart(io))
123+
json = JSONLib.parse(seekstart(io))
124124
@test json.level == "info"
125125
@test json.msg == "info msg"
126126
@test json.module == "Main"
@@ -133,32 +133,32 @@ end
133133
with_logger(FormatLogger(JSON(; recursive=true), io)) do
134134
@info "info msg" x = [1, 2, 3] y = Dict("hi" => Dict("hi2" => [1,2]))
135135
end
136-
json = JSON3.read(seekstart(io))
136+
json = JSONLib.parse(seekstart(io))
137137
@test json.level == "info"
138138
@test json.msg == "info msg"
139139
@test json.module == "Main"
140140
@test json.line isa Int
141141
@test json.kwargs.x == [1, 2, 3]
142-
@test json.kwargs.y == Dict(:hi => Dict(:hi2 => [1,2]))
142+
@test json.kwargs.y == Dict("hi" => Dict("hi2" => [1,2]))
143143

144144
# Fallback to strings
145145
for nest_kwargs in (true, false)
146146
io = IOBuffer()
147147
with_logger(FormatLogger(JSON(; recursive=true, nest_kwargs=nest_kwargs), io)) do
148148
@info "info msg" x = [1, 2, 3] y = Dict("hi" => NaN)
149149
end
150-
json = JSON3.read(seekstart(io))
150+
json = JSONLib.parse(seekstart(io))
151151
@test json.level == "info"
152152
@test json.msg == "info msg"
153153
@test json.module == "Main"
154154
@test json.line isa Int
155155
if nest_kwargs
156156
@test json.kwargs.x == "[1, 2, 3]"
157-
@test json.kwargs[Symbol("LoggingFormats.FormatError")] == "NaN not allowed to be written in JSON spec"
157+
@test occursin("NaN not allowed to be written in JSON spec", json.kwargs[Symbol("LoggingFormats.FormatError")])
158158
y = json.kwargs.y
159159
else
160160
@test json.x == "[1, 2, 3]"
161-
@test json[Symbol("LoggingFormats.FormatError")] == "NaN not allowed to be written in JSON spec"
161+
@test occursin("NaN not allowed to be written in JSON spec", json[Symbol("LoggingFormats.FormatError")])
162162
y = json.y
163163
end
164164
must_have = ("Dict", "\"hi\"", "=>", "NaN")
@@ -172,7 +172,7 @@ end
172172
with_logger(FormatLogger(JSON(; recursive=recursive, nest_kwargs=nest_kwargs), io)) do
173173
@error "Oh no" exception = ArgumentError("no")
174174
end
175-
logs = JSON3.read(seekstart(io))
175+
logs = JSONLib.parse(seekstart(io))
176176
@test logs["msg"] == "Oh no"
177177
ex = nest_kwargs ? logs["kwargs"]["exception"] : logs["exception"]
178178
@test ex == "ArgumentError: no"
@@ -182,7 +182,7 @@ end
182182
with_logger(FormatLogger(JSON(; recursive=recursive, nest_kwargs=nest_kwargs), io)) do
183183
@error "Oh no" ex = ArgumentError("no")
184184
end
185-
logs = JSON3.read(seekstart(io))
185+
logs = JSONLib.parse(seekstart(io))
186186
@test logs["msg"] == "Oh no"
187187
ex = nest_kwargs ? logs["kwargs"]["ex"] : logs["ex"]
188188
@test ex == "ArgumentError: no"
@@ -196,7 +196,7 @@ end
196196
@error "Oh no" exception = (e, catch_backtrace())
197197
end
198198
end
199-
logs = JSON3.read(seekstart(io))
199+
logs = JSONLib.parse(seekstart(io))
200200
@test logs["msg"] == "Oh no"
201201

202202
ex = nest_kwargs ? logs["kwargs"]["exception"] : logs["exception"]
@@ -279,5 +279,5 @@ end
279279
# write(in, str)
280280
# close(in)
281281
# wait(p)
282-
# output = JSON3.read(read(out))
282+
# output = JSONLib.parse(read(out))
283283
end

0 commit comments

Comments
 (0)