[Python-ideas] REG: Scope of a better API for JSON parser
Anoop Thomas Mathew
atmb4u at gmail.com
Sun Apr 6 04:58:24 CEST 2014
I went through the state of cpython JSON parser, and found that there is a
scope for improvement in the parser interface.
I have been thinking of implementing a class called QuickParse inside json
module, which will tidy up the process of finding node, and *cuts down a
number of for loops, if .. else and try ... except blocks.*
For eg.
sample_json = {
'name' : 'John Doe',
'age' : 45,
'level': 'Expert',
'languages': [
'C',
'C++',
'Python',
'Clojure'
],
'account details': {
'account number': 1233312312,
'account balance': 1000000000.00
}
}
sample_json can be a file or string
*json_doc = QuickParse(sample_json)*
*json_doc.get(["name"])*
'John Doe'
*json_doc.get(["languages", 2])*
'C++'
*json_doc.get(["account details", "account balance"])*
1000000000.00
*json_doc.get(["notpresent"]) *
None
This is something I've been using in many number of projects, due to the
complexity of the json documents these days. Also, there is a plan to
provide option to use functions for iterating over the document, as well as
selection ranges for expected values.
Looking forward to hear everyone's views on this.
regards,
ATM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140406/c3c277f6/attachment.html>
More information about the Python-ideas
mailing list