<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.bson.functions.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'fr',
  ),
  'this' => 
  array (
    0 => 'function.mongodb.bson-tojson.php',
    1 => 'MongoDB\\BSON\\toJSON',
    2 => 'Retourne la repr&eacute;sentation JSON &eacute;tendue h&eacute;rit&eacute;e d\'une valeur BSON',
  ),
  'up' => 
  array (
    0 => 'ref.bson.functions.php',
    1 => 'Fonctions',
  ),
  'prev' => 
  array (
    0 => 'function.mongodb.bson-tocanonicalextendedjson.php',
    1 => 'MongoDB\\BSON\\toCanonicalExtendedJSON',
  ),
  'next' => 
  array (
    0 => 'function.mongodb.bson-tophp.php',
    1 => 'MongoDB\\BSON\\toPHP',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/mongodb/functions/bson/tojson.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.mongodb.bson-tojson" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoDB\BSON\toJSON</h1>
  <p class="verinfo">(mongodb &gt;=1.0.0)</p><p class="refpurpose"><span class="refname">MongoDB\BSON\toJSON</span> &mdash; <span class="dc-title">Retourne la représentation JSON étendue héritée d&#039;une valeur BSON</span></p>

 </div>

 <div id="function.mongodb.bson-tojson-refsynopsisdiv">
  <div class="warning"><strong class="warning">Avertissement</strong>
   <p class="para">
    Cette fonction a été <em>DÉPRÉCIÉE</em> depuis la version 1.20.0 de l&#039;extension
    et a été supprimée dans la version 2.0. Les applications devraient utiliser
    <span class="methodname"><a href="mongodb-bson-document.tocanonicalextendedjson.php" class="methodname">MongoDB\BSON\Document::toCanonicalExtendedJSON()</a></span> ou
    <span class="methodname"><a href="mongodb-bson-document.torelaxedextendedjson.php" class="methodname">MongoDB\BSON\Document::toRelaxedExtendedJSON()</a></span> à la place.
   </p>
  </div>
 </div>


 <div class="refsect1 description" id="refsect1-function.mongodb.bson-tojson-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>MongoDB\BSON\toJSON</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$bson</code></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="para rdfs-comment">
   Convertit une chaîne BSON en sa <a href="https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/" class="link external">&raquo;&nbsp;représentation JSON étendue héritée</a>.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
    Il existe plusieurs formats JSON pour représenter BSON. Cette fonction
    implémente le &quot;strict mode&quot; défini dans
    <a href="https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/" class="link external">&raquo;&nbsp;MongoDB Extended JSON</a>,
    qui a été remplacé par les formats canoniques et étendues définis dans la
    <a href="https://github.com/mongodb/specifications/blob/master/source/extended-json/extended-json.md" class="link external">&raquo;&nbsp;spécification JSON étendue</a>
    et implémenté par <span class="function"><a href="function.mongodb.bson-tocanonicalextendedjson.php" class="function">MongoDB\BSON\toCanonicalExtendedJSON()</a></span>
    et <span class="function"><a href="function.mongodb.bson-torelaxedextendedjson.php" class="function">MongoDB\BSON\toRelaxedExtendedJSON()</a></span>, respectivement.
   </span>
  </p></blockquote>
  <div class="warning"><strong class="warning">Avertissement</strong>
   <p class="simpara">
    <a href="http://www.json.org/" class="link external">&raquo;&nbsp;JSON</a> ne prend pas en charge
    <a href="language.types.float.php#language.types.float.nan" class="link"><strong><code><a href="math.constants.php#constant.nan">NAN</a></code></strong></a> et
    <a href="function.is-infinite.php" class="link"><strong><code><a href="math.constants.php#constant.inf">INF</a></code></strong></a> et le
    format JSON étendu de MongoDB ne définit pas une autre représentation pour
    ces valeurs (<a href="https://github.com/mongodb/mongo-c-driver/tree/master/src/libbson" class="link external">&raquo;&nbsp;libbson</a> va
    produire <code class="literal">nan</code> et <code class="literal">inf</code> littéralement,
    qui ne peuvent pas être analysés comme JSON valide). Si on travaille avec
    BSON qui peut contenir des nombres non finis, utiliser svp
    <span class="function"><a href="function.mongodb.bson-tocanonicalextendedjson.php" class="function">MongoDB\BSON\toCanonicalExtendedJSON()</a></span> ou
    <span class="function"><a href="function.mongodb.bson-torelaxedextendedjson.php" class="function">MongoDB\BSON\toRelaxedExtendedJSON()</a></span>.
   </p>
  </div>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mongodb.bson-tojson-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <dl>
   
    <dt><code class="parameter">bson</code> (<span class="type"><a href="language.types.string.php" class="type string">string</a></span>)</dt>
    <dd>
     <p class="para">
      Valeur BSON à convertir.
     </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mongodb.bson-tojson-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   La valeur JSON convertie.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.mongodb.bson-tojson-errors">
  <h3 class="title">Erreurs / Exceptions</h3>
  <ul class="simplelist">
   <li>Lance une exception <span class="classname"><a href="class.mongodb-driver-exception-unexpectedvalueexception.php" class="classname">MongoDB\Driver\Exception\UnexpectedValueException</a></span> si l'entrée ne contient pas exactement un document BSON. Les raisons possibles comprennent, mais ne sont pas limitées à, BSON invalide, des données supplémentaires (après avoir lu un document BSON), ou une erreur imprévu de <a href="https://github.com/mongodb/mongo-c-driver/tree/master/src/libbson" class="link external">&raquo;&nbsp;libbson</a>.</li>
  </ul>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.mongodb.bson-tojson-changelog">
  <h3 class="title">Historique</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      
    <tr>
        <td>PECL mongodb 2.0.0</td>
        <td>
            Cette fonction a été supprimée.
        </td>
    </tr>


     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mongodb.bson-tojson-examples">
  <h3 class="title">Exemples</h3>
  <div class="example" id="example-1">
   <p><strong>Exemple #1 Exemple avec <span class="function"><strong>MongoDB\BSON\toJSON()</strong></span></strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$documents </span><span style="color: #007700">= [<br />    [ </span><span style="color: #DD0000">'null' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">null </span><span style="color: #007700">],<br />    [ </span><span style="color: #DD0000">'boolean' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">true </span><span style="color: #007700">],<br />    [ </span><span style="color: #DD0000">'string' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'foo' </span><span style="color: #007700">],<br />    [ </span><span style="color: #DD0000">'int32' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">123 </span><span style="color: #007700">],<br />    [ </span><span style="color: #DD0000">'int64' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">4294967295 </span><span style="color: #007700">],<br />    [ </span><span style="color: #DD0000">'double' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">1.0</span><span style="color: #007700">, ],<br />    [ </span><span style="color: #DD0000">'nan' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">NAN </span><span style="color: #007700">],<br />    [ </span><span style="color: #DD0000">'pos_inf' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">INF </span><span style="color: #007700">],<br />    [ </span><span style="color: #DD0000">'neg_inf' </span><span style="color: #007700">=&gt; -</span><span style="color: #0000BB">INF </span><span style="color: #007700">],<br />    [ </span><span style="color: #DD0000">'array' </span><span style="color: #007700">=&gt; [ </span><span style="color: #DD0000">'foo'</span><span style="color: #007700">, </span><span style="color: #DD0000">'bar' </span><span style="color: #007700">]],<br />    [ </span><span style="color: #DD0000">'document' </span><span style="color: #007700">=&gt; [ </span><span style="color: #DD0000">'foo' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'bar' </span><span style="color: #007700">]],<br />    [ </span><span style="color: #DD0000">'oid' </span><span style="color: #007700">=&gt; new </span><span style="color: #0000BB">MongoDB\BSON\ObjectId</span><span style="color: #007700">(</span><span style="color: #DD0000">'56315a7c6118fd1b920270b1'</span><span style="color: #007700">) ],<br />    [ </span><span style="color: #DD0000">'dec128' </span><span style="color: #007700">=&gt; new </span><span style="color: #0000BB">MongoDB\BSON\Decimal128</span><span style="color: #007700">(</span><span style="color: #DD0000">'1234.5678'</span><span style="color: #007700">) ],<br />    [ </span><span style="color: #DD0000">'binary' </span><span style="color: #007700">=&gt; new </span><span style="color: #0000BB">MongoDB\BSON\Binary</span><span style="color: #007700">(</span><span style="color: #DD0000">'foo'</span><span style="color: #007700">, </span><span style="color: #0000BB">MongoDB\BSON\Binary</span><span style="color: #007700">::</span><span style="color: #0000BB">TYPE_GENERIC</span><span style="color: #007700">) ],<br />    [ </span><span style="color: #DD0000">'date' </span><span style="color: #007700">=&gt; new </span><span style="color: #0000BB">MongoDB\BSON\UTCDateTime</span><span style="color: #007700">(</span><span style="color: #0000BB">1445990400000</span><span style="color: #007700">) ],<br />    [ </span><span style="color: #DD0000">'timestamp' </span><span style="color: #007700">=&gt; new </span><span style="color: #0000BB">MongoDB\BSON\Timestamp</span><span style="color: #007700">(</span><span style="color: #0000BB">1234</span><span style="color: #007700">, </span><span style="color: #0000BB">5678</span><span style="color: #007700">) ],<br />    [ </span><span style="color: #DD0000">'regex' </span><span style="color: #007700">=&gt; new </span><span style="color: #0000BB">MongoDB\BSON\Regex</span><span style="color: #007700">(</span><span style="color: #DD0000">'pattern'</span><span style="color: #007700">, </span><span style="color: #DD0000">'i'</span><span style="color: #007700">) ],<br />    [ </span><span style="color: #DD0000">'code' </span><span style="color: #007700">=&gt; new </span><span style="color: #0000BB">MongoDB\BSON\Javascript</span><span style="color: #007700">(</span><span style="color: #DD0000">'function() { return 1; }'</span><span style="color: #007700">) ],<br />    [ </span><span style="color: #DD0000">'code_ws' </span><span style="color: #007700">=&gt; new </span><span style="color: #0000BB">MongoDB\BSON\Javascript</span><span style="color: #007700">(</span><span style="color: #DD0000">'function() { return a; }'</span><span style="color: #007700">, [</span><span style="color: #DD0000">'a' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">1</span><span style="color: #007700">]) ],<br />    [ </span><span style="color: #DD0000">'minkey' </span><span style="color: #007700">=&gt; new </span><span style="color: #0000BB">MongoDB\BSON\MinKey </span><span style="color: #007700">],<br />    [ </span><span style="color: #DD0000">'maxkey' </span><span style="color: #007700">=&gt; new </span><span style="color: #0000BB">MongoDB\BSON\MaxKey </span><span style="color: #007700">],<br />];<br /><br />foreach (</span><span style="color: #0000BB">$documents </span><span style="color: #007700">as </span><span style="color: #0000BB">$document</span><span style="color: #007700">) {<br />    </span><span style="color: #0000BB">$bson </span><span style="color: #007700">= </span><span style="color: #0000BB">MongoDB\BSON\fromPHP</span><span style="color: #007700">(</span><span style="color: #0000BB">$document</span><span style="color: #007700">);<br />    echo </span><span style="color: #0000BB">MongoDB\BSON\toJSON</span><span style="color: #007700">(</span><span style="color: #0000BB">$bson</span><span style="color: #007700">), </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>L&#039;exemple ci-dessus va afficher :</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">{ &quot;null&quot; : null }
{ &quot;boolean&quot; : true }
{ &quot;string&quot; : &quot;foo&quot; }
{ &quot;int32&quot; : 123 }
{ &quot;int64&quot; : 4294967295 }
{ &quot;double&quot; : 1.0 }
{ &quot;nan&quot; : nan }
{ &quot;pos_inf&quot; : inf }
{ &quot;neg_inf&quot; : -inf }
{ &quot;array&quot; : [ &quot;foo&quot;, &quot;bar&quot; ] }
{ &quot;document&quot; : { &quot;foo&quot; : &quot;bar&quot; } }
{ &quot;oid&quot; : { &quot;$oid&quot; : &quot;56315a7c6118fd1b920270b1&quot; } }
{ &quot;dec128&quot; : { &quot;$numberDecimal&quot; : &quot;1234.5678&quot; } }
{ &quot;binary&quot; : { &quot;$binary&quot; : &quot;Zm9v&quot;, &quot;$type&quot; : &quot;00&quot; } }
{ &quot;date&quot; : { &quot;$date&quot; : 1445990400000 } }
{ &quot;timestamp&quot; : { &quot;$timestamp&quot; : { &quot;t&quot; : 5678, &quot;i&quot; : 1234 } } }
{ &quot;regex&quot; : { &quot;$regex&quot; : &quot;pattern&quot;, &quot;$options&quot; : &quot;i&quot; } }
{ &quot;code&quot; : { &quot;$code&quot; : &quot;function() { return 1; }&quot; } }
{ &quot;code_ws&quot; : { &quot;$code&quot; : &quot;function() { return a; }&quot;, &quot;$scope&quot; : { &quot;a&quot; : 1 } } }
{ &quot;minkey&quot; : { &quot;$minKey&quot; : 1 } }
{ &quot;maxkey&quot; : { &quot;$maxKey&quot; : 1 } }</pre>
</div>
   </div>
  </div>
 </div>



 <div class="refsect1 seealso" id="refsect1-function.mongodb.bson-tojson-seealso">
  <h3 class="title">Voir aussi</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.mongodb.bson-fromjson.php" class="function" rel="rdfs-seeAlso">MongoDB\BSON\fromJSON()</a> - Retourne la repr&eacute;sentation BSON d'une valeur JSON</span></li>
   <li><span class="function"><a href="function.mongodb.bson-tocanonicalextendedjson.php" class="function" rel="rdfs-seeAlso">MongoDB\BSON\toCanonicalExtendedJSON()</a> - Renvoie la repr&eacute;sentation JSON &eacute;tendue canonique d'une valeur BSON</span></li>
   <li><span class="function"><a href="function.mongodb.bson-torelaxedextendedjson.php" class="function" rel="rdfs-seeAlso">MongoDB\BSON\toRelaxedExtendedJSON()</a> - Renvoie la repr&eacute;sentation JSON &eacute;tendue d&eacute;tendue d'une valeur BSON</span></li>
   <li><a href="https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/" class="link external">&raquo;&nbsp;MongoDB JSON Etendu</a></li>
   <li><a href="https://www.mongodb.com/docs/manual/reference/bson-types/" class="link external">&raquo;&nbsp;MongoDB BSON</a></li>
  </ul>
 </div>


</div><?php manual_footer($setup); ?>