comments in JSON?

Discussion in 'Javascript' started by xu.devel, May 4, 2007.

  1. xu.devel

    xu.devel Guest

    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
     
    xu.devel, May 4, 2007
    #1
    1. Advertisements

  2. The grammar on www.json.org does not define any comments at all.

    With
    {"name": "value" // comments }
    on one line the // comments out the closing brace '}' so that object
    literal lacks the closing brace.
     
    Martin Honnen, May 4, 2007
    #2
    1. Advertisements

  3. xu.devel

    -Lost Guest

    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, May 4, 2007
    #3
  4. xu.devel

    xu.devel Guest

    thanks for the reply!
    this is exactly what i want, but it does not work :-(
     
    xu.devel, May 4, 2007
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.