flipkart-incubator / flipkart-incubator/zjsonpatch
feature request: add a flag to provide non-cumulative diff operations instead of ONLY patch ops
- Dominant language
- Java
- Stars
- 586
- Forks
- 153
- PR merge metrics
- No merged PRs in 30d
Description
USE CASE: Build graphical editor for modifying custom json schema structure and text that includes a button to identify differences graphically for user to review. Differences should be displayed inline in the editor (think tooltip/annotations inside document)
We are trying to use Zjsonpatch as the diff engine to compare the original json doc to the edited json doc which works fairly well but the cumulative nature (requiring the previous op in the array to be applied before the current path resolves correctly) of the patch operations makes it impossible to match operations to nodes without actually munging the doc, especially as the complexity of the edits compound.
I would like to use zjsonpatch to build a diff UI on my custom json schema. IF jsonpatch could be made to provide paths that do not require any to be applied, then we would be able to build any UI on top of our schema and then "annotate" the document with the patch operations and allow the users to review them without knowing anything about the underlying technologies or schemas.
json obj 1:
`{
"dateRevised": null,
"children": [
{
"type": "TITLEPART",
"id": null,
"sortIndex": 0,
"children": [
{
"type": "TEXT",
"id": null,
"sortIndex": 0,
"children": [
{
"children": [],
"content": "This"
},
{
"children": [],
"content": " is"
},
{
"children": [],
"content": " a"
},
{
"children": [],
"content": " test"
}
],
"scheme": null,
"scriptOrientation": null,
"bold": null,
"italic": null,
"underline": null
}
]
}
]
}`
Json obj 2:
`{
"dateRevised": null,
"children": [
{
"type": "TITLEPART",
"id": null,
"sortIndex": 0,
"children": [
{
"type": "TEXT",
"id": null,
"sortIndex": 0,
"children": [
{
"children": [],
"content": "is"
},
{
"children": [],
"content": " test"
}
],
"scheme": null,
"scriptOrientation": null,
"bold": null,
"italic": null,
"underline": null
}
]
}
]
}`
Current Patch:
`[{"op":"replace","path":"/children/0/children/0/children/0/content","value":"is"},{"op":"remove","path":"/children/0/children/0/children/1"},{"op":"remove","path":"/children/0/children/0/children/1"}]`
What I would like to have is
`
[
{"op":"remove","path":"/children/0/children/0/children/0"},{"op":"replace","path":"/children/0/children/0/children/1/content","value":"is"},
{"op":"remove","path":"/children/0/children/0/children/2"},
]
`
I am not an RFC 6902 expert but I'm thinking that simply altering the paths to identify the source node path without respect to other operations would cover 99% of my problems. Am I off base? does anyone else have this use case? how did you solve it?
Contributor guide
Research direction
The issue names no files, tests, or entry points. Start by reviewing RFC 6902 and zjsonpatch's cumulative paths using the supplied JSON documents, then clarify the semantics and API for non-cumulative operations. Done means the behavior is agreed and the example is covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100