Skip to content

Reading JSON objects from streaming buffer #314

@tk3369

Description

@tk3369

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:

  1. The buffer contains exactly one JSON object
  2. The buffer contains more than one JSON object
  3. 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions