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

Option to ignore certain keys from comparison #80

Open
ChrisBlom opened this issue Aug 28, 2024 · 1 comment
Open

Option to ignore certain keys from comparison #80

ChrisBlom opened this issue Aug 28, 2024 · 1 comment

Comments

@ChrisBlom
Copy link

ChrisBlom commented Aug 28, 2024

Hey i'm using this great tool to compare results of sql queries.
For my use case it would be very useful to exclude certain keys when diffing values, but still show them if difference are found in other keys.

Example:

Suppose we have 3 json files:

echo '{"a": 1,"timestamp":1}' > a
echo '{"a": 1,"timestamp":2}' > b
echo '{"a": 2,"timestamp":3}' > c

Then running:

jd a b --ignorekeys timestamp

Should show no differences,

But jd b c outputs

@ ["a"]
- 1
+ 2

If this is a feature that is wanted, I can implement it.

@josephburnett
Copy link
Owner

@ChrisBlom thanks for reaching out! Yeah, this is something I've wanted to add for a while now. My use case was to filter out generated fields from Kubernetes objects, but the idea is the same. We want filters to include / exclude certain paths.

I would like to target specific paths with metadata in general. E.g. #4 to treat a specific array as a set. Allowing for this is a big part of why I created the -v2 diff format. It has a place for metadata before each hunk, prefixed with the ^ character.

E.g.

`^ {"Merge":true}`,

V2 is included in the latest release 1.9.1 but behind a flag because I haven't finished writing the translation routines. The biggest feature it unblocked was smallest edit distance. But it's a good framework for this too.

I want to define the diff format first because that's the baseline functionality. Whatever commandline parameters you provide need to be represented in the diff so it will be applied with the semantics you intended. So how about this for filter out a path?

^ {"exclude":["timestamp"]}
@ ["a"]
- 1
+ 2

You would produce this diff with this command: jd b c -exclude '["timestamp"]' where the -exclude option can be specified multiple times. And it has also an -include friend.

What do you think?

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