Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'string.': 0.05; 'subject:Python': 0.06; 'json': 0.07; 'string': 0.09; 'indicates': 0.09; 'prefix': 0.09; 'prefixes': 0.09; 'subject:process': 0.09; 'subject:using': 0.09; 'wrapped': 0.09; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'json,': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'parser.': 0.16; 'received:211.29': 0.16; 'received:211.29.132': 0.16; 'received:cskk.homeip.net': 0.16; 'received:homeip.net': 0.16; 'received:optusnet.com.au': 0.16; 'received:syd.optusnet.com.au': 0.16; 'remembered': 0.16; 'simpson': 0.16; 'string:': 0.16; 'unicode?': 0.16; 'wrote:': 0.18; 'pfxlen:0': 0.19; 'example': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'header:User- Agent:1': 0.23; 'parse': 0.24; 'processor': 0.24; 'unicode': 0.24; 'cheers,': 0.24; 'looks': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'sort': 0.25; 'switch': 0.26; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'returned': 0.30; "i'm": 0.30; 'sep': 0.31; 'guess': 0.33; 'could': 0.34; 'but': 0.35; 'really': 0.36; 'received:com.au': 0.36; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'received:211': 0.38; 'pm,': 0.38; 'does': 0.39; 'sure': 0.39; 'how': 0.40; 'even': 0.60; 'is.': 0.60; 'you.': 0.62; 'content- disposition:inline': 0.62; "you've": 0.63; 'needing': 0.65; 'to:addr:gmail.com': 0.65; 'subject:this': 0.83; '2013': 0.98 Date: Sun, 1 Sep 2013 10:32:24 +1000 From: Cameron Simpson To: Anthony Papillion Subject: Re: How do I process this using Python? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5222881C.8060205@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) References: <5222881C.8060205@gmail.com> X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=DstvpgP+ c=1 sm=1 tr=0 a=YuQlxtEQCowy2cfE5kc7TA==:117 a=YuQlxtEQCowy2cfE5kc7TA==:17 a=ZtCCktOnAAAA:8 a=PO7r1zJSAAAA:8 a=LcaDllckn3IA:10 a=N6jUAAFR3fkA:10 a=kj9zAlcOel0A:10 a=vrnE16BAAAAA:8 a=FvRhV4G1qyQA:10 a=pGLkceISAAAA:8 a=_Ksn7bYI775wE3AWHZ8A:9 a=CjuIK1q_8ugA:10 a=MSl-tDqOz04A:10 Cc: python-list@python.org 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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1377995558 news.xs4all.nl 15905 [2001:888:2000:d::a6]:39992 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:53387 On 31Aug2013 19:19, Anthony Papillion wrote: | On 08/31/2013 06:48 PM, Chris Angelico wrote: | > On Sun, Sep 1, 2013 at 9:44 AM, Anthony Papillion wrote: | >> I'm writing a processor for Bitmessage messages and I am needing to | >> parse the following returned JSON string: | >> | >> {u'inboxMessages': | > | > Does the JSON string really have those u prefixes and apostrophes? | > That's not valid JSON. You may be able to use ast.literal_eval() on it | > - I was able to with the example data - but not a JSON parser. Can you | > sort out your transmission end? | | I think I remembered what the 'u' prefix is. It indicates that the data | following is a unicode string. So could that be valid JSON data wrapped | up in unicode? How sure are you that it is JSON? It looks to me like a message that might once have been JSON, but has already been passed through json.loads() for you. What does type(the_json) say? What does repr(the_json) say? Print both. I would guess it has already been parsed. Cheers, -- Cameron Simpson Sattinger's Second Law: Even though you've plugged it in, it still won't work until you switch it on.