How to Format JSON in Chrome: 5 Easy Ways
In this article
To format JSON in Chrome, you can use the built-in DevTools, a browser extension, or an online formatter. The quickest method is to open the JSON file in a new tab and press Ctrl+Shift+J (Windows) or Cmd+Option+J (Mac) to open DevTools, then paste the JSON into the Console and press Enter — Chrome will automatically pretty-print it. This guide covers all the reliable methods, including using the DevTools' built-in JSON viewer, the Console, extensions, and online tools.
What You'll Need
- Google Chrome (any recent version)
- A JSON string, file, or URL that returns JSON
- Optional: A JSON viewer extension (like JSON Viewer or JSON Formatter)
Step-by-Step
- Open the JSON in Chrome
If you have a JSON file, drag and drop it into a Chrome tab. If you have a URL that returns JSON (like an API endpoint), navigate to that URL. Chrome will display the raw JSON as plain text. - Use the built-in JSON viewer (if available)
In newer versions of Chrome, opening a.jsonfile or a URL withContent-Type: application/jsonautomatically shows a pretty-printed, collapsible tree view. If you see this, you're done — no further steps needed. If you see plain text, proceed to the next method. - Format via DevTools Console
Press F12 or Ctrl+Shift+I (Windows) / Cmd+Option+I (Mac) to open DevTools. Click the Console tab. Copy your JSON string, typeJSON.stringify(, paste the JSON, then close with, null, 2)and press Enter. For example:JSON.stringify({"name":"John"}, null, 2). The console will output the formatted JSON with indentation. - Use the Network tab for API responses
If you're testing an API, open DevTools, go to the Network tab, refresh the page, and click on the request that returns JSON. Then click the Response or Preview tab. The Preview tab shows a formatted, collapsible view; the Response tab shows raw text. To copy formatted JSON, right-click in the Preview tab and select Copy. - Install a JSON viewer extension
Go to the Chrome Web Store and search for "JSON Viewer" or "JSON Formatter". Install one with good ratings (e.g., JSON Viewer by gildas). Once installed, navigating to a JSON URL will automatically display a formatted, syntax-highlighted view with collapsible sections. - Use an online formatter
If you have JSON copied to your clipboard, go to a trusted online formatter likejsonformatter.orgorjsonlint.com. Paste the JSON and click "Process" or "Validate". The formatted output will appear, and you can copy it.
Common Mistakes
- Forgetting to escape quotes — When pasting JSON into the Console, if you manually type it, you must escape double quotes with backslashes. Better to copy-paste the raw JSON directly.
- Using the wrong DevTools tab — The Elements tab shows HTML, not JSON. Use the Console or Network tab.
- Expecting the built-in viewer on all files — Chrome only pretty-prints JSON if the file extension is
.jsonor the server sends the correct MIME type. A.txtfile with JSON content will show as plain text. - Not refreshing after installing an extension — After installing a JSON viewer, you may need to refresh the tab or reopen the URL for the extension to activate.
- Using
JSON.parseinstead ofJSON.stringify— To format, you needJSON.stringifywith thenull, 2arguments.JSON.parseonly parses, it doesn't format.
Tips
- Use the
null, 2parameters — In the Console method,nullis a replacer function (not needed) and2is the number of spaces for indentation. You can use4for wider indentation. - Copy formatted JSON easily — In the Console, right-click the output and select Copy to copy the formatted string.
- Bookmark a JSON URL — If you frequently check a JSON API, bookmark it; with a viewer extension, it will always open formatted.
- Use the
fetchcommand in Console — For a URL, you can typefetch('url').then(r=>r.json()).then(d=>console.log(JSON.stringify(d,null,2)))in the Console to fetch and format in one go. - Know the keyboard shortcut for DevTools — Ctrl+Shift+J (Windows) / Cmd+Option+J (Mac) opens DevTools directly to the Console.
Troubleshooting
- JSON appears as plain text even after using the built-in viewer — Check the file extension. If it's
.txtor no extension, rename it to.jsonor use the Console method. - Console shows an error like "Unexpected token" — This means your JSON is invalid. Use a validator like JSONLint to check for syntax errors (missing commas, trailing commas, unquoted keys).
- Extension not working — Ensure the extension is enabled for the site. Click the puzzle icon in the toolbar, find the extension, and allow it to access the site. Also try reloading the page.
- Network tab doesn't show the request — Make sure you have the Network tab open before triggering the request. Also, check the filter bar — ensure "All" or "XHR" is selected, not "JS" or "CSS".
- Copying from Preview tab gives raw text — In the Preview tab, right-click on the JSON tree and choose Copy > Copy value or use the Response tab to copy the raw text, then format it via Console.
Frequently Asked Questions
Does Chrome have a built-in JSON formatter?
Yes, when you open a file with the .json extension or a URL that serves application/json, Chrome displays it in a collapsible, syntax-highlighted tree view. However, it doesn't offer a "copy formatted" button directly on that view; you can copy the raw text and use DevTools to format it.
How do I format JSON in Chrome without an extension?
Use DevTools Console: press F12, go to Console, paste your JSON, wrap it in JSON.stringify(..., null, 2), and press Enter. Or use the Network tab's Preview pane for API responses.
Can I format JSON in Chrome's address bar?
No, the address bar only displays raw text. You need DevTools, an extension, or an online tool.
Why does my JSON show as a download instead of displaying?
This happens if the server sends a Content-Disposition: attachment header. You can't override that in Chrome; you'll need to use a tool like Postman or curl to view the response, or copy the downloaded file's content into an online formatter.
Is there a way to auto-format JSON when I open a file?
Yes, install a JSON viewer extension. It will automatically format any JSON file or URL you open in Chrome.
What's the difference between JSON.stringify and JSON.parse for formatting?
JSON.stringify converts a JavaScript object to a JSON string and can take formatting arguments (indentation). JSON.parse converts a JSON string to a JavaScript object. To format, you need JSON.stringify with the indentation parameter.