Skip to content
Merged
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
2 changes: 2 additions & 0 deletions vendor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ A simple, no-dependency JSON parser that can be vendored (copied/pasted) into ot

### Writing
- `JSONX.json(value)` - Convert a Julia value to JSON string
- `JSONX.JSONText(str)` - `str` will be treated as raw JSON and inserted
directly into the output.

### Supported Types

Expand Down
7 changes: 7 additions & 0 deletions vendor/jsonx.jl
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ function parse_number(str::String, pos::Int, len::Int)
end

# JSON writing functionality

struct JSONText
text::String
end

function write_json(io::IO, value)
if value === nothing || value === missing
print(io, "null")
Expand All @@ -271,6 +276,8 @@ function write_json(io::IO, value)
elseif value isa Number
value isa Complex && throw(ArgumentError("Cannot serialize Complex numbers to JSON"))
print(io, value)
elseif value isa JSONText
print(io, value.text)
elseif value isa AbstractString
write_string(io, value)
elseif value isa AbstractVector || value isa AbstractSet || value isa Tuple
Expand Down
2 changes: 2 additions & 0 deletions vendor/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ include("jsonx.jl")
@test JSONX.json((1, 2, 3)) == "[1,2,3]"
# Note: NamedTuple order is not guaranteed, so we parse and compare
@test JSONX.parse(JSONX.json((a=1, b=2))) == Dict("a" => 1.0, "b" => 2.0)
# Test JSONText
@test JSONX.json(JSONX.JSONText("{\"x\": invalid json}")) == "{\"x\": invalid json}"
end

@testset "AbstractSet Support" begin
Expand Down
Loading