User Agents

Web browsers and everyday web tech, explained

Copy Formatted JSON from Browser: Step-by-Step

· 4 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

Copying formatted JSON from a browser is useful when you need to share or save API responses, configuration data, or any JSON you see in DevTools or a web page. This guide shows you how to copy it with proper indentation and line breaks, so it's readable and valid. You'll need a modern browser (Chrome, Firefox, Edge, or Safari) and the JSON visible in the browser's network tab or as a raw response.

What You'll Need

  • A modern web browser (Chrome, Firefox, Edge, or Safari).
  • Access to the JSON you want to copy—either from a URL, an API endpoint, or a page that displays JSON.
  • Basic familiarity with browser Developer Tools (F12 or right-click > Inspect).

Step-by-Step

  1. Open the JSON in your browser. If you have a direct URL (like an API endpoint), navigate to it. If the JSON is part of a web app, open the Network tab in DevTools (F12), reload the page, and click the relevant request to see its response.
  2. View the JSON in a formatted way. In DevTools, the Network tab often shows JSON in a pretty-printed format by default. If you see a single long line, click the "Response" or "Preview" tab—Preview usually formats it. In the browser's main window, if the JSON is raw text, you can use the browser's built-in JSON viewer (Chrome and Edge show it formatted automatically).
  3. Select the entire JSON. In the DevTools preview pane, click inside the JSON and press Ctrl+A (Windows/Linux) or Cmd+A (Mac) to select all. If you're viewing it in the main browser window, click anywhere on the page and use the same shortcut. Ensure the entire JSON is highlighted.
  4. Copy the selection. Press Ctrl+C (Windows/Linux) or Cmd+C (Mac). Alternatively, right-click the selection and choose "Copy" from the context menu.
  5. Paste into your target. Open a text editor, code editor, or any field where you need the JSON. Paste with Ctrl+V or Cmd+V. The formatting (indentation and line breaks) should be preserved.
  6. If you need a copy as a string (for embedding in code): Use the browser's console. Open DevTools, go to the Console tab, and type copy(JSON.stringify(JSON.parse(document.body.innerText))) if the JSON is on the page, or use copy(JSON.stringify(yourObject)) if you have a variable. This copies a minified string, not formatted, but it's useful for code.

Common Mistakes

  • Copying from the wrong tab: In DevTools, the "Response" tab shows raw text, while "Preview" shows formatted. Copying from "Response" may give unformatted text if the server sends it minified.
  • Selecting extra content: If you use Ctrl+A on the whole page, you might include surrounding HTML or UI elements. Make sure you click inside the JSON area first.
  • Copying from the console incorrectly: Using copy() without proper JSON stringify can result in a JavaScript object literal, which may not be valid JSON (e.g., single quotes, undefined values).

Tips

  • Use a JSON formatter extension if you often copy JSON from web pages—they add a "Copy formatted" button.
  • If you need to copy a large JSON, consider using the browser's "Save as" feature in the Network tab to download the file directly.
  • In Chrome and Edge, the built-in JSON viewer has a copy button (clipboard icon) at the top right—click it to copy the formatted JSON instantly.
  • For API responses, you can also use the "Copy" option in the Network tab's context menu (right-click the request > Copy > Copy response).

Troubleshooting

  • Pasted JSON is all on one line: The source was minified. Use a JSON formatter (like JSON.stringify(JSON.parse(data), null, 2) in the console) to re-format before copying.
  • Copy option is grayed out: In DevTools, make sure you're on the correct tab (Preview or Response) and that the response has loaded. Reload the page if needed.
  • Ctrl+C doesn't work: Some browsers block copy commands on certain pages. Try right-clicking and selecting "Copy" from the menu, or use the browser's edit menu.
  • JSON contains syntax errors after pasting: You may have copied extra characters (like trailing commas or HTML). Validate the JSON using a tool like JSONLint before using it.

Frequently Asked Questions

Can I copy formatted JSON from the browser without DevTools?

Yes, if the page displays JSON in a formatted way (e.g., Chrome's built-in viewer), you can just select and copy it. If it's raw text, you'll need DevTools or a browser extension.

How do I copy JSON from a network request?

Open DevTools, go to the Network tab, find the request, click it, and go to the Preview or Response tab. Then select and copy, or right-click and choose "Copy response".

What's the difference between copying formatted and minified JSON?

Formatted JSON has indentation and line breaks for readability. Minified JSON is a single line with no extra whitespace, which is smaller for storage but harder to read.

Does copying from the browser preserve the exact formatting?

Usually yes, if you copy from the Preview tab or the browser's JSON viewer. Copying from the Response tab may give you the raw server format, which could be minified.

Can I copy JSON as a JavaScript object instead of a string?

In the console, you can use copy(JSON.parse(jsonString)) to copy a JavaScript object, but pasting it into a text editor will show it as a string representation, not JSON. For a JSON string, use JSON.stringify().

Why does my copied JSON have extra spaces or tabs?

That's the formatting from the browser or server. If you need a specific indentation (like 2 spaces), you can reformat it using a tool or the console command JSON.stringify(JSON.parse(data), null, 2).