Open nlw0 opened 2 years ago
Digging into this; a few thoughts up front though:
JSON3.Object
value by index, only by key, which means there's fundamentally not a way to distinguish between getting the value 1
or the value 2
JSON3.Object
knows there are 2 unique keys (keyA
and keyC
), and that's where the length(x) == 2
property comes from. But then when printing, once it has printed 2 entries, it thinks it's "done" because of the lengthkeyC
property by doingjulia> x = JSON3.read("""{"keyA": 1, "keyA": 2, "keyC": 3}""")
JSON3.Object{Base.CodeUnits{UInt8, String}, Vector{UInt64}} with 2 entries:
:keyA => 1
:keyA => 2
julia> x.keyC
3
Anyway, I'll have to think about what to do here. Maybe we need to expose a way to index a property by ordinal number to allow getting either keyA
value. It seems we also need to fix the length
computation.
Here's a PR that at least fixes the length
computation: https://github.com/quinnj/JSON3.jl/pull/217
Great, thanks for looking into it. I must check in my actual application if the last key really is present, because I think that's how I found the problem, not just looking at the print.
I would expect a repeated key to just be discarded, with any one the possible values being chosen... Or maybe even an error. I had a repeated entry in my file by accident, but other JSON parsers just ignored it, so I never noticed.
The problem I had before was that converting the object to a Dict
with copy
drops the last value, but it's in the original object indeed. Hopefully the length
fix already solves that as well.
Having a repeated key in an object definition causes the last value to be dropped. For example: