You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I hope you can help me. I would like to know if it's possible to ignore a specific field during comparison. I had a look at this #156 and tried to modify it a bit to make it work for my use case, but I don't understand how to do it.
For more context: my objective is to compare two JSON strings, ignoring a specific field by name present in various levels of the hierarchy. Thank you!
should return a match. I know that I can use some trick like reflection to zero-out the fields, or unmarshal into a struct omitting the values, but if I can implement what I found with go-cmp it would definitely lead to more clear, concise and maintenable code.
The text was updated successfully, but these errors were encountered:
Turns out, it is pretty simple! Here FilterPath is necessary because FilterValues is used to ignore based on values, for example to compare float values etc. but in my case I needed to ignore a path which includes the left-hand side of the "map entry" in the predicate. Simple get all the leaves with p.Last() and you're set:
note also that if you know your struct in advance, you can use IgnoreFields as in the docs (in my case, I don't know, hence I had to use the jsonTransformer as in #156).
Hello, I hope you can help me. I would like to know if it's possible to ignore a specific field during comparison. I had a look at this #156 and tried to modify it a bit to make it work for my use case, but I don't understand how to do it.
For more context: my objective is to compare two JSON strings, ignoring a specific field by name present in various levels of the hierarchy. Thank you!
Test samples:
compared to this (only create and update times are changed):
should return a match. I know that I can use some trick like reflection to zero-out the fields, or unmarshal into a struct omitting the values, but if I can implement what I found with
go-cmp
it would definitely lead to more clear, concise and maintenable code.The text was updated successfully, but these errors were encountered: