User Agents

Web browsers and everyday web tech, explained

How to Beautify JSON in Chrome: 4 Easy Ways

· 5 min read · Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide shows you how to format (or "beautify") raw JSON in the Google Chrome browser, turning a single-line jumble into an indented, readable structure. You can do this without installing anything, using built-in developer tools, or with a simple online tool. No prior knowledge is needed beyond opening a browser tab.

What You'll Need

  • Google Chrome browser (any recent version)
  • A JSON string to format (e.g., from an API response, a config file, or a copied snippet)
  • Optional: internet access if you choose to use an online JSON formatter

Step-by-Step

Method 1: Using Chrome's Developer Tools (No Internet Needed)

  1. Open Chrome and press F12 (or Ctrl+Shift+I on Windows/Linux, Cmd+Option+I on Mac) to open Developer Tools.
  2. Click on the Console tab.
  3. Type or paste the following command and press Enter: console.log(JSON.stringify(JSON.parse(prompt("Paste JSON here")), null, 2))
  4. A prompt will appear. Paste your raw JSON string into the box and click OK.
  5. The console will display the formatted JSON with proper indentation. You can right-click the output and select Copy to copy the formatted version.

Method 2: Using the Address Bar (For JSON Files/URLs)

  1. If you have a URL that returns JSON (like an API endpoint), simply navigate to it in Chrome.
  2. Chrome will display the raw JSON as plain text. Press F12 to open Developer Tools.
  3. Go to the Sources tab, then click on the file name (usually something like data.json or the URL path) in the left panel.
  4. The JSON will appear in the center panel. Click the { } icon (Pretty Print) at the bottom left of that panel. The JSON will be instantly formatted.
  5. Right-click the formatted code and choose Save as to download the beautified version.

Method 3: Using a Bookmarklet (One-Click Anywhere)

  1. Create a new bookmark in Chrome (right-click the bookmarks bar → Add page).
  2. Name it something like "Beautify JSON".
  3. In the URL field, paste the following code:
  4. Save the bookmark. Now, whenever you have JSON on your clipboard, click the bookmark, paste it into the prompt, and the formatted version appears in the console.

Method 4: Using a Free Online Formatter

  1. Go to a trusted JSON formatter website (e.g., jsonformatter.org, jsonlint.com, or similar).
  2. Paste your raw JSON into the text area.
  3. Click the Format or Beautify button.
  4. Copy the formatted output from the result pane.

Common Mistakes

  • Using single quotes – JSON requires double quotes for keys and string values. If your JSON uses single quotes, it will fail to parse. Replace them with double quotes first.
  • Trailing commas – JSON does not allow trailing commas after the last item in an array or object. Remove them.
  • Copying from a browser console – Sometimes console output wraps lines or adds extra indentation. Use the copy function (right-click → Copy) to get clean text.
  • Forgetting to switch to the Console tab – If you run the command in the wrong tab, you might not see the output. Make sure you are in the Console tab.

Tips

  • Use 2 spaces for indentation – it's the most common standard and keeps files compact. You can change the number in the code (e.g., null, 4 for 4 spaces).
  • If you work with JSON often, install a Chrome extension like JSON Viewer or JSON Formatter – they automatically format JSON when you visit a JSON URL.
  • For large JSON files, avoid online tools – they may have size limits. Use the Developer Tools method instead.
  • Learn to read the error messages in the console – they usually tell you the exact line and column where the JSON is invalid.

Troubleshooting

  • "Unexpected token" error – This means your JSON has a syntax error. Check for missing commas, brackets, or quotes. Use a validator like jsonlint.com to pinpoint the issue.
  • Nothing appears in the console – Make sure you pressed Enter after pasting the command. Also check that you are in the Console tab, not the Elements tab.
  • The prompt doesn't appear – If you're using the bookmarklet, ensure you copied the entire code correctly. Some browsers block javascript: URLs in bookmarks – try re-creating it.
  • JSON is valid but still not formatting – If you're using the Sources tab, make sure you clicked the { } icon, not just the file name. The file must be loaded as a JSON resource.
  • Online formatter says "Invalid JSON" – Double-check for hidden characters like non-breaking spaces. Copy the JSON into a plain text editor first to clean it.

Frequently Asked Questions

Can I beautify JSON in Chrome without any tools?

Yes, you can use the Developer Tools console with the JSON.stringify command as shown in Method 1. No installation needed.

Why does Chrome show JSON as plain text?

By default, Chrome displays JSON as plain text. You need to use Developer Tools or an extension to get syntax highlighting and formatting.

Is it safe to paste sensitive JSON into online formatters?

Generally, avoid pasting sensitive data (passwords, personal info) into unknown online tools. Use the offline method in Chrome for privacy.

Can I beautify JSON in Chrome on mobile?

Yes, but it's trickier. You can use an online formatter or install a mobile browser extension if supported. The Developer Tools method works in Chrome for Android via the desktop site option.

How do I copy the beautified JSON from the console?

Right-click the formatted output in the console and select Copy, or use Ctrl+C after selecting the text.

What does "null, 2" mean in the JSON.stringify command?

The null is a replacer function (we don't need it), and 2 is the number of spaces for indentation. Change it to 4 for wider indentation.