-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add comments when dumping #10
Conversation
Thanks for the suggestion. What is your intended use-case? |
Exactly, comments are not data. That's why I think it shouldn't be possible to extract them. But adding them is a different thing. My program generates a config file and I want the user to see what is the meaning of some settings. You can see the code here: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
request changes:
- add annotations for
_get_comments
- add error handling when any inconsistencies occur with data and comments
I see your intent, I thin it's fine for that use-case. |
Not sure about this one. Should the script validate that all keys in dictionary are strs when commenting dict and ints when list? |
I think that at least occurence a warning will help. print(jsonc.dumps({"b": 1}, indent=2, comments={"a": "foo"}))
# {
# "b": 1
# } Also, when you give |
I've added warns for unused comment keys. However, it has a side effect of removing all used ones from original dictionary. I'll add |
Nice work
|
merged. thanks! |
I thought it'd be useful to have a possibility to add comments when dumping by passing
comments=...
todump(s)
. Also I've addedtrailing_comma
arg that adds trailing commas everywhere.