JQuery 1.4, YUI: JSON ParseError – Quotes Required
Thursday, January 14th, 2010Someone just sent me a message asking me to update my imBannerRotater plugin because they were receiving a parseerrormessage with JQuery 1.4.
I tested the plugin with JQuery 1.4 and I too received the parseerror message. I knew immediately that the problem was with the Json record that was returned via an ajax request. Looking at the json record, I noticed that quotes were placed around the value, but not the name/key, so I added the quotes:
// originally {name: "joneil.jpg", url: "http://www.imdb.com/character/ch0005968/"} // changed to {"name": "joneil.jpg", "url": "http://www.imdb.com/character/ch0005968/"} |
I tested and no longer received the parseerror message.
The reason I knew that the error was due to the json record is because I ran into a similar problem with YUI last week. I received a parse error with a json record because I used single quotes rather than double quotes. I thought it was odd (and I was a bit displeased).
Knowing about the problem with YUI and single quotes, I tested json object above using single quotes:
{'name': 'joneil.jpg', 'url': 'http://www.imdb.com/character/ch0005968/'} |
I again received the parseerror message. So you must use double quotes. I went back and read the Json specs. It mentioned placing double quotes around the value, but did not mention anything about placing quotes (double or otherwise) around the the name/key. But YUI and JQuery 1.4 both require it so it must be required.



January 15th, 2010 at 7:02 am
[...] JQuery 1.4, YUI: JSON ParseError – Quotes Required … – Someone just sent me a message asking me to update my imBannerRotater plugin because they were receiving a parseerrormessage with JQuery 1.4. I tested the. Ads by Lake Quincy Media Other Related Items: Start, Run & Grow Your BusinessStart, Run & Grow Your Business is a great collection of tools, resources, information, and discounts to help you get your business up and running qui… Read More > Londons Times Funny Food Coffee other Digestibles – Javascript – Coffee Gift Baskets – Coffee Gift BasketJavascript Coffee Gift Basket is measuring 9×9x4. Contains 15oz mug, BONUS free set of 4 coasters, biscotti and 5 blends of gourmet coffee. French V… Read More > Learning Javascript Level 1 Keystone If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!Related PostDo you Need My Help?jQuery Expand/Collapse Using Head TagsHead First Ajax – BookAjax: The Definitive GuideDoes jQuery Make Us Lazy? Bookmark to: Hide Sites Posted in none | Tags: javascript, jQuery, json, release [...]
February 28th, 2010 at 1:54 pm
Thanks for sharing all the great code on your web site!
With respect to the double-quote requierment for JSON names: are you looking at http://www.json.org/ for the standard? It’s pretty clear about the quote requirement. It defines an object as a series of name/value pairs separated by commas and surrounded by curly braces. It further states that the name is a string (see the first syntax diagram as well as the side-bar), and it goes on to define strings as “A string is a collection of zero or more Unicode characters, wrapped in double quotes”.
Far from mentioning that you must place double-quotes around the value, it defines a value as having any of seven possible types, only one of which (string) requires double-quotes.
What’s not clear to me is whether the json.org home page is considered the authoritative specification. Do you have a better source?
Feel free to delete this comment unpublished.
February 28th, 2010 at 2:13 pm
Json.org is the best source for json specs (and is the site that I use). But in my post, I mentioned that the specs specify that double quotes are required for the ‘value’, but does mention anything about placing quotes (double or otherwise) around the ‘name/key’ (unless I’m reading the specs incorrectly).
I noticed that it was required with JQuery 1.4 (not sure when it became required with YUI). Prior to using JQuery 1.4, I rarely ever placed quotes (double or otherwise) around the name/key.
Thanks.