<?xml version='1.0'?>
<!DOCTYPE rfc SYSTEM 'rfc2629.dtd'>
<rfc ipr="trust200902" docName="draft-hallambaker-jsonl-01">
<front>
<title abbrev="JSON Log Format (JSON-L)">JSON Log Format (JSON-L)</title>
<author fullname="Phillip Hallam-Baker" initials="P. M." surname="Hallam-Baker">
<organization>Comodo Group Inc.</organization>
<address>
<email>philliph@comodo.com</email>
</address>
</author>
<date day="6" month="May" year="2014"/>
<area>General</area>
<workgroup/>
<keyword>JSON</keyword>
<abstract>
<t>A log file format based on the JSON encoding is described. </t>
</abstract>
</front>
<middle>
<section title="Definitions" anchor="Section_1">
<section title="Requirements Language" anchor="Section_1_1">
<t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [RFC2119]. </t>
</section>
</section>
<section title="Requirements" anchor="Section_2">
<t>A log file consists of a sequence of entries. In a JSON-L log file, each entry is a JSON object [RFC7159].</t>
<section title="Append Only Updates" anchor="Section_2_1">
<t>One of the chief drawbacks to using JSON notation as a log file format is that a log file is by definition a sequence of entries and a JSON document MUST contain exactly one object. Further JSON objects and arrays both require start '{[' and end ']}' markers.</t>
<t>Use of the JSON notation as a log file format would thus require a process appending data to a log file to either omit the end markers completely or erase the existing end markers, append the new data the file and write new end markers. </t>
<t>Both approaches are highly unsatisfactory, the first violates the JSON encoding rules and the second introduces a risk of a race condition if two processes attempt to update the same log file at the same time. </t>
<t>An encoding that permits log entries to be appended to the end of a log file without modifying the existing contents is both safer and more efficient. Since writing data to an append only log file is a common requirement, most platforms already provide efficient and robust primitives to effect append-only updates. </t>
</section>
<section title="Resynchronization" anchor="Section_2_2">
<t>Resynchronization is a mechanism that allows a reader to detect the start of a log file entry.</t>
<t>Resynchronization permits a reader to recover in the case that a log entry is corrupted and/or support random access to log file entries.</t>
<t>Log files may grow to thousands or millions of entries. When dealling with log files of such size it is frequently desirable to skip forward or backwards to quickly locate an entry added at a specific time. </t>
<t>Since JSON objects MAY be of variable lengths and MAY include nested JSON objects, a log file viewer that supports such a random access feature requires a simple means of locating the start of the next entry.</t>
</section>
</section>
<section title="Specification" anchor="Section_3">
<t>A JSON-L log file consists of a sequence of zero or more JSON objects as specified in [RFC7159] separated by white space that includes at least one newline character. </t>
<figure>
<artwork>
<![CDATA[
        JSON-L-text = *(object x-ws)
        
        x-ws = *ws %x0A *ws
        ]]></artwork>
</figure>
<section title="Resynchronization" anchor="Section_3_1">
<t>Since control characters are not permitted inside JSON string values and JSON objects MUST be separated by commas inside a JSON array, the sequence '}' *ws LF *ws '{' can only occur at the end of one log entry and the start of the next:'</t>
<figure>
<artwork>
<![CDATA[
        Boundary = end-object x-ws begin-object
        ]]></artwork>
</figure>
</section>
</section>
<section title="Tag Specification" anchor="Section_4">
<t>JSON-L is limited to an encoding and does not impose semantics on the JSON tags or values.</t>
<t>The W3C Extended Log File format [W3C.WD-logfile-960221] defines a set of tags which MAY be used as tags in the JSON object encoding.</t>
<t>[W3C.WD-logfile-960221] specifies this example: </t>
<figure>
<artwork>
<![CDATA[
#Version: 1.0
#Date: 12-Jan-1996 00:00:00
#Fields: time cs-method cs-uri
00:34:23 GET /foo/bar.html
12:21:16 GET /foo/bar.html
12:45:52 GET /foo/bar.html
12:57:34 GET /foo/bar.html
]]></artwork>
</figure>
<t>The corresponding JSON-L encoding is: </t>
<figure>
<artwork>
<![CDATA[
{ "Version": 1.0,
  "Date": "12-Jan-1996 00:00:00"}
    
{"time": "00:34:23", "cs-method" : "GET", "cs-uri": "/foo/bar.html}
{"time": "12:21:16", "cs-method" : "GET", "cs-uri": "/foo/bar.html}
{"time": "12:45:52", "cs-method" : "GET", "cs-uri": "/foo/bar.html}
{"time": "12:57:34", "cs-method" : "GET", "cs-uri": "/foo/bar.html}
]]></artwork>
</figure>
<t>Although the JSON-L encoding is rather less compact than the WD-Logfile format, it is considerably more flexible. It is not necessary for every entry to specify every field being logged. A writer can add the information that is appropriate in the circumstances. </t>
</section>
<section title="Security Considerations" anchor="Section_5">
<t>The security considerations for JSON-L are essentially the same as those for the JSON encoding on which it is based. </t>
<t>Specifically, since JSON's syntax is borrowed from Javascript it is possible to use the "eval ()" function in that language to parse entries in a JSON-L log. This constitutes an unacceptable security risk as the text could contain executable code along with data declarations. The same risk may exist in other languages that provide similar functions that execute data as code. </t>
</section>
<section title="IANA Considerations" anchor="Section_6">
<t>The MIME media type for JSON-Log text is application/json-l.</t>
<t>Type name: application</t>
<t>Subtype name: json-l</t>
<t>Required parameters: n/a</t>
<t>Optional parameters: n/a</t>
<t>Encoding considerations: binary</t>
<t>Security considerations: See [this], Section TBS.</t>
<t>Interoperability considerations: Described in [this]</t>
<t>Published specification: [this]</t>
<t>Applications that use this media type: None (so far)</t>
<t>Additional information:</t>
<figure>
<artwork>
<![CDATA[
        Magic number(s): n/a
        File extension(s): .jsonl
        Macintosh file type code(s): TEXT
        ]]></artwork>
</figure>
<t>Person &amp; email address to contact for further information: Phillip Hallam-Baker &lt;phill@hallambaker.com&gt; </t>
<t>Intended usage: COMMON </t>
<t>Restrictions on usage: none</t>
<t>Author: Phillip Hallam-Baker</t>
<t>Change controller: Phillip Hallam-Baker &lt;phill@hallambaker.com&gt;</t>
<t>Note: No "charset" parameter is defined for this registration. Adding one really has no effect on compliant recipients. </t>
</section>
<section title="Acnowledgements" anchor="Section_7">
<t>This is a minor modification of the JSON encoding developed by Douglas Crockford. Nico Williams provided useful advice on the resynchronization scheme. </t>
</section>
</middle>
<back>
<references title="Normative References">
<reference anchor="W3C.WD-logfile-960221">
<front>
<title>Extended Log File Format</title>
<author fullname="Phillip M. Hallam-Baker" initials="P" surname="Hallam-Baker">
<organization/>
<address>
</address>
</author>
<author fullname="Brian Behlendorf" initials="B" surname="Behlendorf">
<organization/>
<address>
</address>
</author>
<date day="21" month="February" year="1996"/>
</front>
<seriesInfo name="W3C NOTE" value="WD-logfile-960221"/>
<format type="HTML" target="http://www.w3.org/TR/WD-logfile-960221"/>
</reference>
<reference anchor="RFC7159">
<front>
<title>The JavaScript Object Notation (JSON) Data Interchange Format</title>
<author fullname="T. Bray" initials="T." surname="Bray">
<organization/>
<address>
</address>
</author>
<date month="March" year="2014"/>
</front>
<seriesInfo name="RFC" value="7159"/>
<format type="TXT" target="http://www.rfc-editor.org/rfc/rfc7159.txt" octets="27451"/>
</reference>
<reference anchor="RFC2119">
<front>
<title>Key words for use in RFCs to Indicate Requirement Levels</title>
<author fullname="Scott Bradner" initials="S." surname="Bradner">
<organization>Harvard University</organization>
<address>
</address>
</author>
<date month="March" year="1997"/>
<keyword>keyword</keyword>
</front>
<seriesInfo name="BCP" value="14"/>
<seriesInfo name="RFC" value="2119"/>
<format type="TXT" target="http://www.rfc-editor.org/rfc/rfc2119.txt" octets="4723"/>
<format type="HTML" target="http://xml.resource.org/public/rfc/html/rfc2119.html" octets="17970"/>
<format type="XML" target="http://xml.resource.org/public/rfc/xml/rfc2119.xml" octets="5777"/>
</reference>
</references>
</back>
</rfc>
