json_encode

Supported Versions: PHP 5 >= 5.2.0, PHP 7, PHP 8, PECL json >= 1.2.0
Returns the JSON representation of a value
<?php json_encode(mixed $value, int $flags = 0, int $depth = 512): string|false
<?php         file_put_contents(

            $this->cacheFilename,

            json_encode($data),

            LOCK_EX

        );

    }
<?php             is_object($this->value) && method_exists($this->value, '__toString') => $this->value->__toString(),

            is_object($this->value) && method_exists($this->value, 'toString') => $this->value->toString(),

            $this->value instanceof \Illuminate\Testing\TestResponse => $this->value->getContent(), // @phpstan-ignore-line

            is_array($this->value) => json_encode($this->value, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),

            $this->value instanceof Traversable => json_encode(iterator_to_array($this->value), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),

            $this->value instanceof JsonSerializable => json_encode($this->value->jsonSerialize(), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),

            is_object($this->value) && method_exists($this->value, 'toArray') => json_encode($this->value->toArray(), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),
<?php             is_object($this->value) && method_exists($this->value, 'toString') => $this->value->toString(),

            $this->value instanceof \Illuminate\Testing\TestResponse => $this->value->getContent(), // @phpstan-ignore-line

            is_array($this->value) => json_encode($this->value, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),

            $this->value instanceof Traversable => json_encode(iterator_to_array($this->value), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),

            $this->value instanceof JsonSerializable => json_encode($this->value->jsonSerialize(), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),

            is_object($this->value) && method_exists($this->value, 'toArray') => json_encode($this->value->toArray(), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),

            default => InvalidExpectationValue::expected('array|object|string'),
<?php             $this->value instanceof \Illuminate\Testing\TestResponse => $this->value->getContent(), // @phpstan-ignore-line

            is_array($this->value) => json_encode($this->value, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),

            $this->value instanceof Traversable => json_encode(iterator_to_array($this->value), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),

            $this->value instanceof JsonSerializable => json_encode($this->value->jsonSerialize(), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),

            is_object($this->value) && method_exists($this->value, 'toArray') => json_encode($this->value->toArray(), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),

            default => InvalidExpectationValue::expected('array|object|string'),

        };
<?php             is_array($this->value) => json_encode($this->value, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),

            $this->value instanceof Traversable => json_encode(iterator_to_array($this->value), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),

            $this->value instanceof JsonSerializable => json_encode($this->value->jsonSerialize(), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),

            is_object($this->value) && method_exists($this->value, 'toArray') => json_encode($this->value->toArray(), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),

            default => InvalidExpectationValue::expected('array|object|string'),

        };
<?php     {

        $data = ['value' => $value instanceof Stringable ? $value->__toString() : $value];



        $_ENV[self::GLOBAL_PREFIX.$key] = json_encode($data, JSON_THROW_ON_ERROR);

    }
<?php })->with(['my-datas-set-value']);



test('pass with `toArray`', function () {

    TestSuite::getInstance()->snapshots->save(json_encode(['key' => $this->snapshotable], JSON_PRETTY_PRINT));



    $object = new class($this->snapshotable)

    {
<?php });



test('pass with array', function () {

    TestSuite::getInstance()->snapshots->save(json_encode(['key' => $this->snapshotable], JSON_PRETTY_PRINT));



    expect([

        'key' => $this->snapshotable,
<?php });



test('pass with `toSnapshot`', function () {

    TestSuite::getInstance()->snapshots->save(json_encode(['key' => $this->snapshotable], JSON_PRETTY_PRINT));



    $object = new class($this->snapshotable)

    {
<?php         public function toSnapshot()

        {

            return json_encode([

                'key' => $this->snapshotable,

            ], JSON_PRETTY_PRINT);

        }

    };
<?php     try {

        $xml = new SimpleXMLElement(preg_replace("/(<\/?)(\w+):([^>]*>)/", '$1$2$3', $rawXmlContent));



        return json_decode(json_encode((array) $xml), true);

    } catch (Exception $exception) {

        throw new XmlParseException($exception->getMessage(), $exception->getCode(), $exception->getPrevious());

    }