473,406 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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

May 4 '07 #1
4 46378
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: George Jempty | last post by:
In my journal anyway: "JSON: Javascript Unusable by the Client" http://slashdot.org/~scriptify/journal/103074
16
by: G Matthew J | last post by:
http://htmatters.net/htm/1/2005/07/evaling-JSON.cfm This is more or less in response to Mr Crockford's admonition a few months ago, "fork if you must". Ironically, although in that usenet post...
20
by: Luke Matuszewski | last post by:
Welcome As suggested i looked into JSON project and was amazed but... What about cyclical data structures - anybody was faced it in some project ? Is there any satisactional recomendation... ...
2
by: Kevin Newman | last post by:
Hello, I noticed that the JavaScript library for JSON posted on json.org (http://www.json.org/json.js) is modifying Object.prototype (adding a method - toJSONString). I thought this was...
2
by: ChrisO | last post by:
I've been pretty infatuated with JSON for some time now since "discovering" it a while back. (It's been there all along in JavaScript, but it was just never "noticed" or used by most until...
23
by: dhtmlkitchen | last post by:
JSON We all know what it is. In ECMAScript 4, there's a JSON proposal: Object.prototype.toJSONString String.prototype.parseJSON The current proposal, String.prototype.parseJSON, returns...
9
by: Jon Paal [MSMD] | last post by:
using json like ( {"Records": , "RecordCount":"1" } ) and jquery like: $.ajax({ .... success: function(json, status) {
1
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
I have a asp.net app, in client I create a Complicate json string, for example: { a: ‘a’, b : { b ; ‘b’ } } If .net has corresponding type, it could be deserialized, for example: ...
2
pradeepjain
by: pradeepjain | last post by:
i have a page post2.php which prints the json array like { page: 1, total: 239, rows: }, {id:'238',cell:}, {id:'237',cell:}, {id:'236',cell:}, {id:'235',cell:},
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.