-
Notifications
You must be signed in to change notification settings - Fork 0
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
Set operations #8
Comments
@mnot I think this could be very useful, especially when dealing with typical RESTful crud APIs which are really sets most of the time anyway. The items are unique based on id, even if the API is returning a JSON array. Using deep comparisons (like test requires) for set membership would probably be too expensive for a real implementation. The client and server would have to agree on what constitutes identity (an id field, a hash algorithm etc), but that's typical even without JSON Patch. Seems like add and remove could be fairly simple, but maybe have to provide a hint that the target is a set. Perhaps something like using a { "op": "add", "path": "path/to/a/set/-", "value": <value, object, or array> },
{ "op": "remove", "path": "path/to/a/set/-", "value": <value, object, or array> } Or maybe adding specific "set-add" and "set-remove" ops? I think I like the former ( |
"add-set", "remove-set" (or "union" and "complement") operations are critical to my current use case. In an open environment where multiple companies are building clients that need to maintain data in sync, insuring that the current remove-by-index from an array performs as expected depends on everyone maintaining the same sort order for their data... a highly error prone restriction to enforce. |
Set operations could be generalized as value-based operations as I have described in #18. |
@heruan Sets don't have order whereas your "insert before/after certain existing values" suggestion depends on order. @mnot Does "json-patch2" need the concept of order for collections (lists)? Simplicity is a stated goal, so can order in collections be completely omitted? I use JSON Patch only for persistent object models where all collections are sets of entities like what @briancavalier described. This seems to be a common scenario, so perhaps "json-patch2" could be geared specifically towards it. |
I would prefer explicit set operations. But I think it is unclear how to define equality in a reasonable and general enough way. |
Feedback from IETF ALTO WG indicates it'd be good to be able to treat arrays as sets; e.g., "delete the set member with this value", "move this subset to another set".
The text was updated successfully, but these errors were encountered: