json-five icon indicating copy to clipboard operation
json-five copied to clipboard

allow interacting with key value pairs via subscription

Open FlorianLudwig opened this issue 4 years ago • 2 comments

example usage:

import json5.loader
import json5.dumper


model = json5.loader.loads('{foo: "bar" /*a comment */, "a": 1}', loader=json5.loader.ModelLoader())
model.value["foo"] = json5.dumper.modelize("not-bar")

print(json5.dumper.dumps(model, dumper=json5.dumper.ModelDumper()))

FlorianLudwig avatar Jul 31 '21 18:07 FlorianLudwig

I think all I need is some tests for this and we should be good to merge.

spyoungtech avatar Aug 05 '21 00:08 spyoungtech

So, revisiting this, I'm having some doubts about this on account of the fact that duplicate keys are allowed, at least in the abstract model. The same thing is true in Python ast.Dict nodes.

Perhaps we can still allow this, but I think the right behavior of this would have to search the key value pairs in reverse order because of the issue of duplicate keys -- that is: the item returned should be the node object for the corresponding value as if the JSONObject were eventually dumped (where the last key overrides any previous keys of the same value).

spyoungtech avatar Aug 03 '23 21:08 spyoungtech