Connecting Tech Pros Worldwide Help | Site Map

comments in JSON?

xu.devel@googlemail.com
Guest
 
Posts: n/a
#1: May 4 '07
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

Martin Honnen
Guest
 
Posts: n/a
#2: May 4 '07

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/
-Lost
Guest
 
Posts: n/a
#3: May 4 '07

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.
Randy Webb
Guest
 
Posts: n/a
#4: May 4 '07

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/
xu.devel@googlemail.com
Guest
 
Posts: n/a
#5: May 4 '07

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