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

Is there a chance to obtain a diff between obj1 and obj2? #24

Closed
brailateo opened this issue Mar 25, 2014 · 9 comments
Closed

Is there a chance to obtain a diff between obj1 and obj2? #24

brailateo opened this issue Mar 25, 2014 · 9 comments

Comments

@brailateo
Copy link

My application need to get a diff between two different objects, obj1 and obj2 !
Is there a syntax to use it like that?
I don't have an "original object" that is modified at run-time, in order to "observe" it!
I load obj1 from a database and build obj2 from a form, and need to have the diff!
Thanks,
Teo

@Starcounter-Jack
Copy link
Owner

This would be fairly easy to add. I will provide you with a new function.

var obj1 = { FirstName:"Albert", LastName:"Hinkey" };
var obj2 = { FirstName:"Albert", LastName:"Einstein" };
var patch = jsonpatch.compare( obj1, obj2 ); // will return [{op:"replace",path:"/LastName",value:"Einstein"}]

@brailateo
Copy link
Author

That would be great, thanks!
And it's possible that the usage pattern compare(obj1,obj2) would be more frequent!
Best regards,
Teo

@brailateo
Copy link
Author

Any news? :-)
Teo

@warpech
Copy link
Collaborator

warpech commented Apr 3, 2014

Working on it right now!

@warpech
Copy link
Collaborator

warpech commented Apr 3, 2014

I added the new method observe in branch https://github.com/Starcounter-Jack/JSON-Patch/tree/compare

Could you please test and let us know how it works for you?

@brailateo
Copy link
Author

Yes it works! I tested it with information added, updated and deleted at various levels of an [object][Array][Array] variable!
I confirm it is working fine! Thanks a lot!
Please document the method also in the quick howto in home page of the project!
Best regards,
Teo

@warpech
Copy link
Collaborator

warpech commented Apr 3, 2014

Great! I merged the changes to the master branch (including API description in README.md). I will bump the version number soon.

@Starcounter-Jack
Copy link
Owner

Nice work!

@warpech
Copy link
Collaborator

warpech commented May 4, 2014

Bumped version number (0.3.7)

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

3 participants