EDIT: as noted in the comments, this is not perfect, as for some variables you will get a “stackoverflow” response
As suggested by @Mr Han’s answer, here’s how you can do this:
Add a new way to view objects in Intellij debugger as json by
- Going to
File | Settings | Build, Execution, Deployment | Debugger | Data Views | Java Type Renderers - Click
+to add new renderer - Call it
JSON renderer - Supply
java.lang.ObjectforApply renderer to objects of type - Choose
Use following expression:and supply an expression like so:
if (null == this || this instanceof String)
return this;
new com.google.gson.GsonBuilder().setPrettyPrinting().create().toJson(this);
- Click
OK - Now when you choose
Copy Valueon a variable, it will copy as json.

Note: If you don’t want to change default behaviour, create a “default” renderer also with “use default renderer” settings, and put it first in the list, it will use that as default and you can switch to JSON on demand by right click on debugged variable -> use renderer: JSON Renderer.