Make expire condition more standards compliant

I could only test this easily with PostgreSQL, but I'm using only SQL
standard functions and types.  As far as I know, this should work with
any RDBMS that implements the SQL standard.  That said, further testing
would be well warranted.
Added support for native JSON type

Using the JSON format for PostgreSQL caused get to explode since the
return was already an Object.  A check was added for when the returned
sess is a string.
Added better exception handling