Path-like queries, with additions and substractions, in Jackson?

10 views
Skip to first unread message

Philip Roc

unread,
Oct 15, 2019, 12:56:16 AM10/15/19
to jackson-user
Hello,
let's assume a JSON structure containing a list of people, each having favorite foods, hobbies, and speaking one or more foreign languages.
I would like to retrieve data using a path-like syntax. For example: person[0].hobbies.*,person[1].foods.*, meaning "retrieve person 0's hobbies and foods [but not their foreign languages]".
Another example, - person[*].hobbies, - person[*].languages, meaning "delete all persons'hobbies and languages [but retrieve their favorite foods].
Can such queries be made with the Jackson Java API? If so, how? If not, can you recommend another API?
Many thanks.
Cheers,
Phil

Tatu Saloranta

unread,
Oct 15, 2019, 1:07:27 PM10/15/19
to jackson-user
Jackson does support simpler reference language, JSONPointer, so you
can find single value nodes, like:

String firstPersonName =
mapper.readTree().at("/personnel/0/name/first").asString();

but otherwise stays out of more complex querying, matching and traversal.

I know there are many packages that support more complex querying
(like JsonPath), but am not very familiar with best ones available
currently.
Maybe others can share libraries they know of.

-+ Tatu +-
Reply all
Reply to author
Forward
0 new messages