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

Exclude object form array for diff #286

Open
unandyala opened this issue May 13, 2020 · 1 comment
Open

Exclude object form array for diff #286

unandyala opened this issue May 13, 2020 · 1 comment

Comments

@unandyala
Copy link

unandyala commented May 13, 2020

Hi Benjamine,

Thank you for the awesome library. I have a question related to arrays

I have array of objects. I want to exclude some of the objects based on the key - something like if key ends with number don't compare (exclude from diffing). Is that possible with plugins? If so where should it placed in the filters?
sample json:

[
  {
    "key": "A",
    "p1": "p1"
  },
  {
    "key": "B",
    "p1": "p1"
  },
  {
    "key": "A123",
    "p1": "p1",
    "p2": "p2"
  }
]

I want exclude object with key "A123" when doing diff

Thanks

@prasanmgc
Copy link

prasanmgc commented Feb 18, 2022

Haven't tried but you can do something like this using propertyFilter option.
const diffpatcher = create({ propertyFilter: (obj: any, name: string) => obj.name !== "A123", });
const diff = diffpatcher.diff(expectedJson, actualJson);

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