Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > JSON from Python mysqldb

Reply
Thread Tools

JSON from Python mysqldb

 
 
jpuopolo
Guest
Posts: n/a
 
      08-26-2008
All:

I am using Python to read some records from the MySQL database. I am
using the mysqldb library, and things are working well.

Now, I would like to pass back the results of the query to a Web-based
front end, and I would like to use JSON. Is there a library/example of
creating a JSON array from a mysqldb row or row set?

Thanks,
jpuopolo
 
Reply With Quote
 
 
 
 
Larry Bates
Guest
Posts: n/a
 
      08-26-2008
jpuopolo wrote:
> All:
>
> I am using Python to read some records from the MySQL database. I am
> using the mysqldb library, and things are working well.
>
> Now, I would like to pass back the results of the query to a Web-based
> front end, and I would like to use JSON. Is there a library/example of
> creating a JSON array from a mysqldb row or row set?
>
> Thanks,
> jpuopolo


Google turns up several high quality links, just look for 'python json'.

-Larry
 
Reply With Quote
 
 
 
 
jpuopolo
Guest
Posts: n/a
 
      08-27-2008
On Aug 26, 3:15*pm, Larry Bates <(E-Mail Removed)> wrote:
> jpuopolo wrote:
> > All:

>
> > I am using Python to read some records from the MySQL database. I am
> > using the mysqldb library, and things are working well.

>
> > Now, I would like to pass back the results of the query to a Web-based
> > front end, and I would like to use JSON. Is there a library/example of
> > creating a JSON array from a mysqldb row or row set?

>
> > Thanks,
> > jpuopolo

>
> Google turns up several high quality links, just look for 'python json'.
>
> -Larry


Larry:

Thank you for the reply. Unfortunately, some of the libs the Google
search returns bail when
converting a database record into a JSON object. I may be using it/
them incorrectly, so I'll post
results to this newsgroup accordingly.

Best,
John
 
Reply With Quote
 
TYR
Guest
Posts: n/a
 
      08-27-2008
There's always the naive option.

query = ('species', 'lifestyle', 'coolness', 'tentacles=>8')
db.execute('SELECT %s, %s, %s % FROM creatures WHERE %s;' % query)
record = dict(zip((query), (db.fetchall()))
array = '''{
'''
for k,v in record:
array.append('"(k)":"(v)"')
array.append('''
}''')




 
Reply With Quote
 
TYR
Guest
Posts: n/a
 
      08-27-2008
On Aug 27, 2:37*pm, TYR <(E-Mail Removed)> wrote:
> There's always the naive option.
>
> query = ('species', 'lifestyle', 'coolness', 'tentacles=>8')
> db.execute('SELECT %s, %s, %s % FROM creatures WHERE %s;' % query)
> record = dict(zip((query), (db.fetchall()))
> array = '''{
> * * * * * * *'''
> for k,v in record:
> * array.append('"(k)":"(v)"')
> array.append('''
> * * * * * * * * }''')


Actually, don't.

query = ('species', 'lifestyle', 'coolness')
limit = ('tentacles=>8')
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lib to generate XML/JSON[P] output from a DTD/XSD/JSON Schema/etc Acácio Centeno Python 1 02-15-2013 07:34 AM
I am facing an issue while decoding json string using json.loads sajuptpm Python 2 12-28-2012 07:16 AM
[ANN] Security Fix json-1.1.7 for json_pure and json gems Florian Frank Ruby 0 06-30-2009 05:18 PM
Will MySQLdb, the Python shim, be supported for Python 2.6 or 3.x? John Nagle Python 4 11-19-2008 08:38 PM
"JSON for ASP" at json.org Tuğrul Topuz ASP General 1 06-27-2008 11:37 PM



Advertisments