I'm debugging in Visual Studio Code and I have a JSON object that I would like to copy as text to the clipboard.
Is this possible inside of Visual Studio Code?
I'm debugging in Visual Studio Code and I have a JSON object that I would like to copy as text to the clipboard.
Is this possible inside of Visual Studio Code?
I found two ways to do that, both of which are a bit hacky (in my eyes).
I think there will be a limit to the size of the string that this can output, but it was satisfactory for my requirements.
console.log(JSON.stringify(yourJsonObject))
This method only works up to a limited size of the resulting json string (it looks like 10'000 characters).
tmpJson
var tmpJson = JSON.stringify(yourJsonObject)
tmpJson
with the string representation of your json objectIf the string is too long, it cuts it off with a message like the following:
...,"typeName":"rouParallel","toolAssembly":{"id":"ASKA800201","description":"CeonoglodaloD50R6z5","c... (length: 80365)"
But it would work for smaller objects. Maybe this helps some people. It would be great to have this properly built-in with vscode.
toJSON()
method that skips properties. What you get on the console is not necessarily the same as what you get in the debugger.
Feb 12, 2020 at 16:32
json_encode($variable)
in Debug Console. But then you'd need a JSON formatter though.
May 14, 2020 at 9:30
There is an open issue regarding this: https://github.com/microsoft/vscode-java-debug/issues/624
Workaround :
(tested on Java, not JavaScript)
I have an easy workaround to copy anything you want:
JSON.stringify(yourJsonObject)
"
around the stringOpen a browser, such as Chrome, open the inspecting tool, go on the console and write:
copy(JSON.parse("PASTE_THE_STRING_HERE"));
The object is now copy on your keyboard !
The fastest way I found to do that on Visual Studio Code was
If you're in debug mode, you can copy any variable by writing copy() in the debug terminal.
This works with nested objects and also removes truncation and copies the complete value.
Tip: you can right click a variable, and click Copy as Expression
and then paste that in the copy-function.
str(long_object_here)
and this makes sure the truncation is removed
Nov 17, 2021 at 10:40
Tested in python debugger
Add the variable to Watch, but converted to string
str(myvar)
Right-click on the value of the watch, and select Copy Value
Now you should get the full value, even for very long values
(var name blurred out):
If you are debugging Python:
In the DEBUG CONSOLE type, for example:
import json
from pprint import pprint as pp
pp(json.dumps(outDetailsDict))
OUTPUT IS LIKE
{"": {"stn_ix": 43, "stn_name": "Historic Folsom Station (WB)", "name": "", },
...