SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2006
    Posts
    169
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need lightweight AJAX JSON parser

    I have some JSON data at a URL on my server and I want a very lightweight javascript AJAX/JSON parser (<5k if possible) that can read the JSON from the URL and parse it into local javascript variables after the page body has loaded.

    What's the best way to do that? I've been using mootools.js and ext.js, but those are so bloated and I really only need the JSON functionality.

    Ideally I'd like my call to look something like:

    myJSONArray=parseJSON("http://myurl.com/json.php");

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    http://www.json.org/js.html

    Code javascript:
    var myObject = JSON.parse(myJSONtext);
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2006
    Posts
    169
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool. So I just send a standard HTTPRequest via AJAX and then feed the text that is returned into that function?

  4. #4
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Since it's a drop-in replacement for eval('(' + jsonStr + ')'), then yes.

  5. #5
    SitePoint Zealot
    Join Date
    Jan 2006
    Posts
    169
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Works like a champ and is only 3k minified! Thanks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •