Open lukehutch opened 5 years ago
we currently have a PR for json pointers, I believe this could work too
@lukehutch look at https://github.com/eclipse-vertx/vert.x/pull/2898 and feel free to comment
@vietj @slinkydeveloper Thanks, that's exactly the sort of thing I was hoping for. Although I have to say that the escaping ~0
and ~1
for ~
and /
respectively are super weird.
I was going to suggest using the query logic in jq
:
@lukehutch I know but that's how the rfc6901 was designed :smile: We decided to adopt it more than others because we don't want any complex query system inside vertx-core and we need it for $ref resolution in new packages we are developing for vertx 4. There are good json querying libraries out there that can be plugged to support vert.x json structures (e.g. https://github.com/burtcorp/jmespath-java), but they are out of scope of vertx-stack for now
@slinkydeveloper Since a jmespath-jackson
and jmespath-gson
backends already exist, maybe a jmespath-vertx
backend could be written to plug into the vertx JsonObject
/ JsonArray
classes. (I haven't looked at jmespath
closely enough to know if that even makes sense though :-) )
Really there just needs to be a quick and simple query syntax that doesn't require the user to write custom json path-following code from scratch every time. JsonPointer seems to support that fine. However, see my comments in that PR that you linked.
I just submitted https://github.com/eclipse-vertx/vert.x/pull/2931 with a simple query API for JsonObject
/ JsonArray
.
Currently
JsonObject
methods likeJsonObject::getBoolean
take only a field name, and look up the field directly in the embeddedMap
instance. It would be nice ifJsonObject
supported syntax likeouterObject.innerObject
. This could be implemented recursively, removing one path segment at a time, with.
as a delimiter.Probably there should also be support for
JsonArray
indexing, e.g.outerObject.innerArray[0].innermostObject
.These methods would stop and return
null
if they fail at any point along the path.These changes would bring the
JsonObject
andJsonArray
query syntax into line with MongoDB'sfind
method.