Lovelyxredxpanda / json-simple

Automatically exported from code.google.com/p/json-simple
Apache License 2.0
0 stars 0 forks source link

Allow Single Quoted Strings in Parser #20

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
It would be nice if the parser were able to parse single quoted strings.

For example:

{ 'asdf' : 'qwer"zxcv', 'zxcv' : 'qwer\'zxcv' }

would be interpreted as:

{ "asdf" : "qwer\"zxcv", "zxcv" : "qwer'zxcv" }

Original issue reported on code.google.com by matt.fowles on 16 Mar 2010 at 6:45

GoogleCodeExporter commented 9 years ago
It may be a convenient extension for some applications but we need to carefully 
think
of the following items:
- It's not part of JSON spec (http://www.ietf.org/rfc/rfc4627.txt)
- We have to develop an extension grammar (in BNF or other forms) to JSON spec 
and
make compatible to original one
- It may confuse some of users (we have some users who don't like the extension 
of
JSON spec in the implementation, see comments on
http://code.google.com/p/json-simple/wiki/DecodingExamples#Notes_-_Multithreadin
g_and_extensions).

So I am a bit reluctant to add this feature.

Original comment by fangyid...@gmail.com on 17 Mar 2010 at 8:37

GoogleCodeExporter commented 9 years ago
I did notice these discussions earlier.  I am definitely sympathetic to both 
sides, 
although I would find this extension useful.  Allow me to ask a few questions 
which 
might simplify your decisions:

- if I were to provide a patch for this, would you accept it?
- if I were to provide a patch for this and the requested "strict" mode, would 
you 
accept that?

Original comment by matt.fowles on 17 Mar 2010 at 3:01

GoogleCodeExporter commented 9 years ago
That will be great!
May I ask what the grammar for the single quoted strings is?
And may I have a look at the codes?

Thanks.

Original comment by fangyid...@gmail.com on 17 Mar 2010 at 4:16

GoogleCodeExporter commented 9 years ago
The grammar for string would become:

string := double_quote_string | single_quote_string ;
double_quote_string := " double_quote__char* " ;
single_quote_string := ' single_quote_char* '  ;
double_quote_char := any-Unicode-character-except-"-or-\-or-control-character
 | \"
 | escape_sequence ;
single_quote_char := any-Unicode-character-except-'-or-\-or-control-character
 | \'
 | escape_sequence ;
escape_sequence := \\ | \/ | \b | \f | \n | \r | \t | \u four-hex-digits ;

I have not written the code yet because I was not sure if you would accept the 
patch or 
not.

Original comment by matt.fowles on 17 Mar 2010 at 5:06

GoogleCodeExporter commented 9 years ago
Thanks a lot for providing the grammar. It looks good.
And it seems the changes will have non-trivial impacts on the existing codes. 
Could
you provide a sample scenario which requires this enhancement? We need to make 
sure
why we need such kind of enhancement.

Thanks.   

Original comment by fangyid...@gmail.com on 18 Mar 2010 at 5:51

GoogleCodeExporter commented 9 years ago
When hardcoding JSON in Java, the string within string issue becomes quite 
annoying:

String json = "{ \"asdf\" : \"qwer\\\"zxcv\" }"

vs

String json = "{ 'asdf' : 'qwer\"zxcv' }"

Also, because xml allows either form of quoting for attributes, copying and 
pasting 
strings from xml requires extra work converting.

Original comment by matt.fowles on 18 Mar 2010 at 3:03

GoogleCodeExporter commented 9 years ago
I still haven't implemented this because I was waiting on some sort of 
indication as to whether or not the code would be accepted.  Sorry for the long 
delay in response, but life got distracting.

Original comment by matt.fowles on 8 Jun 2010 at 3:30