Results 1 to 7 of 7

Thread: Why Ext.USE_NATIVE_JSON is false by default?

  1. #1
    Sencha Premium User
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    2,352
    Answers
    20
    Vote Rating
    -2788
      -1  

    Default Answered: Why Ext.USE_NATIVE_JSON is false by default?

    Why Ext.USE_NATIVE_JSON is false by default?

    Native JSON parsing is faster and more secure because it will not compile scripts.

  2. Legacy, mostly. There's a whole lot of code that works fine with:

    Code:
    {
        data: [{
            name: 'foo'
        }]
    }
    Then suddenly it all explodes. Most certainly it's better to use the native JSON, but it's off by default for the purposes of backwards compatibility.

  3. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,407
    Answers
    716
    Vote Rating
    503
      0  

    Default

    Here is a previous thread that discusses this a little:
    http://www.sencha.com/forum/showthread.php?73110

    Scott.

  4. #3
    Sencha Premium User
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    2,352
    Answers
    20
    Vote Rating
    -2788
      -2  

    Default

    Thanks Scott, but this is a very old thread.

    You should try to parse using the native JSON parser first.

    Even jQuery is doing that

  5. #4
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,407
    Answers
    716
    Vote Rating
    503
      0  

    Default

    I will shoot this over to one of the senior developers so we can both find out

    Scott.

  6. #5
    Sencha User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    18,965
    Answers
    721
    Vote Rating
    931
      0  

    Default

    Legacy, mostly. There's a whole lot of code that works fine with:

    Code:
    {
        data: [{
            name: 'foo'
        }]
    }
    Then suddenly it all explodes. Most certainly it's better to use the native JSON, but it's off by default for the purposes of backwards compatibility.
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  7. #6
    Sencha Premium Member
    Join Date
    Aug 2007
    Location
    The Netherlands
    Posts
    53
    Vote Rating
    3
      0  

    Default

    There are more issues with the current default (eval-based) approach. E.g. \u2028 and \u2029 characters can not be decoded using eval since they are not valid in a string, but work fine with JSON.parse.

    Try in your console for example:

    var a = {"test": "?this"};

    You will see JavaScript throws an error, since the word "this" contains such a character. However, when this would be received through AJAX (and not as a string literal), it could perfectly fine be decoded through JSON.parse.

  8. #7
    Sencha Premium User
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    2,352
    Answers
    20
    Vote Rating
    -2788
      -1  

    Default

    Quote Originally Posted by evant View Post
    Legacy, mostly. There's a whole lot of code that works fine with:

    Code:
    {
        data: [{
            name: 'foo'
        }]
    }
    Then suddenly it all explodes. Most certainly it's better to use the native JSON, but it's off by default for the purposes of backwards compatibility.
    This is very interesting. I always thought that JSON.parse is the fastest way to parse JSON on all browsers.

    I just tried this test, and eval is significantly faster on Chrome 56 than JSON.parse (both on macOS and Windows).

    https://jsperf.com/json-parse-vs-eval/6

    The results are reversed on IE11 and Firefox.

Posting Permissions

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