-
Notifications
You must be signed in to change notification settings - Fork 97
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
Consider support for yaml (using ruamel.yaml) #136
Comments
Hi! Thanks for your input! As far as I know (I don't use YAML regularly, though) YAML is another serialization for similar structures (nested dict/list like) than JSON. As |
I do have to say that That said, I think I ran into an issue when combining ruamel.yaml with
This results in:
This will thus fail I think this is because My current workaround is to convert all values to normal dict/lists: def deep_copy(value: JSON) -> JSON:
match value:
case dict(value_dict):
return {key: deep_copy(value) for key, value in value_dict.items()}
case list(value_list):
return [deep_copy(value) for value in value_list]
case str() | int() | float() | bool() | None:
return value
case _:
raise ValueError(f"Invalid JSON type: {type(value)}")
src = deep_copy(src)
dst = deep_copy(dst) Note that |
My use case:
This is actually very easy to do with minimal code using ruamel (which preserves comments, unlike pyyaml):
yields:
which is nice
I would like to put a convenient (if trivial) interface on top of this. I could
I suspect (1) would be preferred but thought I would check first. Feel free to close this issue, and I will go ahead with (1), and post a link here when done.
Aside:
I note there is a lib https://github.com/krishicks/yaml-patch from @krishicks but this seems abandoned, and also duplicative. If I go ahead with (1) I wouldn't duplicate any code, just wrap as in the example above
There is also https://github.com/campos-ddc/yaml-patch from @campos-ddc which looks great, but this isn't intended to support the json-patch standard
The text was updated successfully, but these errors were encountered: