Eduard Florinescu Eduard Florinescu - 10 months ago 76
JSON Question

How to save the output of a console.log(object) to a file?

I tried with

, but it doesn't go down on the whole structure and hierarchy.

On the other hand
does that but I cannot save it.

In the
output, I could have expanded one by one all the children and select and copy/paste but the structure is to big for that.


Update: You can now just right click

Right click > Save as in the Console panel to save the logged messages to a file.

Original Answer:

You can use this devtools snippet shown below to create a method. It creates a FileBlob from the input, and then automatically downloads it.

(function(console){ = function(data, filename){

    if(!data) {
        console.error(' No data')

    if(!filename) filename = 'console.json'

    if(typeof data === "object"){
        data = JSON.stringify(data, undefined, 4)

    var blob = new Blob([data], {type: 'text/json'}),
        e    = document.createEvent('MouseEvents'),
        a    = document.createElement('a') = filename
    a.href = window.URL.createObjectURL(blob)
    a.dataset.downloadurl =  ['text/json',, a.href].join(':')
    e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)