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

How to add exclude nodes/keys in JSON during the comparison? #2

Open
vignesh-thangaraj opened this issue Mar 1, 2019 · 1 comment

Comments

@vignesh-thangaraj
Copy link

No description provided.

@espadrine
Copy link
Owner

Hi Dookiee!

I don’t think you can do it in the current API, short of removing the keys before passing the JSON in.

What is the intent? Is it to speed up computation, or fix incorrect matching?
If it is the latter, you can pass in a custom similarity procedure that handle those keys specifically, and fallback to the default algorithm for others. See:

similarity = -> (before, after) do
if before.is_a?(Hash) && after.is_a?(Hash)
if before[:id] == after[:id]
1.0
else
0.0
end
end
end
diff = JsonDiff.diff([
{id: 1, we: "must", start: "somewhere"},
{id: 2, and: "this", will: "do"},
], [
{id: 2, insert: "something", completely: "different"},
{id: 1, this: "too", is: "different"},
], similarity: similarity)

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

2 participants