tidwall/jj

should create an array when keypath is key.-1

Closed this issue · 2 comments

first, i create a blank json file by running touch arraytest.json
then command jsoned -v 1 array1.0 -i arraytest.json -o arraytest.json will results in :

{"array1":[1]}

this is expected, but command jsoned -v 1 array2.-1 -i arraytest.json -o arraytest.json will results in :

{"array2":{"-1":1}}

this time jsoned treats -1 in keypath array2.-1 as normal key instead of an array index

I expect jsoned treats -1 in keypath array2.-1 as an array index , automatically create an array if the array is absent, or appends the value after the last element if the array exists

@tidwall

Thanks for letting me know. This sounds like a bug. I'll investigate further.

I just pushed a release that should fix this issue.
Thanks for reporting this issue.