2

I'd like to assert that an element is completely missing from a JSON, not just null.

I.e. what is the JSONPath, that would match this JSON:

{ "key1": "abc" }

but not this:

{ "key1": "abc", "key2": null }

nor this:

{ "key1": "abc", "key2": "" }

with regards to key2?

For what it's worth, I'm using JSONPath with the Spring MockMVC framework, so any MockMVC ResultMatcher solution is also good.

1 Answer 1

1

if you use MockMvc you can test your api and assert that field is missing in response like that:

mockMvc.perform(...).andExpect(jsonPath("$.key2").doesNotExist())
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.