<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.6 $ -->
<refentry xml:id="function.json-decode" xmlns="http://docbook.org/ns/docbook">
 <refnamediv>
  <refname>json_decode</refname>
  <refpurpose>Decodes a JSON string</refpurpose>
 </refnamediv>

 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis>
   <type>mixed</type><methodname>json_decode</methodname>
   <methodparam><type>string</type><parameter>json</parameter></methodparam>
   <methodparam choice="opt"><type>bool</type><parameter>assoc</parameter></methodparam>
  </methodsynopsis>
  <para>
   Takes a JSON encoded string and converts it into a PHP variable.
  </para>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    <varlistentry>
     <term><parameter>json</parameter></term>
     <listitem>
      <para>
       The <parameter>json</parameter> <type>string</type> being decoded.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>assoc</parameter></term>
     <listitem>
      <para>
       When &true;, returned <type>object</type>s will be converted into
       associative <type>array</type>s.
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   Returns an <type>object</type> or if the optional
   <parameter>assoc</parameter> parameter is &true;, an associative 
   <type>array</type> is instead returned.
  </para>
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <para>
   <example>
    <title><function>json_decode</function> examples</title>
    <programlisting role="php">
<![CDATA[
<?php
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';

var_dump(json_decode($json));
var_dump(json_decode($json, true));

?>
]]>
    </programlisting>
    &example.outputs;
    <screen>
<![CDATA[
object(stdClass)#1 (5) {
    ["a"] => int(1)
    ["b"] => int(2)
    ["c"] => int(3)
    ["d"] => int(4)
    ["e"] => int(5)
}

array(5) {
    ["a"] => int(1)
    ["b"] => int(2)
    ["c"] => int(3)
    ["d"] => int(4)
    ["e"] => int(5)
}
]]>
    </screen>
   </example>
   <example>
    <programlisting role="php">
<![CDATA[
<?php

$json = '{"foo-bar": 12345}';

$obj = json_decode($json);
print $obj->{'foo-bar'}; // 12345

?>
]]>
    </programlisting>
   </example>
  </para>
 </refsect1>

 <refsect1 role="notes">
  &reftitle.notes;
  <caution>
   <para>
    This function will return false if the JSON encoded data is deeper than
    127 elements.
   </para>
  </caution>
 </refsect1>

 <refsect1 role="changelog">
  &reftitle.changelog;
  <para>
   <informaltable>
    <tgroup cols="2">
     <thead>
      <row>
       <entry>&Version;</entry>
       <entry>&Description;</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry>5.2.3</entry>
       <entry>The nesting limit was increased from 20 to 128</entry>
      </row>
     </tbody>
    </tgroup>
   </informaltable>
  </para>
 </refsect1>

 <refsect1 role="seealso">
  &reftitle.seealso;
  <para>
   <simplelist>
    <member><function>json_encode</function></member>
   </simplelist>
  </para>
 </refsect1>
</refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->