MongoDB\BSON\Document::toRelaxedExtendedJSON
Returns the Relaxed Extended JSON representation of the BSON document
&reftitle.description;
final public stringMongoDB\BSON\Document::toRelaxedExtendedJSON
Converts the BSON document to its
Relaxed Extended JSON
representation. The relaxed format prefers use of JSON type primitives at the
expense of type fidelity and is most suited for producing output that can be
easily consumed by web APIs and humans.
&reftitle.parameters;
&no.function.parameters;
&reftitle.returnvalues;
Returns a string containing the
Relaxed Extended JSON
representation of the BSON document.
&reftitle.examples;
MongoDB\BSON\Document::toRelaxedExtendedJSON example
null ],
[ 'boolean' => true ],
[ 'string' => 'foo' ],
[ 'int32' => 123 ],
[ 'int64' => 4294967295 ],
[ 'double' => 1.0 ],
[ 'nan' => NAN ],
[ 'pos_inf' => INF ],
[ 'neg_inf' => -INF ],
[ 'array' => [ 'foo', 'bar' ]],
[ 'document' => [ 'foo' => 'bar' ]],
[ 'oid' => new MongoDB\BSON\ObjectId('56315a7c6118fd1b920270b1') ],
[ 'dec128' => new MongoDB\BSON\Decimal128('1234.5678') ],
[ 'binary' => new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ],
[ 'date' => new MongoDB\BSON\UTCDateTime(1445990400000) ],
[ 'timestamp' => new MongoDB\BSON\Timestamp(1234, 5678) ],
[ 'regex' => new MongoDB\BSON\Regex('pattern', 'i') ],
[ 'code' => new MongoDB\BSON\Javascript('function() { return 1; }') ],
[ 'code_ws' => new MongoDB\BSON\Javascript('function() { return a; }', ['a' => 1]) ],
[ 'minkey' => new MongoDB\BSON\MinKey ],
[ 'maxkey' => new MongoDB\BSON\MaxKey ],
];
foreach ($documents as $document) {
$bson = MongoDB\BSON\Document::fromPHP($document);
echo $bson->toRelaxedExtendedJSON(), "\n";
}
?>
]]>
&example.outputs;
&reftitle.seealso;
MongoDB\BSON\Document::fromJSON
MongoDB\BSON\Document::toCanonicalExtendedJSON
MongoDB\BSON\toRelaxedExtendedJSON
Extended JSON Specification
BSON Types