Sometimes when you need to examine the results of a JSON response, using your browser’s developer tools console just won’t cut the mustard. In such a case, a good alternative would be to copy the JSON object from the console and to view it in your text editor. It’s not quite as easy as ‘CMD + C’, ‘CMD + V’ though, so here’s a quick primer. Specifically, these instructions are for copy the response from Chrome’s Developer Tools console to Sublime text 2.
First, we need to copy the JSON object from the console:
// where res.data is the JSON object copy(JSON.stringify(res.data))
Now, if you don’t already have it, you’ll need to install the Sublime Text 2 package, ‘Pretty JSON’. I got it via Package Control. Read more about Package control and installing new packages here.
Once you have the package installed:
- Paste the copied object in your editor
- Press ‘CMD + SHIFT + P’ to open your package manager
- Search for ‘JSON’
- Select ‘Pretty JSON: Reformat (pretty print) JSON’
That’s it! You could also use the shortcut code for reformatting with Pretty JSON, which is ‘^ + CMD + J’