Object of type stdClass cannot be printed when received JSON response I have:
$result = $client-&gt;request('POST', 'http://'.$core_address.':'.$core_port.$core_uri, [
    'body' =&gt; json_encode([
        'a' =&gt; $a,
        'b' =&gt; $value['v'],
        'x' =&gt; $value['x'],
    ]),
    'headers' =&gt; [
            'Accept' =&gt; 'application/json', 
            'Content-Type' =&gt; 'application/json'
    ], 
]);
    
$output = json_decode($result-&gt;getBody());

i catch the output and print it like:
drupal_set_message($output);

problem is: if output just a flat string, it work like a charm
but when it receive json like:

{'x': ['Not a valid integer.'], 't': ['Not a valid string.'], 's':
['Not a valid string.']}
192.168.yyy.xxx - - [28/Jul/2016 00:14:59] &quot;PUT /Module HTTP/1.1&quot; 200 -

it give me error:

Uncaught PHP Exception Exception: &quot;Object of type stdClass cannot be
printed.&quot; at /path/to/Drupal/Core/Template/TwigExtension.php line 443,
referer: https://url.com/admin/core/my/module/path

why? why?
Short answer: because that is how the API was written.

Long answer is that they do not know how the object should be printed.

To cast an object to a string, you need the object to have a __toString method, which the object in question does not contain.

If you want to print the stringified version of the object then don't transform to an object using json_decode.