Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Ext User
    Join Date
    Dec 2010
    Posts
    8
    Vote Rating
    0
    troutwine is on a distinguished road

      0  

    Default JSONStore does not correctly handle JSON with '-' in property string.

    JSONStore does not correctly handle JSON with '-' in property string.


    I am unable to load otherwise valid JSON with JSONStore owing to the character '-' appearing in, at least, the root property value of my JSON. I have build a demonstration of this issue, which you may find here:

    troutwine.us/buggy_eval/

    The "good" example is a GridPanel backed with a JSONStore whose data has '_' substituted for '-'. The "bad" example does not. You will find a link to the source for the above demonstration at the demonstration's index.

    I am using Ext-3.3.1.

    Thank you,
    Brian L. Troutwine

  2. #2
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    96
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    That syntax is not supported.

    You need to use:
    Code:
    root: '["list-response"].value'
    or
    Code:
    root: function(v) {return v['list-response'].value;}

  3. #3
    Ext User
    Join Date
    Dec 2010
    Posts
    8
    Vote Rating
    0
    troutwine is on a distinguished road

      0  

    Default


    Should not JSONStore and friends have their names changed to JSON-ishStore? The '-' character is a valid character in JSON strings, after all. What other deficiencies exist in ExtJS' support for JSON?

    At the very least the documentation must be updated to reflect ExtJS' inability to correctly handle all valid JSON.

  4. #4
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    96
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    Not true. '-' is only a valid character in quoted identifies.

    (so you also need to quote them in the property selector - as I've shown)

  5. #5
    Ext User
    Join Date
    Dec 2010
    Posts
    8
    Vote Rating
    0
    troutwine is on a distinguished road

      0  

    Default


    Perhaps I'm missing something; maybe you can tell me where my expectations diverge from reality. The JSON definition has these rules:

    object -> { string : value (, string : value)* }
    string -> "" | "chars"
    chars -> char chars
    char -> Any Unicode character minus ", \ and a small list of control characters

    By these rules, which I've transcribed from here, none of the hyphen including identifiers in my JSON are invalid.

  6. #6
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    96
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    A '-' is allowed in property names as long as you put it between "quotes" (which is also mandatory in the JSON specs.

  7. #7
    Ext User
    Join Date
    Dec 2010
    Posts
    8
    Vote Rating
    0
    troutwine is on a distinguished road

      0  

    Default


    Didn't I say just that? You'll note the JSON that ExtJS does not correctly handle is:

    Code:
    {"list-response":
     {"total-count":5,"limit":100,"first-result":0,
      "value":[
          {"id":1,
           "name":"blah",
           "current-location": {"name": "the back room"},
           "status": {"name":"open!"}
          },
          {"id":2,
           "name":"urgh",
           "current-location": {"name": "the front room"},
           "status": {"name":"closed!"}
          }
      ]
     }
    }
    I have valid identifier strings according to the JSON standard. Why, then, does not ExtJS support a valid JSON identifier?

  8. #8
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    96
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    Ext is a javascript library and not a JSON library.

    And in javascript list-response is interpreted as list - response, unless you "quote" it!

  9. #9
    Ext User
    Join Date
    Dec 2010
    Posts
    8
    Vote Rating
    0
    troutwine is on a distinguished road

      0  

    Default


    Quote Originally Posted by Condor View Post
    Ext is a javascript library and not a JSON library.

    And in javascript list-response is interpreted as list - response, unless you "quote" it!
    Yes, I am familiar with the ECMAscript grammar. Section 7.8.5 of the standard defines StringLiterals. Aside from a few exceptions--none of which involve the hyphen character--both DoubleStringCharacters and SingleStringCharacters are:

    SourceCharacter :: Any Unicode code unit

    Further, section 5.12.1.2 defines JSON objects as

    JSONObject :: { } | { JSONMemberList }
    JSONMember :: JSONString : JSONValue
    JSONMemberList :: JSONMember | JSONMemberList , JSONMember

    where, in section 5.12.1.1 we have

    JSONStringCharacter :: SourceCharacter but not double-quote " or backslash \ or U+0000 thru U+001F

    You will note that they hyphen character is U+002D in the BMP. Section 7.6, of course, disallows the hyphen in object property identifier names, but the ExtJS documentation no where suggests that in order to utilize its JSON related tools the member identifiers of the JSON must also be valid Javascript identifiers.

    Is that what you are asserting? If so, ExtJS' support for JSON is contrary to the EMCAscript standard, especially as I do not use object accessors on the data returned through the provided Stores but, rather, string literals. ExtJS is indeed a Javascript library; it's current behavior with regard to JSON support is contrary to the defined Javascript standard.

    Unless, of course, I'm missing something.

  10. #10
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    96
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    Yes, you are missing something: Where in the specs you posted does it say anything about a object accessors?

    The object accessors that JsonReader supports are not something that is directly supported in JSON or javascript; it's something created for the benefit of the user.

    If you only had javascript at your disposal then you would always have to write:
    Code:
    root: function(jsonData) {
      return jsonData['list-response'].value;
    }
    but Ext helps you with this so you can also specify a string instead of a function.

    JsonReader.createAccessor supports 2 modes:
    1. If the accessor string doesn't contain '.' or '[' it will use: value = jsonData[accessor];
    2. If the accessor does contain '.' or '[' it will use: value = eval('jsonData' + (i > 0 ? '.' : '') + accessor);

    So it will support a '-' in an accessor as long as you don't also use a '.' or '[' (mode #1), e.g.
    Code:
    root: 'list-response'
    But if the accessor contains both '-' and '.' (like in your case 'list-response.data') then it will use mode #2 and you are required to add quotes to property names that wouldn't be valid otherwise, e.g.
    Code:
    root: '["list-response"].value'

Similar Threads

  1. JsonStore to handle my serieS
    By fabads in forum Ext 3.x: Help & Discussion
    Replies: 10
    Last Post: 20 Nov 2010, 1:56 AM
  2. How to handle GridFilters on server side correctly?
    By genobis in forum Ext GWT: Discussion
    Replies: 4
    Last Post: 9 Sep 2010, 11:43 PM
  3. JsonStore saving is wrapping JSON data in the root property
    By Ranma13 in forum Ext 3.x: Help & Discussion
    Replies: 3
    Last Post: 27 May 2010, 6:41 PM
  4. Replies: 2
    Last Post: 13 Aug 2009, 8:49 AM
  5. Ajax request doesn't handle beforerequest event correctly
    By Mark Wells in forum Ext 2.x: Help & Discussion
    Replies: 5
    Last Post: 31 Oct 2007, 3:16 AM

Thread Participants: 4

Tags for this Thread