JSON3.jl
JSON3.jl copied to clipboard
Reading JSON objects from streaming buffer
Hi, I'm just looking for suggestions. I want to read JSON objects from an IO in a streaming fashion e.g. taking 1024 bytes at a time. That means I have 3 possible situations when parsing JSON objects from the data buffer:
- The buffer contains exactly one JSON object
- The buffer contains more than one JSON object
- The buffer contains a partial JSON object
When I use JSON3.read, it returns the first JSON object from the string. For case 2, I want to read the first object and shift the pointer so that I can call JSON3.read again to get the next object. l will repeat until I hit case 3 and by then I will trigger a read from the IO.
julia> s = """{"a":1,"b":2}{"a":3,"b":4}{"""
"{\"a\":1,\"b\":2}{\"a\":3,\"b\":4}{"
julia> JSON3.read(s)
JSON3.Object{Base.CodeUnits{UInt8, String}, Vector{UInt64}} with 2 entries:
:a => 1
:b => 2
julia> length("""{"a":1,"b":2}""")
13
So, I think I just need a way to get the offset after reading an object (in the above example, the value is 14). Any suggestion?