<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">On 07/15/2015 11:24 AM, Bob Ippolito
      wrote:<br>
    </div>
    <blockquote
cite="mid:CACwMPm-53kgTdKr01Vica0wQpFGVoqVM+K7USw=Q6ri120LOFg@mail.gmail.com"
      type="cite">Records are a compile time construct, so in order to
      parse as records you'd need to define the records in advance and
      provide a schema and record definition to the parser for the
      document. This could be done in a layer above the JSON parser.<br>
      <br>
    </blockquote>
    One approach which is possible for the record approach, is to use
    the parse transform <a class="moz-txt-link-freetext" href="https://github.com/okeuday/record_info_runtime/">https://github.com/okeuday/record_info_runtime/</a>
    with a function the parse transform adds: record_info_fieldtypes/1. 
    So, then the Erlang type spec information is accessible along with
    the fields based on the record name, to determine any details for
    encoding into JSON or decoding from JSON.  The nice part of that
    approach is then that the type spec information allows validation to
    catch problems, if there are any, like with nested record
    structures.  Not sure about the best way to encapsulate that
    approach, but I know it has worked in the past.<br>
    <br>
    <blockquote
cite="mid:CACwMPm-53kgTdKr01Vica0wQpFGVoqVM+K7USw=Q6ri120LOFg@mail.gmail.com"
      type="cite">
      <div><br>
      </div>
      <div>Maps are the data structure you're looking for. Most of the
        JSON implementations provide backwards compatibility to versions
        of Erlang before maps, so other data structures (such as dicts
        or proplists) are more common.<br>
        <br>
        On Wednesday, July 15, 2015, Kannan <<a
          moz-do-not-send="true" href="mailto:vasdeveloper@gmail.com">vasdeveloper@gmail.com</a>>
        wrote:<br>
        <blockquote class="gmail_quote" style="margin:0 0 0
          .8ex;border-left:1px #ccc solid;padding-left:1ex">
          <div dir="ltr">Is any of them supporting Erlang 'record' as
            their base for encoding/decoding. I see many of them are
            doing it with just list of tuples of binaries.Erlang records
            best match the structure of JSON format.
            <div><br>
            </div>
            <div>JSON</div>
            <div>----------</div>
            <div>{"name": "Theepan",</div>
            <div>  "work": "Coding",</div>
            <div>  "salary": "0"</div>
            <div>}</div>
            <div><br>
            </div>
            <div>Matching Erlang record</div>
            <div>-----------------------------------</div>
            <div>-record( json_record,</div>
            <div>{</div>
            <div>  'name' = "Theepan",</div>
            <div>  'work' = "Coding",</div>
            <div>  'salary' = "0"</div>
            <div>}</div>
            <div>}<br>
              <div><br>
              </div>
              <div>Thanks,</div>
              <div>Theepan</div>
            </div>
          </div>
          <div class="gmail_extra"><br>
            <div class="gmail_quote">On Wed, Jul 15, 2015 at 2:33 PM,
              Jesper Louis Andersen <span dir="ltr"><<a
                  moz-do-not-send="true"
                  href="javascript:_e(%7B%7D,'cvml','jesper.louis.andersen@gmail.com');"
                  target="_blank">jesper.louis.andersen@gmail.com</a>></span>
              wrote:<br>
              <blockquote class="gmail_quote" style="margin:0 0 0
                .8ex;border-left:1px #ccc solid;padding-left:1ex">
                <div dir="ltr"><span>
                    <div class="gmail_extra"><br>
                      <div class="gmail_quote">On Tue, Jul 14, 2015 at
                        10:06 PM, Kannan <span dir="ltr"><<a
                            moz-do-not-send="true"
                            href="javascript:_e(%7B%7D,'cvml','vasdeveloper@gmail.com');"
                            target="_blank">vasdeveloper@gmail.com</a>></span>
                        wrote:<br>
                        <blockquote class="gmail_quote" style="margin:0
                          0 0 .8ex;border-left:1px #ccc
                          solid;padding-left:1ex">
                          <div>I come across many JSON libraries. Once
                            from MochiWeb, Other one from Yaws. Third
                            one from CouchDB. And some others through
                            Googling.</div>
                        </blockquote>
                      </div>
                      <br>
                    </div>
                  </span>
                  <div class="gmail_extra">There are two very popular
                    JSON parsers in Erlang: jsx and jiffy.<br>
                    <br>
                  </div>
                  <div class="gmail_extra">jsx is written in plain
                    Erlang. It is fast, correct and since it is written
                    in Erlang, it will also automatically yield for
                    other processes in the system.<br>
                    <br>
                  </div>
                  <div class="gmail_extra">jiffy is written as a C NIF.
                    It is about 10 times faster than jsx, but the caveat
                    is everything that has to do with C NIFs: blocking a
                    scheduler, C code having errors, security
                    considerations, etc.<br>
                    <br>
                  </div>
                  <div class="gmail_extra">I tend to run with `jsx` in
                    my projects, and then I switch away from JSON when
                    it gets to slow. JSON is a bad format that should
                    never have existed in the first place. We are stuck
                    with it because it's historic alternative, XML, was
                    far worse in every aspect.<span><font
                        color="#888888"><br>
                      </font></span></div>
                  <span><font color="#888888">
                      <div class="gmail_extra"><br clear="all">
                        <br>
                        -- <br>
                        <div>J.</div>
                      </div>
                    </font></span></div>
              </blockquote>
            </div>
            <br>
          </div>
        </blockquote>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
erlang-questions mailing list
<a class="moz-txt-link-abbreviated" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a>
<a class="moz-txt-link-freetext" href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>