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
apply(doc3, patch1) // result is {"foo":["x1"]} - great!
So in the case of doc 2, this patch will not work and will produce an error!
I tried the following patch:
patch2 := "[{"op": "add", "path": "/foo", "value": ["x1"]}]"
apply(doc1, patch2) // result is {"foo":["x1"]} - bad! I need to add not replace
apply(doc2, patch2) // result is {"foo":["x1"]} - great!
apply(doc3, patch2) // result is {"foo":["x1"]} - great!
So in the case of doc 1, this patch will not work and the original document data is replaced
What can I do?
How can I create using one or more ops, an array in documents (where it does not exist), without destroying the array data in documents where it exists?
A similar issue exists with nested keys - if you do not know if a key is there in the document or not, there is no way to create it without replacing all values in it (in case it exists). These seem to be fundamental issues with the RFC.
@evan
If my reading of the RFC is correct, this is an RFC issue, not in your implementation.
Yet, it is a problem for any application that wishes to use JSON patch and be resilient to the document provided
If I am not wrong in my interpretation, the RFC needs to be extended to solve these problems.
Will you consider extending beyond the RFC?
(e.g. add {"op": "radd" ...} which behaves like "add" but offers nested addition of keys if does not exist (recursive addition).
The text was updated successfully, but these errors were encountered:
Seems like v5 offers such extendibility by offering a way of deviating from the RFC
davidhadas
changed the title
empty array - not working as expected
Limitations of the RFC6902 when approaching document with structure not known in advance
Jan 23, 2023
davidhadas
changed the title
Limitations of the RFC6902 when approaching document with structure not known in advance
Limitations of the RFC6902 when the document structure is not known in advance
Jan 23, 2023
davidhadas
changed the title
Limitations of the RFC6902 when the document structure is not known in advance
RFC6902 limitations when the document structure is not known in advance
Jan 23, 2023
How do I add an element to an array if I do not know if the array already exist or not?
For example,I may receive any of the following base documents:
I tried the following patch:
patch1 := "[{"op": "add", "path": "/foo/0", "value": "x1"}]"
So in the case of doc 2, this patch will not work and will produce an error!
I tried the following patch:
patch2 := "[{"op": "add", "path": "/foo", "value": ["x1"]}]"
So in the case of doc 1, this patch will not work and the original document data is replaced
What can I do?
How can I create using one or more ops, an array in documents (where it does not exist), without destroying the array data in documents where it exists?
A similar issue exists with nested keys - if you do not know if a key is there in the document or not, there is no way to create it without replacing all values in it (in case it exists). These seem to be fundamental issues with the RFC.
@evan
If my reading of the RFC is correct, this is an RFC issue, not in your implementation.
Yet, it is a problem for any application that wishes to use JSON patch and be resilient to the document provided
If I am not wrong in my interpretation, the RFC needs to be extended to solve these problems.
Will you consider extending beyond the RFC?
(e.g. add {"op": "radd" ...} which behaves like "add" but offers nested addition of keys if does not exist (recursive addition).
The text was updated successfully, but these errors were encountered: