JSON3.jl icon indicating copy to clipboard operation
JSON3.jl copied to clipboard

Allow for a partial parse

Open eike opened this issue 2 years ago • 1 comments

It would be great if there were a way to partially parse a JSON. For example, I imagine a call like

dict = JSON3.read("""
{
  "a": { "foo": 1 },
  "b": { "bar": 2 },
}""", Dict{String, JSON3.Partial})

where the result would be a Dict with the two keys "a" and "b" and values representing the two inner dictionaries. Then, you could later call JSON3.read(dict["a"], some_type) to further parse the sub-results.

The point is to postpone the decision on how to parse the inner dictionaries; for example, their target types could depend on the keys (or each other) in complex ways.

I have the impression that this is almost possible with RawType and RawValue, but if it is, I can’t figure out how.

eike avatar Oct 10 '23 16:10 eike

This will be supported in the JSON.jl 1.0 release with the introduction of JSON.lazy(x) it returns a LazyValue that can be used to lazily navigate a json structure and then materialize at a later time.

quinnj avatar Apr 24 '25 16:04 quinnj