Loading ...
Sorry, an error occurred while loading the content.

157JSON.parse

Expand Messages
  • Douglas Crockford
    Dec 26, 2005
      I have a a new version of JSON.parse in JavaScript. It is vastly
      faster and smaller than the previous version. It uses a single call to
      eval to do the conversion, guarded by a single regExp test to assure
      that it is safe.

      parse: function (text) {
      return
      (/^(\s|[,:{}\[\]]|"(\\["\\bfnrtu]|[^\x00-\x1f"\\])*"|-?\d+(\.\d*)?([eE][+-]?\d+)?|true|false|null)+$/.test(text))
      &&
      eval('(' + text + ')');
      }

      It is ugly, but it is really efficient. I will be posting it on
      JSON.org in a few days.
    • Show all 7 messages in this topic