Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<MongoDB\BSON\PackedArray::toPHPMongoDB\BSON\PackedArray::__toString>
^MongoDB\BSON\PackedArrayLast updated: Mon, 26 Oct 2026

MongoDB\BSON\PackedArray::toRelaxedExtendedJSON

(mongodb >=1.20.0)

MongoDB\BSON\PackedArray::toRelaxedExtendedJSON — Returns the Relaxed Extended JSON representation of the BSON array

Description

final public function MongoDB\BSON\PackedArray::toRelaxedExtendedJSON(): string

Converts the BSON array 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.

Parameters

This function has no parameters.

Return Values

Returns a string containing the » Relaxed Extended JSON representation of the BSON array.

Examples

Example #1 MongoDB\BSON\PackedArray::toRelaxedExtendedJSON() example

<?php

$array = [
    'foo',
    123,
    4294967295,
    new MongoDB\BSON\ObjectId('56315a7c6118fd1b920270b1'),
];

$packedArray = MongoDB\BSON\PackedArray::fromPHP($array);
echo $packedArray->toRelaxedExtendedJSON(), "\n";

?>

The above example will output:

[ "foo", 123, 4294967295, { "$oid" : "56315a7c6118fd1b920270b1" } ]

See Also


<MongoDB\BSON\PackedArray::toPHPMongoDB\BSON\PackedArray::__toString>
^MongoDB\BSON\PackedArrayLast updated: Mon, 26 Oct 2026