Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; 'third- party': 0.04; 'output': 0.05; 'json': 0.07; 'linux,': 0.07; 'converted': 0.09; 'exit': 0.09; 'received:localnet': 0.09; 'python': 0.11; '127': 0.16; '255': 0.16; 'command-line': 0.16; 'grounds': 0.16; 'guys,': 0.16; 'parse,': 0.16; 'patches': 0.16; 'roy': 0.16; 'soap,': 0.16; 'wrote:': 0.18; 'module': 0.19; 'file,': 0.19; 'result.': 0.19; 'solution.': 0.20; 'shell': 0.22; 'format,': 0.24; 'parse': 0.24; 'string,': 0.24; 'cheers,': 0.24; 'source': 0.25; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'on,': 0.29; 'xml': 0.29; "i'm": 0.30; 'bunch': 0.31; 'faster,': 0.31; 'run': 0.32; 'checking': 0.33; 'url:non-standard http port': 0.33; 'core': 0.34; 'received:209.85': 0.35; 'case,': 0.35; 'done.': 0.35; 'monday': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'version': 0.36; 'module.': 0.36; 'object,': 0.36; 'ubuntu': 0.36; "didn't": 0.36; 'example,': 0.37; 'operating': 0.37; 'received:209.85.216': 0.37; 'received:209': 0.37; 'system,': 0.38; 'same.': 0.38; 'to:addr:python-list': 0.38; 'that,': 0.38; 'bad': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'numbers': 0.61; "you're": 0.61; 'first': 0.61; 'header:Message-Id:1': 0.63; 'email addr:gmail.com': 0.63; 'charset:windows-1256': 0.64; 'mar': 0.68; 'reads': 0.68; 'smith': 0.68; 'store,': 0.68; 'received:204': 0.75; 'article': 0.77; 'old,': 0.85; 'boxes': 0.91 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:references:in-reply-to :mime-version:content-type:content-transfer-encoding:message-id; bh=eG9ARJKPZ5k6mx6WciOzVPBbY7XBKe0XpEmx2xgGix4=; b=CEQll8wwlpp+G2aPlT3e9sIlkpJcuDVMCr09+cVz6cpIcqsTjj+HlCwjF1s8l19shb k7rlA7gK6yoR9PW4+jQPwAxt7RI/YugD2bVmETA0oWDLV8pat0E4dRfJ4YLoBzOU0lse pFasVwbXgXCrCIm+xrwccRq86qoCTcj0SbNq94HZSV9evvIpyYf+DwPxdY7iesA2NV1F IyzFGAsscpUVN/iMaTQ6jvArDhNCcupeOgU4VzX5E/sYq5roYbYaMhzi5AvLrza4qGoO QRMc2/7GyCwoggNyoo0nAcYIE4gdGrn5q3W57kdZ+17pyKdOUSInUo3bNROGVR+Vz6fj jSdw== X-Gm-Message-State: ALoCoQllQZbL7G3NMR7lnpR2fHi2ljjjO6bWHLas/Ol+HabWq9V6CL6eWjrwC4GGt1XvhWWi1opX X-Received: by 10.224.166.9 with SMTP id k9mr33229134qay.25.1401118632532; Mon, 26 May 2014 08:37:12 -0700 (PDT) From: Gene Heskett X-Google-Original-From: Gene Heskett To: python-list@python.org Subject: Re: Verify JSON Data Date: Mon, 26 May 2014 11:37:10 -0400 References: In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="windows-1256" Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 61 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1401119046 news.xs4all.nl 2841 [2001:888:2000:d::a6]:57429 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:72072 On Monday 26 May 2014 11:19:53 Roy Smith did opine And Gene did reply: > In article , > > 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. Just for S&G, and without checking the version numbers of anything, this may not be all that bulletproof a test: gene@coyote:~$ echo '[1, 2, 3]' | json_xs -t null 2>/dev/null; echo $? 127 gene@coyote:~$ echo '[1; 2, 3]' | json_xs -t null 2>/dev/null; echo $? 127 Old, buntu 10.04.4 LTS system, all up to date security patches wise. kernal 3.13.9, PAE on a quad core phenom. Interesting result. Source of error? DamnedifIknow. Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page US V Castleman, SCOTUS, Mar 2014 is grounds for Impeaching SCOTUS