422,751 Members | 2,036 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 422,751 IT Pros & Developers. It's quick & easy.

comments in JSON?

P: 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

May 4 '07 #1
Share this Question
Share on Google+
4 Replies


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

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/
May 4 '07 #2

P: n/a
xu******@googlemail.com wrote:
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.
May 4 '07 #3

P: n/a
xu******@googlemail.com said the following on 5/4/2007 8:44 AM:
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/
May 4 '07 #4

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

May 4 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.