A simple, no-dependency JSON parser that can be vendored (copied/pasted) into other packages.
JSONX.parse(json_str::String)- Parse a JSON stringJSONX.parse(bytes::AbstractVector{UInt8})- Parse JSON from byte arrayJSONX.parsefile(filename::String)- Parse JSON from a file
JSONX.json(value)- Convert a Julia value to JSON stringJSONX.JSONText(str)-strwill be treated as raw JSON and inserted directly into the output.
Reading (JSON → Julia):
null→nothingtrue/false→Bool- Numbers →
Int64orFloat64(integers without decimal/exponent → Int64, with overflow fallback to Float64) - Strings →
String(with full Unicode support) - Arrays →
Vector{Any} - Objects →
Dict{String, Any}
Writing (Julia → JSON):
nothing/missing→nullBool→true/falseNumber→ JSON numberAbstractString→ JSON stringAbstractVector/AbstractSet/Tuple→ JSON arrayAbstractDict/NamedTuple→ JSON objectSymbol/Enum→ JSON string
JSONX includes full Unicode support:
- Proper Unicode escape sequence parsing (
\uXXXX) - UTF-16 surrogate pair handling
- Lone surrogate handling
- All standard JSON escape sequences (
\",\\,\/,\b,\f,\n,\r,\t)
using JSONX
# Parse JSON
data = JSONX.parse("{\"name\":\"John\",\"age\":30}")
# Returns: Dict("name" => "John", "age" => 30.0)
# Parse from bytes
bytes = Vector{UInt8}("{\"key\":\"value\"}")
data = JSONX.parse(bytes)
# Parse from file
data = JSONX.parsefile("data.json")
# Write JSON
json_str = JSONX.json(Dict("a" => 1, "b" => 2))
# Returns: "{\"a\":1,\"b\":2}"
# Unicode examples
JSONX.parse("\"Hello 世界! 🌍\"") # Full Unicode support
JSONX.parse("\"\\u0048\\u0065\\u006C\\u006C\\u006F\"") # Unicode escapesJSONX provides detailed error messages for invalid JSON:
- Unexpected end of input
- Invalid escape sequences
- Malformed Unicode escapes
- Trailing commas
- Control characters in strings
- Invalid number formats
Compared to the full JSON.jl package, JSONX is intentionally simplified:
- Limited numeric types: Parses as Int64 or Float64 only (no BigInt/BigFloat for very large numbers)
- No custom type parsing: Only returns basic Julia types
- No configuration options: Uses fixed defaults
- No streaming: Loads entire input into memory
- No pretty printing: Output is compact only
- No schema validation: Basic JSON validation only
- No performance optimizations: Simple, readable implementation
- No dependencies: Uses only Base Julia functionality
- Byte-level processing: Uses
codeunitfor accurate string handling - Memory efficient: Avoids unnecessary string concatenation
- Error robust: Comprehensive error checking and reporting
Note: Functions are not exported, so use JSONX.parse and JSONX.json with the module prefix.