Loading ...
Sorry, an error occurred while loading the content.

Stripping comments from JSON.

Expand Messages
  • Dave Gamble
    Hi, THERE ARE NO COMMENTS IN JSON. I DO KNOW. With that out of the way, it s perfectly valid for someone to generate a textfile which, when passed through,
    Message 1 of 6 , May 25, 2013
    • 0 Attachment
      Hi,

      THERE ARE NO COMMENTS IN JSON. I DO KNOW.

      With that out of the way, it's perfectly valid for someone to generate a
      textfile which, when passed through, say, the C preprocessor, comes out as
      valid JSON. It'll strip comments and leave a neat, tidy block of JSON.

      So, I have this function, which is 16 lines of ANSI C, which implements
      Kyle Simpson's JSON minify routine. Lo and behold, one could use this
      extremely fast routine in place of a call to CPP and get the same results!
      Commented textfiles (read: config files), yay!

      In code use, you'd need to go:
      1. Load textfile. (as one text string)
      2. Minify. (it's still a text string)
      3. Parse JSON. (NOW it's a data structure)

      Assuming I do nothing that might conflate 2+3, does it seem acceptable that
      I could roll this into an existing JSON library (cJSON is mine)? Or am I
      tempting fate? Should I keep it separate, and make it a separate thing that
      doesn't have a function name that includes the word JSON (I am currently
      slating it as cJSON_Minify)?

      TL;DR: Function strips comments from text. Does adding this to a JSON
      library make the world a worse place?

      Will be very appreciative of any thought/feedback on the matter. Sorry if
      this one has come up before and I've not seen the thread.

      Dave.


      [Non-text portions of this message have been removed]
    • douglascrockford
      ... Have you read the JSON RFC? http://www.ietf.org/rfc/rfc4627.txt 4. Parsers A JSON parser transforms a JSON text into another representation. A JSON
      Message 2 of 6 , May 26, 2013
      • 0 Attachment
        --- In json@yahoogroups.com, Dave Gamble <davegamble@...> wrote:
        > Will be very appreciative of any thought/feedback on the matter. Sorry if
        > this one has come up before and I've not seen the thread.

        Have you read the JSON RFC? http://www.ietf.org/rfc/rfc4627.txt

        4. Parsers

        A JSON parser transforms a JSON text into another representation. A
        JSON parser MUST accept all texts that conform to the JSON grammar.
        A JSON parser MAY accept non-JSON forms or extensions.
      • Dave Gamble
        ... be the case, and the root of my confusion) to be consensus that parsers should keep JSON pure , and reject comments. I understand that according to the
        Message 3 of 6 , May 26, 2013
        • 0 Attachment
          On Sunday, May 26, 2013, douglascrockford wrote:

          > **
          >
          >
          > --- In json@yahoogroups.com <javascript:_e({}, 'cvml',
          > 'json%40yahoogroups.com');>, Dave Gamble <davegamble@...> wrote:
          > > Will be very appreciative of any thought/feedback on the matter. Sorry if
          > > this one has come up before and I've not seen the thread.
          >
          > Have you read the JSON RFC? http://www.ietf.org/rfc/rfc4627.txt
          >
          > Of course. However, in the wild, there appears (and this may in fact not
          be the case, and the root of my confusion) to be consensus that parsers
          should "keep JSON pure", and reject comments.

          I understand that according to the RFC parsing comments natively is
          acceptable, but it seems to be generally frowned upon.

          Hence, I wondered whether a simple preprocessor might be best of both world.

          Cheers!

          Dave.


          >
          >


          [Non-text portions of this message have been removed]
        • douglascrockford
          ... ECMAScript s JSON.parse is very strict. The design assumption was that if you allow web developers to do something really stupid, many of them will. So a
          Message 4 of 6 , May 26, 2013
          • 0 Attachment
            --- In json@yahoogroups.com, Dave Gamble <davegamble@...> wrote:
            > > --- In json@yahoogroups.com <javascript:_e({}, 'cvml',
            > > 'json%40yahoogroups.com');>, Dave Gamble <davegamble@> wrote:
            > > > Will be very appreciative of any thought/feedback on the matter. Sorry if
            > > > this one has come up before and I've not seen the thread.
            > >
            > > Have you read the JSON RFC? http://www.ietf.org/rfc/rfc4627.txt
            > >
            > > Of course. However, in the wild, there appears (and this may in fact not
            > be the case, and the root of my confusion) to be consensus that parsers
            > should "keep JSON pure", and reject comments.
            >
            > I understand that according to the RFC parsing comments natively is
            > acceptable, but it seems to be generally frowned upon.

            ECMAScript's JSON.parse is very strict. The design assumption was that if you allow web developers to do something really stupid, many of them will. So a lenient JSON parser in JavaScript would effectively break JSON compatibility with other languages.
          • Dave Gamble
            ... anyone to do anything stupid, since the Parse function remains equally strict. Cheers! Dave. ... [Non-text portions of this message have been removed]
            Message 5 of 6 , May 26, 2013
            • 0 Attachment
              On Sunday, May 26, 2013, douglascrockford wrote:

              > **
              >
              >
              > --- In json@yahoogroups.com <javascript:_e({}, 'cvml',
              > 'json%40yahoogroups.com');>, Dave Gamble <davegamble@...> wrote:
              > > > --- In json@yahoogroups.com <javascript:_e({}, 'cvml',
              > 'json%40yahoogroups.com');> <javascript:_e({}, 'cvml',
              > > > 'json%40yahoogroups.com');>, Dave Gamble <davegamble@> wrote:
              > > > > Will be very appreciative of any thought/feedback on the matter.
              > Sorry if
              > > > > this one has come up before and I've not seen the thread.
              > > >
              > > > Have you read the JSON RFC? http://www.ietf.org/rfc/rfc4627.txt
              > > >
              > > > Of course. However, in the wild, there appears (and this may in fact
              > not
              > > be the case, and the root of my confusion) to be consensus that parsers
              > > should "keep JSON pure", and reject comments.
              > >
              > > I understand that according to the RFC parsing comments natively is
              > > acceptable, but it seems to be generally frowned upon.
              >
              > ECMAScript's JSON.parse is very strict. The design assumption was that if
              > you allow web developers to do something really stupid, many of them will.
              > So a lenient JSON parser in JavaScript would effectively break JSON
              > compatibility with other languages.
              >
              >
              > Ok. That makes sense. The method I'm proposing really doesn't encourage
              anyone to do anything stupid, since the Parse function remains equally
              strict.

              Cheers!

              Dave.





              >
              >


              [Non-text portions of this message have been removed]
            • Jonathan Wallace
              Many libraries have support for comments. Libjson for example supports /* c comments */, //c++ comments, and #bash comments Sent from my iPhone
              Message 6 of 6 , May 26, 2013
              • 0 Attachment
                Many libraries have support for comments. Libjson for example supports /* c comments */, //c++ comments, and #bash comments

                Sent from my iPhone

                On May 26, 2013, at 10:13, Dave Gamble <davegamble@...> wrote:

                > On Sunday, May 26, 2013, douglascrockford wrote:
                >
                >> **
                >>
                >>
                >> --- In json@yahoogroups.com <javascript:_e({}, 'cvml',
                >> 'json%40yahoogroups.com');>, Dave Gamble <davegamble@...> wrote:
                >>>> --- In json@yahoogroups.com <javascript:_e({}, 'cvml',
                >> 'json%40yahoogroups.com');> <javascript:_e({}, 'cvml',
                >>>> 'json%40yahoogroups.com');>, Dave Gamble <davegamble@> wrote:
                >>>>> Will be very appreciative of any thought/feedback on the matter.
                >> Sorry if
                >>>>> this one has come up before and I've not seen the thread.
                >>>>
                >>>> Have you read the JSON RFC? http://www.ietf.org/rfc/rfc4627.txt
                >>>>
                >>>> Of course. However, in the wild, there appears (and this may in fact
                >> not
                >>> be the case, and the root of my confusion) to be consensus that parsers
                >>> should "keep JSON pure", and reject comments.
                >>>
                >>> I understand that according to the RFC parsing comments natively is
                >>> acceptable, but it seems to be generally frowned upon.
                >>
                >> ECMAScript's JSON.parse is very strict. The design assumption was that if
                >> you allow web developers to do something really stupid, many of them will.
                >> So a lenient JSON parser in JavaScript would effectively break JSON
                >> compatibility with other languages.
                >>
                >>
                >> Ok. That makes sense. The method I'm proposing really doesn't encourage
                > anyone to do anything stupid, since the Parse function remains equally
                > strict.
                >
                > Cheers!
                >
                > Dave.
                >
                >
                >
                >
                >
                >>
                >>
                >
                >
                > [Non-text portions of this message have been removed]
                >
                >
                >
                > ------------------------------------
                >
                > Yahoo! Groups Links
                >
                >
                >
              Your message has been successfully submitted and would be delivered to recipients shortly.