Skip to content

Conversation

@FlorianLudwig
Copy link
Contributor

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 FlorianLudwig marked this pull request as draft July 31, 2021 18:40
@FlorianLudwig FlorianLudwig marked this pull request as ready for review August 1, 2021 10:22
Copy link
Owner

@spyoungtech spyoungtech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! It sounds like a great idea for the library 💯

I have just a couple questions/discussion topics on the interface and how it might be most useful to users.

Also, would be good to have some tests for this as well!

@spyoungtech
Copy link
Owner

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

@spyoungtech
Copy link
Owner

spyoungtech commented Aug 3, 2023

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants