Copying variable contents to clipboard while debugging in Visual Studio Code

I found two ways to do that, both of which are a bit hacky (in my eyes).

Use console.log

I think there will be a limit to the size of the string that this can output, but it was satisfactory for my requirements.

  1. In the debug console, write console.log(JSON.stringify(yourJsonObject))
  2. Copy the resulting output from the debug console. That can be a bit tedious for long strings, but a combination of mouse and keyboard (ctrl-shift-end) worked ok for me.

Use a watch (limited to 10’000 characters)

This method only works up to a limited size of the resulting json string (it looks like 10’000 characters).

  1. Set a breakpoint in a reasonable location where your variable is in scope and start your app.
  2. Go to the debug view, add a watch for a temporary variable, e.g. tmpJson
  3. Get your breakpoint to hit.
  4. In the debug console, write var tmpJson = JSON.stringify(yourJsonObject)
  5. This will now have populated the watched variable tmpJson with the string representation of your json object
  6. In the debug view, right click on the watched variable, click copy.

If 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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)