Chrome DevTools Console: copying a JSON object to your clipboard

Google Chrome DevTools Console - copy JSON to clipboard

I use the Chrome DevTools Console a lot when debugging client-side JavaScript. I often use it to inspect JSON objects that could be generated from a variety of sources (e.g. Google Tag Manager data layers, AJAX responses, jQuery selectors, etc.). In some cases I wish to copy the JSON object to my clipboard so that I can paste it into my IDE for further inspection.

 


 

Here’s the simple one line of code that will do this for you. Paste this in your Chrome DevTools Console:

// refToJSONobj - reference to a JSON object
copy(refToJSONobj);

For example, if I want to copy the current state of Google Tag Manager’s data layer to my clipboard, I would use the following in my Chrome DevTools Console:

copy(window.dataLayer);

Chrome DevTools Console’s copy(object) function:

  • Gets the string representation of the object
  • Copies it to the clipboard

 


 

Did you find this helpful and think it would be beneficial for someone else? Share now!

Leave a Reply

Your email address will not be published. Required fields are marked *