Menu

#6 Formater removes spaces inside single quote strings

None
open
nobody
None
6
2013-02-24
2013-02-23
xavier
No

Example: {text:'A simple test'} becomes
{
text: 'Asimpletest'
}

Discussion

  • xavier

    xavier - 2013-02-23

    Single quotes should be treated in the same way as double quotes.

     
  • modernskyangel

    modernskyangel - 2013-02-23

    But JSON specification said that string should use only double quote. And parameter name should use quotes for name too. For this input parser must return error at second character. I understand that this string is valid JSON object for JavaScript, but other languages and parsers is more strict, and will produce an error because bad syntax.

     

    Last edit: modernskyangel 2013-02-23
  • xavier

    xavier - 2013-02-23

    I agree that the strict application of the specification requires both properties and data to be quoted.
    However many leading Javascript APIs (e.g. ExtJs/Sencha Touch) allow for a more relaxed interpretation of the specification.

    For instance in Javascript the following is valid:

    {
        myFunction: function(msg){
            alert(msg);
        },
        myData: [
            "O'Donald",
            'a "string"',
            7
        ],
        'more':"data",
        "and-again": {hello:"world"}
    }
    

    I have yet to find a formatter that works correctly with such applications.

    It would be very nice if your plugin did! In fact I suspect that your plugin would become very popular!

     
  • Kapil Ratnani

    Kapil Ratnani - 2013-02-23

    Formatter doesn't checks for syntax errors before formatting. I think you are trying to format a JS object defined in code here. I am thinking whether to fix it or not..

     
  • Kapil Ratnani

    Kapil Ratnani - 2013-02-23

    Well, i just went through json.org

    "JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others."

    The plugin is meant for JSON data-interchange format not Javascript. The above thing is more of a job for a Javascript code formatter rather than a JSON Formatter. May be i should do a check for syntax errors before formatting(but that will make things too slow).

     
  • xavier

    xavier - 2013-02-23

    You have a good point: I should have been looking for a Javascript formatter plugin.

    The JSMinNPP (http://jsminnpp.sourceforge.net/download.php) seems to be doing the job.

     
  • Kapil Ratnani

    Kapil Ratnani - 2013-02-24
    • milestone: -->
    • priority: 1 --> 6
     

Log in to post a comment.