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
{{ message }}
Repository navigation
Feature Request: assert that key is present but ignore value #17
I was wondering if you'd be open to including some kind of flag within the macro that indicates that it should check that the key exists, but ignores the value (or just accepts any value).
The main reason for doing this would be for values such as decimals where checking for exact equality isn't likely to work eg:
json atoms at path ".price" are not equal:expected:2.97actual:2.9699999999999998
changed the title [-]Feature: assert that key to be present but ignore value[/-][+]Feature Request: assert that key to be present but ignore value[/+]on Dec 6, 2020
changed the title [-]Feature Request: assert that key to be present but ignore value[/-][+]Feature Request: assert that key is present but ignore value[/+]on Dec 6, 2020
In those cases I usually try and access the element with something like json["foo"]["bar"][1337] without any assertions since that'll panic if the key isn't there. Of course not as elegant but without a custom json! macro I don't think a better solution is possible.
A custom json! macro would also be needed to fix #8 so at least there is two use cases now.
JsonUnit for Java has some good features related to this that may inspire you :)
You can use values like ${json-unit.any-number} ${json-unit.any-string} ${json-unit-ignore} regex and so on....
Activity
[-]Feature: assert that key to be present but ignore value[/-][+]Feature Request: assert that key to be present but ignore value[/+][-]Feature Request: assert that key to be present but ignore value[/-][+]Feature Request: assert that key is present but ignore value[/+]davidpdrsn commentedon Dec 6, 2020
In those cases I usually try and access the element with something like
json["foo"]["bar"][1337]without any assertions since that'll panic if the key isn't there. Of course not as elegant but without a customjson!macro I don't think a better solution is possible.A custom
json!macro would also be needed to fix #8 so at least there is two use cases now.angristan commentedon Jun 11, 2021
I'd love this too :)
GrandmasterTash commentedon Jan 7, 2022
JsonUnit for Java has some good features related to this that may inspire you :)
You can use values like ${json-unit.any-number} ${json-unit.any-string} ${json-unit-ignore} regex and so on....