quinnj / JSON3.jl

Other
214 stars 47 forks source link

`JSON3.read(json; jsonlines=true)` can't handle trailing newlines #263

Open mcmcgrath13 opened 1 year ago

mcmcgrath13 commented 1 year ago

The below snippet fails due to the double trailing newlines:

JSON3.read("1\n\n2\n\n";jsonlines=true)

Exception:

ERROR: ArgumentError: invalid JSON at byte position 7 while parsing type JSON3.Array: error
1

2

Stacktrace:
 [1] invalid(error::Function, buf::Base.CodeUnits{UInt8, String}, pos::Int64, T::Type)
   @ JSON3 ~/src/raicodes/.raicode-depots/mcm-mirror-outline-union-map/packages/JSON3/jTUC3/src/JSON3.jl:30
 [2] jsonlines!(buf::Base.CodeUnits{UInt8, String}, pos::Int64, len::Int64, b::UInt8, tape::Vector{UInt64}, tapeidx::Int64, checkint::Bool; kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ JSON3 ~/src/raicodes/.raicode-depots/mcm-mirror-outline-union-map/packages/JSON3/jTUC3/src/read.jl:417
 [3] jsonlines!
   @ ~/src/raicodes/.raicode-depots/mcm-mirror-outline-union-map/packages/JSON3/jTUC3/src/read.jl:361 [inlined]
 [4] read(json::String; jsonlines::Bool, numbertype::Nothing, kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ JSON3 ~/src/raicodes/.raicode-depots/mcm-mirror-outline-union-map/packages/JSON3/jTUC3/src/read.jl:55
 [5] top-level scope
   @ REPL[5]:1

One trailing newline seems to be fine

JSON3.read("1\n\n2\n";jsonlines=true)