Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/pretty.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function pretty(out::IO, str::AbstractString, ac=AlignmentContext(); kw...)
if b == UInt8('{')
Base.write(out, "{\n")

obj = JSON3.read(str; kw...)
obj = JSON3.parse(buf; kw...)

if length(obj) == 0
Base.write(out, ' '^(ac.indent * ac.level + ac.offset) * "}")
Expand Down Expand Up @@ -95,7 +95,7 @@ function pretty(out::IO, str::AbstractString, ac=AlignmentContext(); kw...)
elseif b == UInt8('[')
Base.write(out, "[\n")

arr = JSON3.read(str; kw...)
arr = JSON3.parse(buf; kw...)

if length(arr) == 0
Base.write(out, ' '^(ac.indent * ac.level + ac.offset) * "]")
Expand All @@ -116,7 +116,7 @@ function pretty(out::IO, str::AbstractString, ac=AlignmentContext(); kw...)
end
# printing constant?
else
Base.write(out, str)
Base.write(out, buf)
end
return
@label invalid
Expand Down
16 changes: 8 additions & 8 deletions src/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ end
Base.codeunits(x::VectorString) = x.bytes

# high-level user API functions
read(io::Union{IO, Base.AbstractCmd}; kw...) = read(Base.read(io, String); kw...)
read(bytes::AbstractVector{UInt8}; kw...) = read(VectorString(bytes); kw...)
read(io::Union{IO, Base.AbstractCmd}; kw...) = parse(Base.read(io); kw...)
read(bytes::AbstractVector{UInt8}; kw...) = parse(bytes; kw...)
parse(str::AbstractString; kw...) = parse(codeunits(str); kw...)

"""
JSON3.read(json, [type]; kw... )
Expand All @@ -16,7 +17,7 @@ Read JSON.

## Args

* `json`: A file, string, IO, or bytes (`AbstractVector{UInt8`) containing JSON to read
* `json`: A file, string, IO, or bytes (`AbstractVector{UInt8}`) containing JSON to read
* `type`: Optionally, a type to read the JSON into. If not a [built in type](#Builtin-types), must have a "struct mapping" registered with [StructTypes.jl](#Struct-API).

## Keyword Args
Expand All @@ -28,14 +29,13 @@ Read JSON.
* `numbertype`: Type to parse numbers as. [default `nothing`, which parses numbers as Int if possible, Float64 otherwise]
* `ignore_extra_fields`: Ignore extra fields in the JSON when reading into a struct. [default `true`]
"""
function read(json::AbstractString; jsonlines::Bool=false,
numbertype::Union{DataType, Nothing}=nothing, kw...)
return parse(read_json_str(json); jsonlines, numbertype, kw...)
function read(json::AbstractString; kw...)
return parse(read_json_str(json); kw...)
end

function parse(str::AbstractString; jsonlines::Bool=false,
function parse(bytes::AbstractVector{UInt8}; jsonlines::Bool=false,
numbertype::Union{DataType, Nothing}=nothing, kw...)
buf = codeunits(str)
buf = bytes
len = length(buf)
if len == 0
error = UnexpectedEOF
Expand Down
Loading