I use python and mySql, run the query below:
sSql = "select id from table_name"
cursor.execute( sSql )
lrec = self.cursor.fetchall()
json.dumps( lrec )
and get an error message because I get back long int notation 'id' : 1L instead of 'id' : 1
the only way to work around this I found to be is ugly:
sSql = "select cast(id as char(10)) as id from table_name"
Any better way of doing it?
Thanks, Juergen
fetchallis a value, not a notation. The value can contain longs, admitted. What you "get back" fromdumpsis a string, so that can contain a notation like1L. Which is it?[{ 'id': 1L}]and[{ 'id': '1'}]in second. first is no valid JSON of course and json.dumps breaks. Also in case of dates I get e.g.'date_joined': datetime.datetime(2013, 7, 2, 9, 18, 38). Ideally I could tell json.dumps to evaluate to strings, booleans and ints to make it valid JSON.