Add support for reading/writing C and C++ style comments

Issue #13 wontfix
Anonymous created an issue

It can be useful to comment some JSON files, so can you add support for reading and preserving C and C++ style comments in JSON files.

Comments (2)

  1. Serge Zaitsev repo owner

    JSON format does not support comments. So, with JSON itself I see little sense in this, since no JSON writer will allow you to write invalid JSONs. If you want to write JSON-like structured in text editor manually inserting comments I may suggest a non-strict parser mode, that allows you to write code like this (so, almost every token is valid):

    int test_nonstrict_mode() {
        const char *js;
        int r;
        jsmn_parser p;
        jsmntok_t t[10];
        js = "foo: bar\n"
             "# \"my long comment\"";
        r = jsmn_parse(&p, js, t, 10);
        check(r == JSMN_SUCCESS);
        check(TOKEN_STRING(js, t[0], "foo"));
        check(TOKEN_STRING(js, t[1], "bar"));
        check(TOKEN_STRING(js, t[2], "#"));
        check(TOKEN_STRING(js, t[3], "my long comment"));
        return 0;
  2. Log in to comment