particledecay / ansible-jsonpatch

An Ansible module for patching JSON files
MIT License
118 stars 27 forks source link

add an edit operation #17

Closed kiorky closed 3 years ago

particledecay commented 3 years ago

I'm a little torn here... I know what this is meant to do, but this would introduce a potentially confusing new command where the only difference between edit and replace is that edit doesn't need a value to exist? Couldn't you use add instead?

I'm trying to weigh the overall benefit here, because this command doesn't exist in RFC 6902, and it's also pretty close in functionality to two other commands.

kiorky commented 3 years ago

Hello @particledecay.

Yes, i totally agree that this command is not in RFC6902 and may look confusing at first, but it is not totally the same as add as when you add. If the target location specifies an array index, a new value is inserted into the array at the specified index.

In my case, the goal to edit, is ... to edit an array Value by replacing it with a new one, and not to append ot it. This is exactly what replace does.

edit not either equal to a remove then add as edit will detect correctly changes (and so trigger correctly handlers/events, and at contrario do nothing when there are no changes where remove then add will always be by definition a change and events will be always fired.

particledecay commented 3 years ago

The use case you describe regarding array values is already handled by replace. Is there another use case you figure would be good for edit? I'm very hesitant about deviating from the RFC here, especially when the command is almost exactly the same code as replace.

kiorky commented 3 years ago

Re reading carefuly the RFC, seems i mis read something around add afterall.

Thx !