Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #72069

Re: Verify JSON Data

From Roy Smith <roy@panix.com>
Newsgroups comp.lang.python
Subject Re: Verify JSON Data
Date 2014-05-26 11:19 -0400
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <roy-CA8FC6.11195326052014@news.panix.com> (permalink)
References <e26d3f14-ac97-4abd-bdfc-699d9ed2175c@googlegroups.com>

Show all headers | View raw


In article <e26d3f14-ac97-4abd-bdfc-699d9ed2175c@googlegroups.com>,
 gaurangnshah@gmail.com wrote:

> Hi Guys, 
> 
> Would someone let me know how to verify JSON data in python. There are so 
> many modules available to verify XML file, however i didn't find any good 
> module to verify JSON Data. 

Python comes with a built-in json module.  Just use json.load() or 
json.loads() to parse your JSON data.  The first call reads from a 
string, the second on from a file, but in all other ways, they're 
identical.

There are a bunch of third-party modules (ujson, etc) which are faster, 
but fundamentally, they're all the same.

If I understand you correctly, you're reading a JSON document which is 
so large that if you store the converted data as a Python object, you 
run out of memory?  If that's the case, I'm not sure if there's a good 
pure Python solution.  I don't know of any json modules which parse, but 
don't store, the data.

Depending on what operating system you're on, there may be a 
command-line utility which parse JSON.  For example, on Ubuntu linux, 
there's "json_xs".  Perhaps shell out to that, use the "-t null" output 
format, redirect the output to /dev/null, and see what exit status you 
get:

# Good JSON
$ echo '[1, 2, 3]' | json_xs -t null 2>/dev/null; echo $?
0

# Bad JSON
$ echo '[1; 2, 3]' | json_xs -t null 2>/dev/null; echo $?
255

Wrap this up in a subprocess.check_output() call, and you're done.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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