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

Introducing NXJSON parser (written in C)

Expand Messages
  • yarosla
    NXJSON is full-featured yet very small (~400 lines of code) JSON parser, which has easy to use API. Features Parses JSON from null-terminated string Easy to
    Message 1 of 5 , May 13 1:55 PM
    • 0 Attachment
      NXJSON is full-featured yet very small (~400 lines of code) JSON parser, which has easy to use API.


      Features

      Parses JSON from null-terminated string
      Easy to use tree traversal API
      Allows // line and /* block */ comments (except before colon ':')
      Operates on single-byte or multi-byte characters (like UTF-8), not wide characters
      Unescapes string values (including Unicode codepoints & surrogates)
      Can use custom Unicode encoder, UTF-8 encoder built in
      Can use custom memory allocator
      Can use custom macro to print errors
      Test suite included


      Limitations

      Non-validating parser; might accept invalid JSON (eg., extra or missing commas, comments, octal or hex numeric values, etc.)


      Example usage

      const nx_json* json=nx_json_parse_utf8(code);
      printf("hello=%s\n", nx_json_get(json, "hello")->text_value);
      const nx_json* arr=nx_json_get(json, "my-array");
      int i;
      for (i=0; i<arr->length; i++) {
      const nx_json* item=nx_json_item(arr, i);
      printf("arr[%d]=(%d) %ld\n", i, (int)item->type, item->int_value);
      }
      nx_json_free(json);


      Project homepage: https://bitbucket.org/yarosla/nxjson
    • wjosdejong
      Though very practical and desired by many, comments are not supported by JSON. To prevent compatibility issues in the future, it may be better to be consistent
      Message 2 of 5 , May 14 12:01 AM
      • 0 Attachment
        Though very practical and desired by many, comments are not supported by JSON. To prevent compatibility issues in the future, it may be better to be consistent with the specs...


        --- In json@yahoogroups.com, "yarosla" <yarosla@...> wrote:
        >
        > NXJSON is full-featured yet very small (~400 lines of code) JSON parser, which has easy to use API.
        >
        >
        > Features
        >
        > Parses JSON from null-terminated string
        > Easy to use tree traversal API
        > Allows // line and /* block */ comments (except before colon ':')
        > Operates on single-byte or multi-byte characters (like UTF-8), not wide characters
        > Unescapes string values (including Unicode codepoints & surrogates)
        > Can use custom Unicode encoder, UTF-8 encoder built in
        > Can use custom memory allocator
        > Can use custom macro to print errors
        > Test suite included
        >
        >
        > Limitations
        >
        > Non-validating parser; might accept invalid JSON (eg., extra or missing commas, comments, octal or hex numeric values, etc.)
        >
        >
        > Example usage
        >
        > const nx_json* json=nx_json_parse_utf8(code);
        > printf("hello=%s\n", nx_json_get(json, "hello")->text_value);
        > const nx_json* arr=nx_json_get(json, "my-array");
        > int i;
        > for (i=0; i<arr->length; i++) {
        > const nx_json* item=nx_json_item(arr, i);
        > printf("arr[%d]=(%d) %ld\n", i, (int)item->type, item->int_value);
        > }
        > nx_json_free(json);
        >
        >
        > Project homepage: https://bitbucket.org/yarosla/nxjson
        >
      • Tatu Saloranta
        I think the way most parsers deal with this is to make comment acceptance optional: such that by default it is disabled (produces parsing error), but can be
        Message 3 of 5 , May 14 8:03 AM
        • 0 Attachment
          I think the way most parsers deal with this is to make comment acceptance
          optional: such that by default it is disabled (produces parsing error), but
          can be enabled if user explicitly chooses to.
          This is one of few tough choices with JSON: although standards should be
          followed, many (including myself) feel omission of comments is a major
          design flaw in JSON.

          -+ Tatu +-



          On Tue, May 14, 2013 at 12:01 AM, wjosdejong <wjosdejong@...> wrote:

          > Though very practical and desired by many, comments are not supported by
          > JSON. To prevent compatibility issues in the future, it may be better to be
          > consistent with the specs...
          >
          >
          > --- In json@yahoogroups.com, "yarosla" <yarosla@...> wrote:
          > >
          > > NXJSON is full-featured yet very small (~400 lines of code) JSON parser,
          > which has easy to use API.
          > >
          > >
          > > Features
          > >
          > > Parses JSON from null-terminated string
          > > Easy to use tree traversal API
          > > Allows // line and /* block */ comments (except before colon ':')
          > > Operates on single-byte or multi-byte characters (like UTF-8), not wide
          > characters
          > > Unescapes string values (including Unicode codepoints & surrogates)
          > > Can use custom Unicode encoder, UTF-8 encoder built in
          > > Can use custom memory allocator
          > > Can use custom macro to print errors
          > > Test suite included
          > >
          > >
          > > Limitations
          > >
          > > Non-validating parser; might accept invalid JSON (eg., extra or missing
          > commas, comments, octal or hex numeric values, etc.)
          > >
          > >
          > > Example usage
          > >
          > > const nx_json* json=nx_json_parse_utf8(code);
          > > printf("hello=%s\n", nx_json_get(json, "hello")->text_value);
          > > const nx_json* arr=nx_json_get(json, "my-array");
          > > int i;
          > > for (i=0; i<arr->length; i++) {
          > > const nx_json* item=nx_json_item(arr, i);
          > > printf("arr[%d]=(%d) %ld\n", i, (int)item->type, item->int_value);
          > > }
          > > nx_json_free(json);
          > >
          > >
          > > Project homepage: https://bitbucket.org/yarosla/nxjson
          > >
          >
          >
          >
          >
          > ------------------------------------
          >
          > Yahoo! Groups Links
          >
          >
          >
          >


          [Non-text portions of this message have been removed]
        • Stephan Beal
          ... A partial workaround which i use in some projects: { README : this is the doc for this particular part of the JSON tree. , data : ... } it has very
          Message 4 of 5 , May 22 3:10 AM
          • 0 Attachment
            On Tue, May 14, 2013 at 5:03 PM, Tatu Saloranta <tsaloranta@...>wrote:

            > **
            >
            > I think the way most parsers deal with this is to make comment acceptance
            > optional: such that by default it is disabled (produces parsing error), but
            > can be enabled if user explicitly chooses to.
            > This is one of few tough choices with JSON: although standards should be
            > followed, many (including myself) feel omission of comments is a major
            > design flaw in JSON.
            >

            A partial workaround which i use in some projects:

            {
            "README": "this is the doc for this particular part of the JSON tree.",
            "data": ...
            }

            it has very limited applicability but can (in some contexts) be used, e.g.,
            for commenting configuration options:

            "config":{
            "foo": 17,
            "foo.DOC": "this is the doc for the foo config option.",
            ...
            }

            --
            ----- stephan beal
            http://wanderinghorse.net/home/stephan/
            http://gplus.to/sgbeal


            [Non-text portions of this message have been removed]
          • wjosdejong
            The cases where I wish I could insert comments in a JSON file are normally cases where the file contains configuration for some application. I think JSON is
            Message 5 of 5 , May 22 4:02 AM
            • 0 Attachment
              The cases where I wish I could insert comments in a JSON file are normally cases where the file contains configuration for some application. I think JSON is excellent as a data interchange format, but much less perfect as configuration format. For configuration files I think formats like yaml and ini are better suitable.

              Jos

              --- In json@yahoogroups.com, Tatu Saloranta <tsaloranta@...> wrote:
              >
              > I think the way most parsers deal with this is to make comment acceptance
              > optional: such that by default it is disabled (produces parsing error), but
              > can be enabled if user explicitly chooses to.
              > This is one of few tough choices with JSON: although standards should be
              > followed, many (including myself) feel omission of comments is a major
              > design flaw in JSON.
              >
              > -+ Tatu +-
              >
              >
              >
              > On Tue, May 14, 2013 at 12:01 AM, wjosdejong <wjosdejong@...> wrote:
              >
              > > Though very practical and desired by many, comments are not supported by
              > > JSON. To prevent compatibility issues in the future, it may be better to be
              > > consistent with the specs...
              > >
              > >
              > > --- In json@yahoogroups.com, "yarosla" <yarosla@> wrote:
              > > >
              > > > NXJSON is full-featured yet very small (~400 lines of code) JSON parser,
              > > which has easy to use API.
              > > >
              > > >
              > > > Features
              > > >
              > > > Parses JSON from null-terminated string
              > > > Easy to use tree traversal API
              > > > Allows // line and /* block */ comments (except before colon ':')
              > > > Operates on single-byte or multi-byte characters (like UTF-8), not wide
              > > characters
              > > > Unescapes string values (including Unicode codepoints & surrogates)
              > > > Can use custom Unicode encoder, UTF-8 encoder built in
              > > > Can use custom memory allocator
              > > > Can use custom macro to print errors
              > > > Test suite included
              > > >
              > > >
              > > > Limitations
              > > >
              > > > Non-validating parser; might accept invalid JSON (eg., extra or missing
              > > commas, comments, octal or hex numeric values, etc.)
              > > >
              > > >
              > > > Example usage
              > > >
              > > > const nx_json* json=nx_json_parse_utf8(code);
              > > > printf("hello=%s\n", nx_json_get(json, "hello")->text_value);
              > > > const nx_json* arr=nx_json_get(json, "my-array");
              > > > int i;
              > > > for (i=0; i<arr->length; i++) {
              > > > const nx_json* item=nx_json_item(arr, i);
              > > > printf("arr[%d]=(%d) %ld\n", i, (int)item->type, item->int_value);
              > > > }
              > > > nx_json_free(json);
              > > >
              > > >
              > > > Project homepage: https://bitbucket.org/yarosla/nxjson
              > > >
              > >
              > >
              > >
              > >
              > > ------------------------------------
              > >
              > > Yahoo! Groups Links
              > >
              > >
              > >
              > >
              >
              >
              > [Non-text portions of this message have been removed]
              >
            Your message has been successfully submitted and would be delivered to recipients shortly.