esironal / json-path

Automatically exported from code.google.com/p/json-path
0 stars 0 forks source link

A syntax for assertions #12

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

This is not an issue, it is more like a feature request or the desire to open a 
discussion i suppose :-)

So I wanted to use jsonpath for implementing filtering on my command line tool 
that deals with json data. I wanted to be able to express things like:

Do something with the given json item if: a.b==3 AND a.d!="cheese" AND a.c<2.

Programmatically, the JsonAssert style assertions are a great way to do this. 
In fact I've written some code that chains a set of these assertions together 
and accepts items accordingly. However, the input is quite dirty!

If the values being checked happened to be list items, i.e. the json looked 
like: {"a":[{"b":1}]} then as jsonpath input one can write things like: 
a[?(@.b==1)]. Nice and tidy. However, assertions against non-list values seem 
to be not syntactically supported.

My current "massive hack"(tm) is to accept strings like: a.b:==1 and split on 
:== and then build the assertion, taking the first half as the jsonpath and the 
second half as the value to test equality against. 

This is obviously not a great idea, not to mention requiring to split strings, 
it doesn't support complex assertions yet, and to do so would be horrible 
(given the current way im doing it)

So questions! Is there already a way to express the kind of filter? If not, is 
there a plan to build assertions into jsonpath syntax? If so, can i help? :-)

Cheers!
- Sina

Original issue reported on code.google.com by sin...@gmail.com on 14 Apr 2012 at 1:46

GoogleCodeExporter commented 9 years ago
Sorry but this is out of scope.

Original comment by kalle.st...@gmail.com on 31 Aug 2012 at 9:14