Copy JSON from console.log in developer tool to clipboard?

186

66

Using Chrome Developer Tools, i have printed a JSON object with console.log.

is there a way that I can copy it to the clipboard?

Anagio

Posted 2014-07-05T05:53:53.563

Reputation: 2 518

Answers

338

If the right-click -> copy is not available you could try:

1 - Right-click the object and select "Store as global variable"

2 - The console will print the new variable's name, for example:

//temp1

3 - Type:

copy(temp1)   

The object is now available in your clipboard.

Tested in chrome 36

Bertrand

Posted 2014-07-05T05:53:53.563

Reputation: 3 496

3Bertrand's answer works like a charm. Should be selected as correct answer, @Anagio. – fmquaglia – 2014-09-25T18:50:05.743

3In Chrome 41 this returns undefined. – isherwood – 2015-03-20T14:32:50.163

@isherwood I've jsut tested in Chrome 41 and still works, you might be missing something. – Bertrand – 2015-03-20T17:56:58.830

what do you mean by " Right-click the object" ? – RollRoll – 2015-04-01T21:47:10.723

1@EdwinSnts Bertrand means in the Javascript console, after logging an object with console.log( myObject ), to right click on that object. It will give you a context menu with the "Store as global variable" feature. – BradGreens – 2015-05-08T16:37:20.943

10copy(temp1) works in Chrome 46, but copying a larger object (a jQuery.Event object), the clipboard gets [object Object]. – sealocal – 2015-11-09T19:33:07.890

5In Chrome copy(temp1) returns undefined but the object is available in your clipboard. – Suzana – 2016-01-27T16:42:54.663

1Does this work programatically too, or only through the console? (e.g forcing content on the user's clipboard) – Hanna – 2016-02-16T18:48:28.613

1Also, make sure <top frame> is selected or Store as Global Variable won't work. – JDavis – 2016-02-18T20:35:22.063

@Johannes seems to work programaticaly for me – rex – 2017-03-27T10:41:06.540

This is the best way to capture the JSON from console. Is there a Chrome extension that does this and downloads to a log file? – smokinguns – 2018-08-29T23:41:08.900

@sealocal: Yes, I also experienced this with a large object. Kind of irritating, because it is speacially on large objects this would be useful. – awe – 2018-09-28T06:59:47.407

So simple, I had no idea. Love it! – Jordan – 2019-08-27T19:44:31.560

1

Another simple method...from the console surround the json with JSON.stringify(yourobjecthere). Then highlight the text or optionally select the Copy button in the developer bar if it exceeds X number of rows. Hope this helps someone.

Example:

JSON.stringify(JSON.parse(window.atob(localStorage.getItem('C_C_M'))))

Rob

Posted 2014-07-05T05:53:53.563

Reputation: 111

0

Select the text in the console, then use right click -> copy

To copy the entire log (when I needed): hit ctrl-a (select all) then ctrl-c (copy)

Note: Since posting this I noticed sometimes it is necessary to select a little text before these steps work. Also for a long console output scroll to the top of the console and select a little text first. Grrr... still this is easier than saving as a file.

== Above is using Chrome 35 ==

Paul Lockwood

Posted 2014-07-05T05:53:53.563

Reputation: 258

1Doesn't work for me—it just copies the collapsed summary of the variable. – Michael Scheper – 2017-12-12T03:12:35.460