Hamcrest matchers for JSON

1,377 views
Skip to first unread message

SudhirR

unread,
Jun 29, 2011, 12:30:24 AM6/29/11
to hamcre...@googlegroups.com
Hi,

Could not find one that can be used for JSON key, value, path matching. If available please point me to it.

Regards.

Chris Rose

unread,
Jun 29, 2011, 12:32:50 AM6/29/11
to hamcre...@googlegroups.com
I'm not sure what you mean by this; do you want a matcher that will act on an encoded JSON string? Or one that will work on the decoded object? If the former, you're right -- there isn't one in the core distribution.

assert_that(json.dumps(str)), ...)

Perhaps you can explain in more detail what you want?

SudhirR

unread,
Jun 29, 2011, 12:47:43 AM6/29/11
to hamcre...@googlegroups.com
I am looking for the java version which does something like

assertThat(jsonObject, allOf(
  hasPath("one.two.three[3].four"),
  hasValueInPath("one.two.three[0].four.key", "value"),
  // and so on
));

This is for testing complete JSON structure in one shot. Currently we are relying on having an expected JSON and doing a toString match.

I have started with a hamcrest extension here - http://code.google.com/p/jsonmatcher


David Harkness

unread,
Jun 29, 2011, 12:08:16 PM6/29/11
to hamcre...@googlegroups.com

I recommend adding Json to the names, e.g. hasJsonPath. This is to distinguish them from hasXpath and friends.




--
You received this message because you are subscribed to the Google Groups "Hamcrest Developer...

To view this discussion on the web visit https://groups.google.com/d/msg/hamcrest-dev/-/ufXi5WjJy5gJ.


To post to this group, send email to hamcre...@googlegroups.com.
To unsubscribe from this group,...

Sudhir Ravindramohan

unread,
Jun 29, 2011, 12:47:02 PM6/29/11
to hamcre...@googlegroups.com
Sure will do. Thanks for the feedback.

--
You received this message because you are subscribed to the Google Groups "Hamcrest Developers" group.
To post to this group, send email to hamcre...@googlegroups.com.
To unsubscribe from this group, send email to hamcrest-dev...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hamcrest-dev?hl=en.



--
With best regards,
- Sudhir R
Tech Lead| BT, India| Blog

Reply all
Reply to author
Forward
0 new messages