Possible Duplicate:
Selecting a JSON object with a colon in the key
I apologize if this is a duplicate question. I searched, I really did!
What I'm trying to achieve is a simple date re-format into something nicer like "Friday, March 9, 2012". I would LOVE to use one of the many convenient jQuery plugins to parse the readily available "pubDate" value into something more useful. Unfortunately there are forces preventing me from importing any other scripts, including jQuery UI. The page template mandated by my superiors imports jQuery and that's it.
My JSON data contains the following snippet:
"items": [
{
"title": "blah blah",
"link": "http://url.blah.com",
"category": "category blah",
"pubDate": "Fri, 09 Mar 2012 16:16:05 -0500",
"y:published": {
"hour": "21",
"timezone": "UTC",
"second": "5",
"month": "3",
"month_name": "March",
"minute": "16",
"utime": "1331327765",
"day": "9",
"day_ordinal_suffix": "th",
"day_of_week": "5",
"day_name": "Friday",
"year": "2012"
},
"y:id": {
"permalink": "true",
"value": null
},
"y:title": "blah blah",
"description": "more blah blah"
}
If I'm looping over "items" using $.each, how do I retrieve the values for stuff in "y:published"?
Obviously something like
items.y:published.day_name
doesn't work because of the colon. Alas, I am not the creator of this content (it's actually the JSON feed from a Yahoo Pipe, which would probably explain the "y:"); I'm simply tasked with manipulating it. From what I've read, the "y:blahblah" entries are non-standard JSON (?) and probably not parsed via .getJSON, in which case I'm screwed. (Sub-question: is this assessment correct?)
(And just so I cover all my bases here: changing the Yahoo Pipe output from JSON to RSS/XML eliminates the "y:published" node altogether, so that's not an option.)
Thanks in advance. I have no pride; I would appreciate even the most forehead-slappingly simple solution, as long as it could be done with straight js or jQuery.
UPDATE: Answered in record time! Thanks to everyone who contributed.
The solution:
var niceDate =
singleItem['y:published'].day_name + ', ' +
singleItem['y:published'].month_name + ' ' +
singleItem['y:published'].day + ', ' +
singleItem['y:published'].year;