Connecting Tech Pros Worldwide Help | Site Map

comments in JSON?

  #1  
Old May 4th, 2007, 01:45 PM
xu.devel@googlemail.com
Guest
 
Posts: n/a
Hello,

which comment character is used in JSON?

i have tried with {"name": "value" /* comments */ }, it is ok, but
{"name": "value" // comments } does not work.

thanks!

schuen

  #2  
Old May 4th, 2007, 01:55 PM
Martin Honnen
Guest
 
Posts: n/a

re: comments in JSON?


xu.devel@googlemail.com wrote:
Quote:
which comment character is used in JSON?
The grammar on www.json.org does not define any comments at all.

Quote:
i have tried with {"name": "value" /* comments */ }, it is ok, but
{"name": "value" // comments } does not work.
With
{"name": "value" // comments }
on one line the // comments out the closing brace '}' so that object
literal lacks the closing brace.


--

Martin Honnen
http://JavaScript.FAQTs.com/
  #3  
Old May 4th, 2007, 01:55 PM
-Lost
Guest
 
Posts: n/a

re: comments in JSON?


xu.devel@googlemail.com wrote:
Quote:
Hello,
>
which comment character is used in JSON?
>
i have tried with {"name": "value" /* comments */ }, it is ok, but
{"name": "value" // comments } does not work.
Maybe it depends on the comment being the last thing on the line. As
in, perhaps // is killing the }.

var obj1 = {
attr1 : 'the first attribute',
attr2 : 'the second attribute', // works!
attr3 : 'the third and final attribute' /* works! */
}

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
  #4  
Old May 4th, 2007, 02:05 PM
Randy Webb
Guest
 
Posts: n/a

re: comments in JSON?


xu.devel@googlemail.com said the following on 5/4/2007 8:44 AM:
Quote:
Hello,
>
which comment character is used in JSON?
>
i have tried with {"name": "value" /* comments */ }, it is ok, but
{"name": "value" // comments } does not work.
The second does indeed create a comment. The reason it "does not work"
isn't because of the comment itself, but, because the comment goes from
// to the end of the line and that, in turn, "eats" the } and causes a
syntax error:

{"name":"value"}//This comment will "work"

You don't get an error with the first one because the comment goes from
the opening to the closing comment de-limeters and doesn't "eat" the }
after it because the */ closes the comment.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
  #5  
Old May 4th, 2007, 02:15 PM
xu.devel@googlemail.com
Guest
 
Posts: n/a

re: comments in JSON?


thanks for the reply!
Quote:
{"name":"value"}//This comment will "work"
this is exactly what i want, but it does not work :-(

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Complicate json object? =?Utf-8?B?QmlsbHkgWmhhbmc=?= answers 1 August 13th, 2008 04:55 AM
url rewriting with no extension in url rapiddata answers 8 November 2nd, 2006 01:35 PM
What the heck is wrong with this JSON?? Ryan answers 5 July 13th, 2006 06:35 PM
eval to create an object (JSON) petermichaux@gmail.com answers 3 April 14th, 2006 06:15 PM