Json and pimcore_cache_item?


In a pimcore6 site inside a twig view, I try to transforme a DataObject into json for JavaScript need.
Usually, I use something like that :
var user = {{ user|json_encode|raw }};

But I get :
var user = {"__pimcore_cache_item":“object_65”};

In pimcore5, I get something like that (more usefull :slight_smile: ):

var siteElement = {“o_classId”:“9”,“o_className”:“siteElement”,“name”:“S1gpt5”,“type_element”:“1”,“geolocalization”:…

So how to get my nicely json conversion ? I tried also the function json_encode() inside the controller but get also this pimcore_cache_item …

What am I missing ?

Thanks you for the help.

Hello, a few more information :slight_smile:

I upgraded to pimcore to 6.2.1 without more success.
I get “pimcore_cache_item” every time I try to encode in json.

If I dump my user (dump($this->getUser())) in my controller, I get :
/CustomerController.php&line=109#line109) on line 109: User^ {#5153#o_classId: “1” #o_className: “User” #username: “adminEF” #firstname: “Admin” #lastname: “Admin”

But (dump(json_encode($this->getUser()))), give:
/CustomerController.php&line=109#line109) on line 109: “{”__pimcore_cache_item":“object_65”}"

You can still do it this way

but handle with care because this wasn’t the goal of making the variables protected :slight_smile: