Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: MRAB Newsgroups: comp.lang.python Subject: Re: json.loads(...) ValueError: Expecting value: line 1 column 1 (char 0) Date: Mon, 9 May 2016 21:21:05 +0100 Lines: 32 Message-ID: References: <137a2593-c307-405f-8f23-3959099ff16f@googlegroups.com> <0bc0f2ad-3190-4ba0-534b-ab11015eeb54@mrabarnett.plus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de X3HidzvGYbg3E0/q/jKMSA3CVASMnDKOLENHNjxci8tQ== 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; 'error:': 0.05; 'json': 0.05; 'python3': 0.05; 'column': 0.07; 'valueerror:': 0.07; '(char': 0.09; 'expected.': 0.09; 'obj,': 0.09; 'skip:f 30': 0.15; 'decode': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject: \n (': 0.16; 'url:json': 0.16; 'value",': 0.16; 'value:': 0.16; 'wrote:': 0.16; 'variable': 0.18; '"",': 0.22; 'exec': 0.22; "skip:' 40": 0.22; 'defined': 0.23; 'this:': 0.23; '(most': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'command': 0.26; 'skip:_ 20': 0.26; 'skip:( 20': 0.28; 'looks': 0.29; 'loads': 0.29; "skip:' 50": 0.29; 'raise': 0.29; 'skip:b 40': 0.29; 'received:84': 0.32; 'getting': 0.33; 'traceback': 0.33; 'file': 0.34; 'community': 0.36; 'url:org': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'skip:v 20': 0.38; 'files': 0.38; 'hi,': 0.38; 'end': 0.39; 'why': 0.39; 'format': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'email addr:gmail.com': 0.62; 'here:': 0.63; 'subject:value': 0.84; 'edition': 0.86 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=bsGxfxui c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=IkcTkHD0fZMA:10 a=pGLkceISAAAA:8 a=v6S4GRpBAAAA:8 a=XSwMjfS6Z96Rukd8ggwA:9 a=QEXdDO2ut3YA:10 a=6kGIvZw6iX1k4Y-7sg4_:22 a=fWIMW1rJUG9htVytcIPe:22 X-AUTH: mrabarnett@:2500 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.0 In-Reply-To: <137a2593-c307-405f-8f23-3959099ff16f@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <0bc0f2ad-3190-4ba0-534b-ab11015eeb54@mrabarnett.plus.com> X-Mailman-Original-References: <137a2593-c307-405f-8f23-3959099ff16f@googlegroups.com> Xref: csiph.com comp.lang.python:108437 On 2016-05-09 20:56, zljubisic@gmail.com wrote: > Hi, > > in python3 my variable looks like this: > > a = b'{"uuid":"5730e8666ffa02.34177329","error":""}' > str(a) = 'b\'{"uuid":"5730e8666ffa02.34177329","error":""}\'' > > If I execute the following command I get the error: > >>>> json.loads(str(a)) > Traceback (most recent call last): > File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.1.2\helpers\pydev\_pydevd_bundle\pydevd_exec2.py", line 3, in Exec > exec(exp, global_vars, local_vars) > File "", line 1, in > File "C:\Program Files\Python34\lib\json\__init__.py", line 318, in loads > return _default_decoder.decode(s) > File "C:\Program Files\Python34\lib\json\decoder.py", line 343, in decode > obj, end = self.raw_decode(s, idx=_w(s, 0).end()) > File "C:\Program Files\Python34\lib\json\decoder.py", line 361, in raw_decode > raise ValueError(errmsg("Expecting value", s, err.value)) from None > ValueError: Expecting value: line 1 column 1 (char 0) > > Why I am getting this error? > If I set variable a to the '{"uuid":"5730e8666ffa02.34177329","error":""}' everything works as expected. > The b-prefix is Python-specific. It's not valid JSON syntax. The JSON format is defined here: http://www.json.org/