public function encodeJson($data): string
    {
        if ($data instanceof JsonSerializable) {
            $data = $data->jsonSerialize();
        }

        $result = json_encode($this->utf8Encoding->encodeUtf8($data), 512, JSON_THROW_ON_ERROR);

        if ($result === false) {
            throw new JsonException('Json encoding failed');
        }

        return $result;
    }
public function encodeJson($data): string
    {
        if ($data instanceof JsonSerializable) {
            $data = $data->jsonSerialize();
        }

        $result = json_encode($this->utf8Encoding->encodeUtf8($data), 512, JSON_THROW_ON_ERROR);

        if ($result === false) {
            throw new JsonException('Json encoding failed');
        }

        return $result;
    }
public function encodeJson ( $ data ) : string { if ( $ data instanceof JsonSerializable ) { $ data = $ data -> jsonSerialize ( ) ; } $ result = json_encode ( $ this -> utf8Encoding -> encodeUtf8 ( $ data ) , 512 , JSON_THROW_ON_ERROR ) ; if ( $ result === false ) { throw new JsonException ( 'Json encoding failed' ) ; } return $ result ; }
Encode an array to JSON.

Also makes sure the data is encoded in UTF-8.

@param mixed $data the array to encode in JSON

@throws JsonException

@return string the JSON encoded string
Encode an array to JSON .