Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

JSON Performance

I have found that performance while using JSON.parse(foo) where foo is

{"movements":[["Thruster",21, 95],["Pullup",21, 0],["Thruster",15, 95],["Pullup",15, 0],["Thruster",9, 95],["Pullup",9, 0]]}

is horrible, it takes about 25sec on a Iphone 3G.

Has anyone ran into this issue? Any alternatives?
I definitely cant have a user wait 25 sec for this to happen.

— asked September 29th 2010 by Juan Bermudez
  • json
  • json.parse
  • performance

5 Answers

  • I happened to test a json parsing of a json file with 5000 objects in an array as a part of one of project's stress test…..and it took roughly 5000ms …(Though that was on Android).

    — answered October 5th 2010 by Satta Ravi
  • I don't have a JSON parser in my head, but that fragment doesn't look right. Maybe you should check you JSON string here: http://www.jsonlint.com/

    — answered September 29th 2010 by Ben Hornedo
  • Yeah that's not valid JSON….note that your first array is missing it's starting [, the first use of "meters" is not enclosed in quotes, and you have an extra ] before the closing }. Also, while it doesn't effect JSON you probably are also missing an array entry from the first block as all the rest have 3.

    {meters, 33],["feet",21, 0],["miles",15, 95],["miles",15, 0],["inches",9, 95],["kilometers",9, 0]]}

    — answered September 29th 2010 by Mike Robinson
    1 Comment
    • Hi Mike,
      The JSON I copied was incomplete. Sorry about that.
      I updated the question with the full json string.

      Also I should note that I get this JSON from calling JSON.stringfy() save it to the DB, and later pull the string and parse it.

      — commented September 29th 2010 by Juan Bermudez
  • How big is the json string?
    I do parse strings and don't have this issue ( on a 3GS and ipod 2nd gen ).

    — answered September 30th 2010 by Dan Tamas
  • I update the JSON Object to the correct one and validated it. It says its is Valid, so I don't understand why it would take SO long to parse.

    Any hints?

    — answered October 4th 2010 by Juan Bermudez
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.