Connecting Tech Pros Worldwide Help | Site Map

comments in JSON?

 
LinkBack Thread Tools Search this Thread
  #1  
Old May 4th, 2007, 12:45 PM
xu.devel@googlemail.com
Guest
 
Posts: n/a
Default comments in JSON?

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, 12:55 PM
Martin Honnen
Guest
 
Posts: n/a
Default 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, 12:55 PM
-Lost
Guest
 
Posts: n/a
Default 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, 01:05 PM
Randy Webb
Guest
 
Posts: n/a
Default 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, 01:15 PM
xu.devel@googlemail.com
Guest
 
Posts: n/a
Default 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 :-(

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.