Skip to content

Commit 86bda4c

Browse files
committed
more type stability for prune_json
1 parent 38af2d7 commit 86bda4c

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

Diff for: src/schema/schema.jl

+1-5
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,5 @@ prune_json(json, sch::ArrayEntry) = map(json) do el
5858
end
5959

6060
function prune_json(json, sch::DictEntry)
61-
out = Dict()
62-
for (k,v) in children(sch)
63-
String(k) keys(json) && (out[String(k)] = prune_json(json[String(k)], v))
64-
end
65-
out
61+
Dict(String(k) => prune_json(json[String(k)], v) for (k,v) in children(sch) if String(k) keys(json))
6662
end

Diff for: test/schema.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -502,30 +502,30 @@ end
502502

503503
sch = JsonGrinder.schema([j1,j2,j3,j4,j5,j6])
504504

505-
@test JsonGrinder.prune_json(j1, sch) == Dict(
505+
@test JsonGrinder.prune_json(j1, sch) == Dict{String, Any}(
506506
"c" => Dict("a"=>Dict("b"=>[4.0, 5.0, 6.0],"a"=>[1.0, 2.0, 3.0])),
507507
"b" => Dict("b"=>1.0,"a"=>[1.0, 2.0, 3.0]),
508508
"a" => 4.0)
509509

510-
@test JsonGrinder.prune_json(j2, sch) == Dict(
510+
@test JsonGrinder.prune_json(j2, sch) == Dict{String, Any}(
511511
"c" => Dict("a"=>Dict("b"=>[5, 6],"a"=>[2, 3])),
512512
"a" => 4)
513513

514514
delete!(sch.childs, :b)
515515

516-
@test JsonGrinder.prune_json(j1, sch) == Dict(
516+
@test JsonGrinder.prune_json(j1, sch) == Dict{String, Any}(
517517
"c" => Dict("a"=>Dict("b"=>[4.0, 5.0, 6.0],"a"=>[1.0, 2.0, 3.0])),
518518
"a" => 4.0)
519519

520-
@test JsonGrinder.prune_json(j2, sch) == Dict(
520+
@test JsonGrinder.prune_json(j2, sch) == Dict{String, Any}(
521521
"c" => Dict("a"=>Dict("b"=>[5, 6],"a"=>[2, 3])),
522522
"a" => 4)
523523

524524
delete!(sch.childs, :c)
525525

526-
@test JsonGrinder.prune_json(j1, sch) == Dict(
526+
@test JsonGrinder.prune_json(j1, sch) == Dict{String, Any}(
527527
"a" => 4.0)
528528

529-
@test JsonGrinder.prune_json(j2, sch) == Dict(
529+
@test JsonGrinder.prune_json(j2, sch) == Dict{String, Any}(
530530
"a" => 4)
531531
end

0 commit comments

Comments
 (0)