4139N/A<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 4139N/A <
meta http-
equiv="Content-Type" content="text/html; charset=utf-8" />
4139N/A <
title>RFC Conformance — Jansson 2.7 documentation</
title>
4139N/A var DOCUMENTATION_OPTIONS = {
4139N/A <
li class="right" style="margin-right: 10px">
4139N/A accesskey="I">index</
a></
li>
4139N/A accesskey="N">next</
a> |</
li>
4139N/A accesskey="P">previous</
a> |</
li>
4139N/A <
div class="documentwrapper">
4139N/A <
div class="section" id="rfc-conformance">
4139N/A<
span id="id1"></
span><
h1>RFC Conformance<
a class="headerlink" href="#rfc-conformance" title="Permalink to this headline">¶</
a></
h1>
4139N/Afor JavaScript Object Notation (JSON)”</
em>.</
p>
4139N/A<
div class="section" id="character-encoding">
4139N/A<
h2>Character Encoding<
a class="headerlink" href="#character-encoding" title="Permalink to this headline">¶</
a></
h2>
4139N/A<
p>Jansson only supports UTF-8 encoded JSON texts. It does not support or
4139N/Aauto-detect any of the other encodings mentioned in the RFC, namely
4139N/AUTF-16LE, UTF-16BE, UTF-32LE or UTF-32BE. Pure ASCII is supported, as
4139N/Ait’s a subset of UTF-8.</
p>
4139N/A<
div class="section" id="strings">
4139N/A<
h2>Strings<
a class="headerlink" href="#strings" title="Permalink to this headline">¶</
a></
h2>
4139N/A<
p>JSON strings are mapped to C-style null-terminated character arrays,
4139N/Aand UTF-8 encoding is used internally.</
p>
4139N/A<
p>All Unicode codepoints U+0000 through U+10FFFF are allowed in string
4139N/Avalues. However, U+0000 is not allowed in object keys because of API
4139N/A<
p>Unicode normalization or any other transformation is never performed
4139N/Aon any strings (string values or object keys). When checking for
4139N/Aequivalence of strings or object keys, the comparison is performed
4139N/Abyte by byte between the original UTF-8 representations of the
4139N/A<
div class="section" id="numbers">
4139N/A<
h2>Numbers<
a class="headerlink" href="#numbers" title="Permalink to this headline">¶</
a></
h2>
4139N/A<
div class="section" id="real-vs-integer">
4139N/A<
span id="id2"></
span><
h3>Real vs. Integer<
a class="headerlink" href="#real-vs-integer" title="Permalink to this headline">¶</
a></
h3>
4139N/A<
p>JSON makes no distinction between real and integer numbers; Jansson
4139N/Adoes. Real numbers are mapped to the <
tt class="docutils literal"><
span class="pre">double</
span></
tt> type and integers to
4139N/Athe <
tt class="docutils literal"><
span class="pre">json_int_t</
span></
tt> type, which is a typedef of <
tt class="docutils literal"><
span class="pre">long</
span> <
span class="pre">long</
span></
tt> or
4139N/A<
tt class="docutils literal"><
span class="pre">long</
span></
tt>, depending on whether <
tt class="docutils literal"><
span class="pre">long</
span> <
span class="pre">long</
span></
tt> is supported by your
4139N/A<
p>A JSON number is considered to be a real number if its lexical
4139N/Arepresentation includes one of <
tt class="docutils literal"><
span class="pre">e</
span></
tt>, <
tt class="docutils literal"><
span class="pre">E</
span></
tt>, or <
tt class="docutils literal"><
span class="pre">.</
span></
tt>; regardless if
4139N/Aits actual numeric value is a true integer (
e.g., all of <
tt class="docutils literal"><
span class="pre">1E6</
span></
tt>,
4139N/A<
tt class="docutils literal"><
span class="pre">3.0</
span></
tt>, <
tt class="docutils literal"><
span class="pre">400E-2</
span></
tt>, and <
tt class="docutils literal"><
span class="pre">3.14E3</
span></
tt> are mathematical integers, but
4139N/Awill be treated as real values). With the <
tt class="docutils literal"><
span class="pre">JSON_DECODE_INT_AS_REAL</
span></
tt>
4139N/Adecoder flag set all numbers are interpreted as real.</
p>
4139N/A<
p>All other JSON numbers are considered integers.</
p>
4139N/A<
p>When encoding to JSON, real values are always represented
4139N/Awith a fractional part;
e.g., the <
tt class="docutils literal"><
span class="pre">double</
span></
tt> value 3.0 will be
4139N/Arepresented in JSON as <
tt class="docutils literal"><
span class="pre">3.0</
span></
tt>, not <
tt class="docutils literal"><
span class="pre">3</
span></
tt>.</
p>
4139N/A<
div class="section" id="overflow-underflow-precision">
4139N/A<
h3>Overflow, Underflow & Precision<
a class="headerlink" href="#overflow-underflow-precision" title="Permalink to this headline">¶</
a></
h3>
4139N/A<
p>Real numbers whose absolute values are too small to be represented in
4139N/Aa C <
tt class="docutils literal"><
span class="pre">double</
span></
tt> will be silently estimated with 0.0. Thus, depending on
4139N/Aplatform, JSON numbers very close to zero such as 1E-999 may result in
4139N/A<
p>Real numbers whose absolute values are too large to be represented in
4139N/Aa C <
tt class="docutils literal"><
span class="pre">double</
span></
tt> will result in an overflow error (a JSON decoding
4139N/Aerror). Thus, depending on platform, JSON numbers like 1E+999 or
4139N/A-1E+999 may result in a parsing error.</
p>
4139N/A<
p>Likewise, integer numbers whose absolute values are too large to be
4139N/Arepresented in the <
tt class="docutils literal"><
span class="pre">json_int_t</
span></
tt> type (see above) will result in an
4139N/Aoverflow error (a JSON decoding error). Thus, depending on platform,
4139N/AJSON numbers like 1000000000000000 may result in parsing error.</
p>
4139N/A<
p>Parsing JSON real numbers may result in a loss of precision. As long
4139N/Aas overflow does not occur (
i.e. a total loss of precision), the
4139N/Arounded approximate value is silently used. Thus the JSON number
4139N/A1.000000000000000005 may, depending on platform, result in the
4139N/A<
tt class="docutils literal"><
span class="pre">double</
span></
tt> value 1.0.</
p>
4139N/A<
div class="section" id="signed-zeros">
4139N/A<
h3>Signed zeros<
a class="headerlink" href="#signed-zeros" title="Permalink to this headline">¶</
a></
h3>
4139N/A<
p>JSON makes no statement about what a number means; however Javascript
4139N/A(ECMAscript) does state that +0.0 and -0.0 must be treated as being
4139N/Adistinct values,
i.e. -0.0 ≠ 0.0. Jansson relies on the
4139N/Aunderlying floating point library in the C environment in which it is
4139N/Acompiled. Therefore it is platform-dependent whether 0.0 and -0.0 will
4139N/Abe distinct values. Most platforms that use the IEEE 754
4139N/Afloating-point standard will support signed zeros.</
p>
4139N/A<
p>Note that this only applies to floating-point; neither JSON, C, or
4139N/AIEEE support the concept of signed integer zeros.</
p>
4139N/A<
div class="section" id="types">
4139N/A<
h3>Types<
a class="headerlink" href="#types" title="Permalink to this headline">¶</
a></
h3>
4139N/A<
p>No support is provided in Jansson for any C numeric types other than
4139N/A<
tt class="docutils literal"><
span class="pre">json_int_t</
span></
tt> and <
tt class="docutils literal"><
span class="pre">double</
span></
tt>. This excludes things such as unsigned
4139N/Atypes, <
tt class="docutils literal"><
span class="pre">long</
span> <
span class="pre">double</
span></
tt>, etc. Obviously, shorter types like <
tt class="docutils literal"><
span class="pre">short</
span></
tt>,
4139N/A<
tt class="docutils literal"><
span class="pre">int</
span></
tt>, <
tt class="docutils literal"><
span class="pre">long</
span></
tt> (if <
tt class="docutils literal"><
span class="pre">json_int_t</
span></
tt> is <
tt class="docutils literal"><
span class="pre">long</
span> <
span class="pre">long</
span></
tt>) and <
tt class="docutils literal"><
span class="pre">float</
span></
tt>
4139N/Aare implicitly handled via the ordinary C type coercion rules (subject
4139N/Ato overflow semantics). Also, no support or hooks are provided for any
4139N/Asupplemental “bignum” type add-on packages.</
p>
4139N/A <
div class="sphinxsidebar">
4139N/A <
div class="sphinxsidebarwrapper">
4139N/A<
li><
a class="reference internal" href="#">RFC Conformance</
a><
ul>
4139N/A<
li><
a class="reference internal" href="#character-encoding">Character Encoding</
a></
li>
4139N/A<
li><
a class="reference internal" href="#strings">Strings</
a></
li>
4139N/A<
li><
a class="reference internal" href="#numbers">Numbers</
a><
ul>
4139N/A<
li><
a class="reference internal" href="#real-vs-integer">Real vs. Integer</
a></
li>
4139N/A<
li><
a class="reference internal" href="#overflow-underflow-precision">Overflow, Underflow & Precision</
a></
li>
4139N/A<
li><
a class="reference internal" href="#signed-zeros">Signed zeros</
a></
li>
4139N/A<
li><
a class="reference internal" href="#types">Types</
a></
li>
4139N/A title="previous chapter">Tutorial</
a></
p>
4139N/A title="next chapter">Portability</
a></
p>
4139N/A <
ul class="this-page-menu">
4139N/A rel="nofollow">Show Source</
a></
li>
4139N/A<
div id="searchbox" style="display: none">
4139N/A <
input type="text" name="q" />
4139N/A <
input type="submit" value="Go" />
4139N/A <
input type="hidden" name="check_keywords" value="yes" />
4139N/A <
input type="hidden" name="area" value="default" />
4139N/A <
p class="searchtip" style="font-size: 90%">
4139N/A Enter search terms or a module, class or function name.
4139N/A <
div class="clearer"></
div>
4139N/A <
li class="right" style="margin-right: 10px">
4139N/A © Copyright 2009-2014, Petri Lehtinen.