Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #72071
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Verify JSON Data |
| Date | 2014-05-26 15:43 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <llvnf2$kag$1@dont-email.me> (permalink) |
| References | <e26d3f14-ac97-4abd-bdfc-699d9ed2175c@googlegroups.com> |
On Mon, 26 May 2014 07:26:20 -0700, gaurangnshah wrote:
> Is there any module through which i can verify JSON file like DOM or
> Object oriented way. ( i.e. data.key)
Where is the json data coming from? What do you mean by verify?
https://docs.python.org/2/library/json.html#encoders-and-decoders
explains how json object strings get decoded to python data types. A json
object string should at the highest level be either an object or an
array, although the python decoder can also handle strings, numbers and a
few special values.
Are you trying to check that the json string is valid json code (ie json
lint) or are you trying to check that it meets some specific structure,
in which case the only way to verify it is to decode it and check the
structure.
Note that not all valid python structures can be successfully converted
to json objects, for example a python dictionary can have tuples as keys,
but a json object can not have an array as an attribute name. For example:
d = { (1,2,3):'one',('a','b','c'):'two' }
print d
print json.JSONEncoder().encode( d )
Gives a TypeError in the json code "keys must be a string"
If you have a debian based linux distro, you can get jsonlint with:
sudo apt-get install python-demjson
which provides a command line json syntax checker and formatter.
Otherwise, google json lint, there are several web based tools that seem
to be able to do something similar.
--
Denis McMahon, denismfmcmahon@gmail.com
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Verify JSON Data gaurangnshah@gmail.com - 2014-05-26 07:26 -0700
Re: Verify JSON Data Roy Smith <roy@panix.com> - 2014-05-26 11:19 -0400
Re: Verify JSON Data Gene Heskett <gheskett@shentel.net> - 2014-05-26 11:37 -0400
Re: Verify JSON Data Roy Smith <roy@panix.com> - 2014-05-26 11:55 -0400
Re: Verify JSON Data Chris Angelico <rosuav@gmail.com> - 2014-05-27 02:02 +1000
Re: Verify JSON Data Gene Heskett <gheskett@shentel.net> - 2014-05-26 12:43 -0400
Re: Verify JSON Data Chris Angelico <rosuav@gmail.com> - 2014-05-27 01:58 +1000
Re: Verify JSON Data Chris Angelico <rosuav@gmail.com> - 2014-05-27 02:00 +1000
Re: Verify JSON Data Burak Arslan <burak.arslan@arskom.com.tr> - 2014-05-26 17:28 +0200
Re: Verify JSON Data Denis McMahon <denismfmcmahon@gmail.com> - 2014-05-26 15:43 +0000
Re: Verify JSON Data Gene Heskett <gheskett@shentel.net> - 2014-05-26 12:44 -0400
Re: Verify JSON Data Grant Edwards <invalid@invalid.invalid> - 2014-05-26 18:35 +0000
Re: Verify JSON Data Rustom Mody <rustompmody@gmail.com> - 2014-05-26 21:28 -0700
csiph-web