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

1959Stripping comments from JSON.

Expand Messages
  • Dave Gamble
    May 25 6:00 PM
    • 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]
    • Show all 6 messages in this topic