Skip to content
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

Open
mnot opened this issue Jul 28, 2014 · 5 comments
Open

Set operations #8

mnot opened this issue Jul 28, 2014 · 5 comments

Comments

@mnot
Copy link
Member

mnot commented Jul 28, 2014

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".

@briancavalier
Copy link

@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 - marker at the end of the path to indicate a set operation?

{ "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 (-) better, but not 100% sure what's best.

@michaelkantor
Copy link

"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.

@heruan
Copy link

heruan commented Nov 3, 2016

Set operations could be generalized as value-based operations as I have described in #18.

@HappyNomad
Copy link

@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.

@mitar
Copy link

mitar commented Oct 12, 2019

I would prefer explicit set operations. But I think it is unclear how to define equality in a reasonable and general enough way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants