Logical Query JSON

Denis McMahon denismfmcmahon at gmail.com
Fri Jul 31 14:36:52 CEST 2015


On Fri, 31 Jul 2015 08:07:23 +0200, dieter wrote:

> Keep in mind that Python is a (more or less) "general purpose" language
> which does not know about "jsonquery". It has "and", "or" and "not"
> operators (defined in the language reference) *BUT* these are not the
> operators you are looking for.
> You will need a special "jsonquery" extension (search
> "http://pypi.python.org" to find out whether there is something like
> this)
> which would provide appropriate support.

Actually it's not too hard. You can construct the json query syntax 
fairly easily from python once you understand it:

>>> import json

>>> query = json.dumps( { "$and":[ { "$gt": {"age": 5} }, { "$not": 
{"name": "curly"} } ] } )

>>> query

'{"$and": [{"$gt": {"age": 5}}, {"$not": {"name": "curly"}}]}'

-- 
Denis McMahon, denismfmcmahon at gmail.com


More information about the Python-list mailing list