raise ValueError(errmsg("Expecting property name", s, end)) http://docs.python.org/library/json.html What am I doing wrong ?
gert wrote: > raise ValueError(errmsg("Expecting property name", s, end)) > http://docs.python.org/library/json.html > What am I doing wrong ? You need proper quotation marks: >>> s = json.dumps({'test':'test'}) >>> s '{"test": "test"}' >>> json.loads(s) {u'test': u'test'} The JSON format is described here: http://www.json.org/ Peter
On Jan 26, 5:12=A0am, gert <gert.cuyk...@gmail.com> wrote: > raise ValueError(errmsg("Expecting property name", s, end))http://docs.py= thon.org/library/json.html > What am I doing wrong ? You use wrong quotes, it should be wrapped by double quotes not single quotes. Read http://json.org/: "A string is a collection of zero or more Unicode characters, wrapped in double quotes, ..." >>> v =3D json.loads('{"test":"test"}') >>> v {u'test': u'test'}
Please include all relevant information in the *body* of your message, not just in the subject. It's a pain having to piece a question back together between the subject. On Sun, 2009-01-25 at 13:12 -0800, gert wrote: > raise ValueError(errmsg("Expecting property name", s, end)) > http://docs.python.org/library/json.html > What am I doing wrong ? JSON requires strings to be enclosed in double quotes. It is not as flexible as python when it comes to quotation. If you change your example to v = json.loads('{"test":"test"}') it will work. (Note JSON also doesn't allow trailing commas, so '{"test":"test",}' will also fail) Cheers, Cliff > -- > http://mail.python.org/mailman/listinfo/python-list >
> raise ValueError(errmsg("Expecting property name", s, end)) > http://docs.python.org/library/json.html > What am I doing wrong ? try this v = json.loads('{"test":"test"}') JSON doesn't support single quotes, only double quotes. -- дамјан ( http://softver.org.mk/damjan/ ) A: Because it reverses the logical flow of converstion. Q: Why is top posting frowned upon?
On Jan 25, 11:16=C2=A0pm, =D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD =D0=93=D0=B5= =D0=BE=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8 <gdam...@gmail.com> = wrote: > > raise ValueError(errmsg("Expecting property name", s, end)) > >http://docs.python.org/library/json.html > > What am I doing wrong ? > > try this > v =3D json.loads('{"test":"test"}') > > JSON doesn't support single quotes, only double quotes. the funny part is when you print(v) you get {'test': 'test'} Single quotes works in every browser that support json so i recommended python should support it too, besides it looks much cleaner {'test': 'test'} {"test": "test"} It can not be that hard to support both notation can it ?
gert schrieb: > On Jan 25, 11:16 pm, Дамјан Георгиевски <gdam...@gmail.com> wrote: >>> raise ValueError(errmsg("Expecting property name", s, end)) >>> http://docs.python.org/library/json.html >>> What am I doing wrong ? >> try this >> v = json.loads('{"test":"test"}') >> >> JSON doesn't support single quotes, only double quotes. > > the funny part is when you print(v) you get > {'test': 'test'} So what? That's python deciding to print strings using single-quotes. That has nothing to do with JSON. The important part is this: >>> json.dumps(json.loads('{"test":"test"}')) '{"test": "test"}' > Single quotes works in every browser that support json so i > recommended python should support it too, besides it looks much > cleaner > {'test': 'test'} > {"test": "test"} > > It can not be that hard to support both notation can it ? It's not hard, but it's not standard-conform. Most browsers even accept something like this: {foo : "bar"} But all of this is not JSON. Diez
On Jan 25, 11:51=C2=A0pm, "Diez B. Roggisch" <de...@nospam.web.de> wrote: > gert schrieb: > > > On Jan 25, 11:16 pm, =D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD =D0=93=D0=B5= =D0=BE=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8 <gdam...@gmail.com> = wrote: > >>> raise ValueError(errmsg("Expecting property name", s, end)) > >>>http://docs.python.org/library/json.html > >>> What am I doing wrong ? > >> try this > >> v =3D json.loads('{"test":"test"}') > > >> JSON doesn't support single quotes, only double quotes. > > > the funny part is when you print(v) you get > > {'test': 'test'} > > So what? That's python deciding to print strings using single-quotes. > That has nothing to do with JSON. > > The important part is this: > > =C2=A0>>> json.dumps(json.loads('{"test":"test"}')) > '{"test": "test"}' > > > Single quotes works in every browser that support json so i > > recommended python should support it too, besides it looks much > > cleaner > > {'test': 'test'} > > {"test": "test"} > > > It can not be that hard to support both notation can it ? > > It's not hard, but it's not standard-conform. > > Most browsers even accept something like this: > > {foo : "bar"} > > But all of this is not JSON. Yes it is, you just make it more python dictionary compatible :) What is this json person email address so I can ask that he makes a very small update on his site. Besides if you can make lightweight versions of standards http://docs.python.org/library/xml.dom.minidom.html You can defenatly add lightweight quotes to json.
>> >> But all of this is not JSON. > > Yes it is, you just make it more python dictionary compatible :) No, what you do is to make it more incompatible with other json-implementations. Which defies the meaning of a standard. Besides, {foo : "bar"} is *not* python dictionary compatible, at least not unless you defined foo beforehand, and then there is no guarantee that foo is actually as string containing 'foo'. > What is this json person email address so I can ask that he makes a > very small update on his site. Go try your luck - http://www.json.org/ > > Besides if you can make lightweight versions of standards > http://docs.python.org/library/xml.dom.minidom.html minidom is a lightweight version of the DOM-API. But it reads and writes standard-conform XML documents. The same applies for element-tree and lxml. So it does not serve as a counter-example. > You can defenatly add lightweight quotes to json. If you bring all other implementors of all other languages to simultaneously do so - yes, you can. Again, good luck with that. Diez
On Sun, 25 Jan 2009 23:51:41 +0100 "Diez B. Roggisch" <deets@nospam.web.de> wrote: > gert schrieb: > > {'test': 'test'} > > {"test": "test"} > > > > It can not be that hard to support both notation can it ? > > It's not hard, but it's not standard-conform. > OK, playing the devil's advocate here: Doesn't practicality beat purity? /W -- My real email address is constructed by swapping the domain with the recipient (local part).
En Sun, 25 Jan 2009 21:08:04 -0200, gert <gert.cuykens@gmail.com> escribió: > On Jan 25, 11:51 pm, "Diez B. Roggisch" <de...@nospam.web.de> wrote: >> gert schrieb: >> >> > On Jan 25, 11:16 pm, Дамјан Георгиевски <gdam...@gmail.com> wrote: >> >>> raise ValueError(errmsg("Expecting property name", s, end)) >> >>>http://docs.python.org/library/json.html >> >>> What am I doing wrong ? >> >> try this >> >> v = json.loads('{"test":"test"}') >> >> >> JSON doesn't support single quotes, only double quotes. >> > It can not be that hard to support both notation can it ? >> It's not hard, but it's not standard-conform. >> >> Most browsers even accept something like this: >> >> {foo : "bar"} >> >> But all of this is not JSON. > > Yes it is, you just make it more python dictionary compatible :) What do you mean? The above is not valid Python. JSON is whatever the author says it is. And he says "A string is a collection of zero or more Unicode characters, wrapped in double quotes, using backslash escapes". > What is this json person email address so I can ask that he makes a > very small update on his site. Try http://www.json.org/ -- good luck. > Besides if you can make lightweight versions of standards > http://docs.python.org/library/xml.dom.minidom.html This is not a lightweight version of XML, but a lightweight version of an API. minidom reads and writes the same valid XML documents. > You can defenatly add lightweight quotes to json. JSON is ligthweight *already*: "JSON (JavaScript Object Notation) is a lightweight data-interchange format." Introducing single quoted strings, apart from being incompatible with the previous version, would make parsing more complex. -- Gabriel Genellina
Andreas Waldenburger wrote: > On Sun, 25 Jan 2009 23:51:41 +0100 "Diez B. Roggisch" > <deets@nospam.web.de> wrote: > >> gert schrieb: >>> {'test': 'test'} >>> {"test": "test"} >>> >>> It can not be that hard to support both notation can it ? >> It's not hard, but it's not standard-conform. >> > OK, playing the devil's advocate here: Doesn't practicality beat purity? > It's not practical to expect a standard to be rewritten to conform with the ideas of one individual, as well as all the implementations of that standard. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/
On Jan 26, 12:40=A0am, "Diez B. Roggisch" <de...@nospam.web.de> wrote: > >> But all of this is not JSON. > > > Yes it is, you just make it more python dictionary compatible :) > > No, what you do is to make it more incompatible with other > json-implementations. Which defies the meaning of a standard. > > Besides, {foo : "bar"} is *not* python dictionary compatible, at least > not unless you defined foo beforehand, and then there is no guarantee > that foo is actually as string containing 'foo'. > > > What is this json person email address so I can ask that he makes a > > very small update on his site. > > Go try your luck -http://www.json.org/ > > > Besides if you can make lightweight versions of standards > >http://docs.python.org/library/xml.dom.minidom.html > > minidom is a lightweight version of the DOM-API. But it reads and writes > standard-conform XML documents. > > The same applies for element-tree and lxml. > > So it does not serve as a counter-example. yes it does because adding ' does not mean replacing " so it will still load standard json. Like every browser does and is exactly the same philosofie as http://docs.python.org/library/xml.dom.minidom.html The xml.dom.minidom module is essentially a DOM 1.0-compatible DOM with some DOM 2 features (primarily namespace features). or unlink() is a xml.dom.minidom-specific extension to the DOM API. After calling unlink() on a node, the node and its descendants are essentially useless.
On Sun, 25 Jan 2009 19:04:44 -0500 Steve Holden <steve@holdenweb.com> wrote: > Andreas Waldenburger wrote: > > On Sun, 25 Jan 2009 23:51:41 +0100 "Diez B. Roggisch" > > <deets@nospam.web.de> wrote: > > > >> gert schrieb: > >>> {'test': 'test'} > >>> {"test": "test"} > >>> > >>> It can not be that hard to support both notation can it ? > >> It's not hard, but it's not standard-conform. > >> > > OK, playing the devil's advocate here: Doesn't practicality beat > > purity? > > > It's not practical to expect a standard to be rewritten to conform > with the ideas of one individual, as well as all the implementations > of that standard. > But as gert says, the standard is "broken" by many many browsers already (I don't know if that's true, though; I just assume it is). Why not make it compatible with, and as forgiving as, those? (I feel a bit stupid here, because I'm basically on the "adhere to the standard" side. I just noticed that the Zen (or what I make of it) seems to suggest otherwise.) regards, /W -- My real email address is constructed by swapping the domain with the recipient (local part).
On Sun, 25 Jan 2009 19:04:44 -0500, Steve Holden wrote: > Andreas Waldenburger wrote: >> On Sun, 25 Jan 2009 23:51:41 +0100 "Diez B. Roggisch" >> <deets@nospam.web.de> wrote: >> >>> gert schrieb: >>>> {'test': 'test'} >>>> {"test": "test"} >>>> >>>> It can not be that hard to support both notation can it ? >>> It's not hard, but it's not standard-conform. >>> >> OK, playing the devil's advocate here: Doesn't practicality beat >> purity? >> > It's not practical to expect a standard to be rewritten to conform with > the ideas of one individual, as well as all the implementations of that > standard. Supposedly "every browser" (what, all of them?) already support a de facto extension to the JSON standard, allowing more flexible quoting. In an ideal world, yes the standard should change to conform to what "all browsers" do, since what they do is sensible. In my opinion, Python's handling of quotes simply is The Right Way To Do It. But more realistically, I think a more attainable solution will be for json.loads() to give a better error message than "Expecting property name" when you use the wrong quotes. -- Steven
gert wrote: > On Jan 25, 11:16 pm, Дамјан Георгиевски <gdam...@gmail.com> wrote: >>> raise ValueError(errmsg("Expecting property name", s, end)) >>> http://docs.python.org/library/json.html >>> What am I doing wrong ? >> try this >> v = json.loads('{"test":"test"}') >> >> JSON doesn't support single quotes, only double quotes. > > the funny part is when you print(v) you get > {'test': 'test'} > > Single quotes works in every browser that support json so i > recommended python should support it too, besides it looks much > cleaner > {'test': 'test'} > {"test": "test"} > > It can not be that hard to support both notation can it ? There's a difference between JavaScript source code and JSON. AFAICT from the source [1], Mozilla's JSON parser doesn't accept single quotes. [1] <http://mxr.mozilla.org/mozilla-central/source/js/src/json.cpp> --
Matt Nordhoff wrote: > gert wrote: >> On Jan 25, 11:16 pm, Дамјан Георгиевски <gdam...@gmail.com> wrote: >>>> raise ValueError(errmsg("Expecting property name", s, end)) >>>> http://docs.python.org/library/json.html >>>> What am I doing wrong ? >>> try this >>> v = json.loads('{"test":"test"}') >>> >>> JSON doesn't support single quotes, only double quotes. >> the funny part is when you print(v) you get >> {'test': 'test'} >> >> Single quotes works in every browser that support json so i >> recommended python should support it too, besides it looks much >> cleaner >> {'test': 'test'} >> {"test": "test"} >> >> It can not be that hard to support both notation can it ? > > There's a difference between JavaScript source code and JSON. AFAICT > from the source [1], Mozilla's JSON parser doesn't accept single quotes. > > [1] <http://mxr.mozilla.org/mozilla-central/source/js/src/json.cpp> By the way, I forgot to add, according to the ECMA-262 standard (page 18, section 7.8.4) [1], ECMAScript string literals can use either double or single quotes, so that's not a browser-specific extension. [1] <http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf> (<http://xrl.us/bedr3c>) --
Andreas Waldenburger <geekmail@usenot.de> wrote: > >But as gert says, the standard is "broken" by many many browsers >already We're debating relatively picky semantic point, so I won't feel bad by being picky. Browsers have nothing to do with the JSON standard. JSON is not Javascript, nor is it a part of Javascript. JSON is a data exchange standard, which happens to be readable to Javascript parsers. A valid JSON expression happens to be a valid Javascript expression, but not vice versa. That's just the way it is. -- Tim Roberts, timr@probo.com Providenza & Boekelheide, Inc.
Diez wrote: > gert schrieb: > > Single quotes works in every browser that support json so i > > recommended python should support it too, besides it looks much > > cleaner > > {'test': 'test'} > > {"test": "test"} > > > It can not be that hard to support both notation can it ? > > It's not hard, but it's not standard-conform. > > Most browsers even accept something like this: > > {foo : "bar"} > > But all of this is not JSON. By the way, all of this *is* YAML: >>> yaml.load("{'test':'test'}") {'test': 'test'} >>> yaml.load("{test: test}") {'test': 'test'} If someone needs more forgiving and user-editable format, YAML might be a good choice. -- Ivan
gert schrieb: > On Jan 26, 12:40 am, "Diez B. Roggisch" <de...@nospam.web.de> wrote: >>>> But all of this is not JSON. >>> Yes it is, you just make it more python dictionary compatible :) >> No, what you do is to make it more incompatible with other >> json-implementations. Which defies the meaning of a standard. >> >> Besides, {foo : "bar"} is *not* python dictionary compatible, at least >> not unless you defined foo beforehand, and then there is no guarantee >> that foo is actually as string containing 'foo'. >> >>> What is this json person email address so I can ask that he makes a >>> very small update on his site. >> Go try your luck -http://www.json.org/ >> >>> Besides if you can make lightweight versions of standards >>> http://docs.python.org/library/xml.dom.minidom.html >> minidom is a lightweight version of the DOM-API. But it reads and writes >> standard-conform XML documents. >> >> The same applies for element-tree and lxml. >> >> So it does not serve as a counter-example. > > yes it does because adding ' does not mean replacing " so it will > still load standard json. Like every browser does and is exactly the > same philosofie as No. If minidom would accept XML-documents that contain newlines in attributes (which otherwise are forbidden), e.g. <foo bar="some text"/> *that* would be like adding single-quote stringliterals to JSON. This is about the *format*, not the API. There are people who say something along the lines of "be strict when writing, and tolerant when reading" (the exact quote is different, but neither google:~site:mybrain nor any other have helped me here), so one could argue that reading JSON that is not standard-conform would be ok. But IMHO that would increase the amount of interoperability-problems - because some people would *write* json that isn't standard-conform anymore. Diez
On Mon, Jan 26, 2009 at 4:06 AM, Diez B. Roggisch wrote: > There are people who say something along the lines of "be strict when > writing, and tolerant when reading" (the exact quote is different, but > neither google:~site:mybrain nor any other have helped me here) That's Postel's Law: http://en.wikipedia.org/wiki/Robustness_Principle -Miles
On Sun, 2009-01-25 at 14:28 -0800, gert wrote: > On Jan 25, 11:16 pm, Дамјан Георгиевски <gdam...@gmail.com> wrote: > > > raise ValueError(errmsg("Expecting property name", s, end)) > > >http://docs.python.org/library/json.html > > > What am I doing wrong ? > > > > try this > > v = json.loads('{"test":"test"}') > > > > JSON doesn't support single quotes, only double quotes. > > the funny part is when you print(v) you get > {'test': 'test'} > > Single quotes works in every browser that support json so i > recommended python should support it too, besides it looks much > cleaner > {'test': 'test'} > {"test": "test"} > > It can not be that hard to support both notation can it ? It's not that hard, but it does add a noticeable level of complexity to the process. In JSON, you simply tell the parser, "if you see a double-quote character, we're now parsing a string. When you see another (unescaped) double-quote character, the string is done. The equivalent version for your extended JSON would say, "if you see a quote character of either kind, we're parsing a string. When you see another (unescaped) quote character of either kind, the string is done." But that doesn't work, because it would allow {'test": "test'}. So the parser has to remember which quote character is being used, and require those characters to be escaped, and not the other (but then does "te \'st" render as r"te'st" or r"te\'st"?) and only close the string when the appropriate quote is found. Not an impossible task, but certainly more complex than the current parsing requirements for JSON. Cheers, Cliff
"Steven D'Aprano" <steve@REMOVE-THIS-cybersource.com.au> wrote in message news:018d0300$0$20629$c3e8da3@news.astraweb.com... > Supposedly "every browser" (what, all of them?) already support a de > facto extension to the JSON standard, allowing more flexible quoting. That's a consequence of JSON being a subset of Javascript syntax, so you can just call eval() on it, if you're willing. When you use a library, it's pot luck whether it accepts JSON-soup or not.