You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is actually very easy to do with minimal code using ruamel (which preserves comments, unlike pyyaml):
importsysfromruamel.yamlimportYAMLinp="""\# examplename: # details family: Smith # very common given: Alice # one of the siblings"""yaml=YAML()
obj=yaml.load(inp)
patch=JsonPatch([
{'op': 'add', 'path': '/foo', 'value': {'bar': 'baz'}},
{'op': 'remove', 'path': '/name/family'}
])
obj=patch.apply(obj)
yaml.dump(obj, sys.stdout)
yields:
# examplename:
# detailsgiven: Alice # one of the siblingsfoo:
bar: baz
which is nice
I would like to put a convenient (if trivial) interface on top of this. I could
Make a new pypi module python-yaml-patch that has this trivial wrapping code, plus CLI bindings
Make a PR on this repo
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
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 YAML objects can be used through indexing, and as your example shows, it already works with jsonpatch. Therefore I am not quite sure which additional functionality you'd need. Can you give some example?
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: