Menu

#86 undefined not an acceptable parser token

closed-fixed
aalmiray
None
5
2009-05-17
2009-04-20
No

JSONTokenizer accepts "true" "false" and "null" but not "undefined".
I have a jquery.json library which produces the value JSON text:
{ "key": undefined }

But this throws the exception:
net.sf.json.JSONException: Unquotted string 'undefined'
at net.sf.json.util.JSONTokener.nextValue(JSONTokener.java:460)

This could trivially be handled by changing line 408 to:
if( s.equals( "null" ) || s.equals( "undefined" ) ){
return JSONNull.getInstance();
}

Discussion

  • aalmiray

    aalmiray - 2009-05-17
    • assigned_to: nobody --> aalmiray
     
  • aalmiray

    aalmiray - 2009-05-17

    Technically the value 'undefined' is not valid JSON but valid JavaScript.
    I'm thinking that by adding a setJavaScriptCompatible() flag to JsonConfig would be enough to open up the serialization mechanism to be javascript friendly.

     
  • aalmiray

    aalmiray - 2009-05-17
    • status: open --> closed-fixed
     
  • aalmiray

    aalmiray - 2009-05-17

    FIXED.

    Make sure you set jsonConfig.setJavascriptCompliant() to true before serializing. undefined will be treated as JSONNull.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.