JSON · 11 min read

JSON Copied From HTML: Checking " Entities and Intended Values

When your JSON arrives littered with " entities and curly quotes, the data itself is often fine — the page you copied it from was merely displaying HTML-escaped text.

Abstract illustration of a shape passing from a page into a document

The copy that was never the data

Some of the most confusing JSON failures do not start with JSON at all. They start with a selection, a right-click, and a copy. A developer needs a sample payload for a test fixture, finds one in a blog tutorial or an API documentation page, selects the block of JSON as it appears on screen, and pastes it into an editor. What lands in the buffer looks almost right — and then refuses to parse, or parses into values that are quietly wrong. The payload was never damaged in transit. The text you copied was never the payload. It was the page's rendering of the payload, and rendering passes through an escaping layer that exists for the web page's own safety.

The distinction matters because a rendered page and its underlying source are two different documents. The source contains the characters the server sent. The rendering contains the characters the browser chose to display after interpreting markup, resolving entities, and applying typography. When you copy from the rendered view, you receive the second document: entity sequences that were meant to be displayed as text, quote characters that a typographic filter replaced with curved alternatives, and whitespace that a rich-text layer substituted with non-breaking variants. None of this is visible at a glance. Curly quotes and straight quotes are nearly identical in most UI fonts, and a non-breaking space occupies exactly the pixel width of an ordinary one.

This guide covers the full arc of the problem: where the escaping comes from, how it survives the clipboard, how to diagnose which species of damage you are holding, how to undo it in a controlled way, and — the step most people skip — how to verify afterwards that the recovered values match what the original author intended.

Why pages display escaped text

HTML has a hard constraint: certain characters are structural. A literal less-than sign in a text node would be parsed as the start of a tag, an ampersand could begin an entity, and a quotation mark inside an attribute value would terminate the attribute. Every serious templating system therefore escapes user-supplied text before it reaches the page. A CMS storing a biography that contains an ampersand will emit & into the HTML; a documentation site embedding a code sample with angle brackets will emit < and >. The browser resolves those sequences back to the intended characters and displays them correctly, so the page looks perfect to a human reader.

But the escaping is not always fully reversed at display time, and it is almost never reversed at copy time. Three situations produce the escaped-looking text that ends up on your clipboard:

The source itself HTML-escaped the JSON. Tutorials and reference pages routinely publish JSON samples that were escaped at every level — the structural quotes around keys were written as ", the quotes inside string values likewise. This is deliberate: the publisher wanted the sample to survive any markup pipeline, comment system, or email newsletter without being shredded by an over-eager sanitizer. The page displays the entity sequences as literal text, which is exactly what the reader is supposed to see and copy.

The page escaped only the content, not the structure. More common is the middle case: the JSON's braces and key quotes are genuine characters, but values that contain ampersands, angle brackets, or quotation marks were escaped when the sample was authored. The payload renders as valid-looking JSON, yet the string values carry entity text inside them.

The transport layer re-escaped or re-typeset the text. Email clients, chat applications, and some documentation viewers run copied or quoted text through additional processing. A message quoting a JSON snippet may pass it through a typographic filter that converts straight quotes to curly ones for visual polish, or a rich-text composer that turns double spaces into non-breaking spaces. The recipient copies from the quoting UI and inherits every substitution.

Here is what the first situation looks like on screen. A tutorial page showing a configuration object, fully escaped for bulletproof publication:

{"name": "Acme & Co", "motto": "<em>Ship it</em>", "year": 2026}

Every structural quote in that sample is the seven-character sequence ", the ampersand inside the company name is &, and the motto's emphasis markup is <em> and </em>. The page is behaving correctly: those entities are the published text. The reader is expected to copy them and unescape them on the receiving end. The failure occurs when the reader copies the text and pastes it directly into a .json file without that step.

What actually lands on the clipboard

The clipboard copies what the page shows, not what the server sent. That single sentence explains nearly every symptom in this class of problem, and it produces two sharply different outcomes depending on where the escaping sat.

Outcome one: the paste fails loudly. If the structural quotes were escaped, the pasted text is not JSON at all. A strict parser encounters the token " where it expects a quotation mark and stops immediately with something like Unexpected token '&' in JSON at position 1. The error is accurate but the cause is invisible — position 1 is where every character of the pasted text is, and the parser cannot tell you that the character you meant was a quote hiding inside an entity.

Outcome two: the paste succeeds silently, and this is the dangerous one. If the escaping sat only inside string values, the pasted text is still perfectly valid JSON. Entities such as " are just ordinary characters to a parser when they appear inside a string. The file parses, the tests pass, the payload ships — and every affected value is wrong. Someone downstream eventually discovers that the API is storing the literal text & instead of an ampersand, or that a rendering layer is displaying entities to end users because the data was double-escaped at ingestion.

A well-meaning intermediate step often manufactures outcome two. The developer notices the outer " sequences breaking the parse, hand-replaces them with real quotes, and ships the result without inspecting the values:

{"name": "Acme & Co", "motto": "<em>Ship it</em>", "year": 2026}

This file is valid JSON. It will parse on the first try in every language. And every string value in it is corrupted: the company name now contains six literal characters where an ampersand belongs, and the motto will arrive at its destination wrapped in visible entity text instead of markup. Quiet corruption of valid files is far more expensive than loud corruption of invalid ones, because nothing alerts anyone until the bad data has propagated.

Copy from the rendered page and you copy what the page shows. Copy from view-source or the network panel and you copy what the server sent. Only one of those is the data.

Three more species of damage

Entity sequences are only the most visible contaminant. Rendered-page copies routinely carry three more, and they interact with the first.

Typographic quotes. Editors and messaging layers with "smart punctuation" replace the ASCII quotation mark U+0022 with the left and right double quotation marks U+201C and U+201D, and the ASCII apostrophe U+0027 with the right single quotation mark U+2019. JSON permits exactly one string delimiter: U+0022. A payload whose quotes were typeset for a magazine will not parse, and the error message may render the offending character as something that looks like a normal quote, sending you in circles. Related guides cover this in depth — see why JSON requires double quotes for the grammar behind the restriction.

Non-breaking and decorative whitespace. Rich-text surfaces substitute U+00A0 for spaces after punctuation, and some viewers insert zero-width spaces at line-wrap points. Both characters are illegal unescaped inside JSON string values in strict parsers, and both are invisible in every editor that does not specifically render them.

Invisible prefixes. Copying from some views prepends a byte-order mark, list bullets, or line-number gutters to each line. The parse error then points at a column position that looks impossible — a line you can see starting with an open brace is reported as starting with something else, because an invisible character sits before it. Our field note on reading JSON syntax errors by line and column walks through reconciling reported positions with visible text.

All three species together produce a payload like this — note the curved quotation marks around the nested phrase, the curved apostrophe in the name, and the non-breaking space between "grids," and "rhythm" (it is present in the sample below even though your font renders it like an ordinary space):

{
  "title": "Notes on “design systems”",
  "speaker": "Anaïs O’Connell",
  "summary": "A study of grids, rhythm, and restraint"
}

A strict parser rejects this at the first curved quote inside the title value. Nothing about the error message will suggest that the character in question differs from a standard quotation mark by a single code point.

Diagnosing before you fix

The instinct is to start editing. Resist it: every one of these contaminants is removable in seconds once you know which one you have, and hand-editing before diagnosis risks damaging values that were correct. The table below maps the common symptoms to their causes and their fixes.

SymptomLikely causeFix
Unexpected token '&' near the start of the payload Structural quotes were copied as " entity text Unescape HTML entities, then validate
JSON parses, but values contain visible &, <, or " text Entity sequences inside string values survived the copy Unescape string values only, then verify against the source page
Unexpected token '“' or a reported character that looks like a normal quote Smart quotes: U+201C/U+201D replaced U+0022 Replace curved quotes with ASCII quotes deliberately
Parser rejects whitespace inside strings Non-breaking spaces (U+00A0) from a rich-text layer Normalize whitespace to U+0020 before validating
Error line/column points at a position with no visible problem Invisible characters: NBSP, zero-width space, BOM, line-number gutter Reveal all non-ASCII code points, strip or convert them
Extra data error after the first line Copied more than the payload: bullets, signature lines, adjacent UI text Trim to the payload boundaries before any other repair

Two quick inspections settle most diagnoses. First, list the entity sequences present in the file — if the count is zero, entities are not your problem and you can skip unescaping entirely. Second, list every non-ASCII code point, which exposes smart quotes, NBSP, and zero-width characters in one stroke:

$ grep -oE '&[a-zA-Z]+[0-9]*;' pasted.json | sort | uniq -c
       4 "
       1 &
       2 <

$ python3 -c "print(sorted({hex(ord(c)) for c in open('pasted.json').read() if ord(c) > 127}))"
['0xa0', '0x2019', '0x201c', '0x201d']

Read the two outputs together and you know the complete repair plan before touching a single character. In this example: unescape three species of entity, convert two curved quote characters and one curved apostrophe, collapse one non-breaking space, and validate. Anything not in these lists can be left alone.

Recovery in three controlled passes

The repair itself should be boring, scripted, and ordered. Each pass addresses one species of damage, and the order matters because passes can interfere with each other.

Pass 1: unescape entities. Run the text through an HTML unescaper — not a hand-rolled find-and-replace, which will miss numeric entities like “ and can double-process sequences like &. Python's html.unescape or an equivalent in your language handles the full entity table. Do this pass only after diagnosis confirmed entities are present, and only on text you believe was escaped for display — more on that distinction in the verification section below.

Pass 2: normalize characters deliberately. Replace U+201C and U+201D with U+0022, U+2018 and U+2019 with U+0027, and U+00A0 with U+0020. Strip a byte-order mark if present. The word deliberately is doing real work here: blind normalization is exactly what corrupted the text in the first place, so each replacement should be a conscious decision with a recorded before-and-after. If a value legitimately contains a typographic quote — a novelist's name, a book title — replacing it changes meaning, and you want to know that you did it.

Pass 3: validate strictly. Parse the result with a strict JSON parser before using it anywhere. Then compare value counts against the original: the recovered payload should have the same number of keys and the same array lengths as the damaged one. A length change means a normalization pass merged or split something it should not have.

Applied to the samples above, the passes produce a recovered payload:

{
  "name": "Acme & Co",
  "motto": "<em>Ship it</em>",
  "title": "Notes on \"design systems\"",
  "speaker": "Anaïs O’Connell",
  "summary": "A study of grids, rhythm, and restraint",
  "year": 2026
}

Notice what the recovery did not do. The ampersand in the company name came back as a real ampersand. The motto kept its angle brackets — escaped, as JSON requires, as \u003c-style sequences or accepted literally by the parser inside strings. The nested phrase inside title was re-inserted with proper backslash escapes rather than bare quotes, because recovering from curly quotes by blindly swapping in U+0022 would otherwise have produced unescaped quotes inside a string — a fresh parse error of a different species. If that distinction is new to you, the guide on why JSON requires double quotes shows exactly where the grammar draws the line.

Every repair pass is a transformation, and every transformation is a chance to corrupt a value that was correct. Run passes in order, keep a copy of the pre-repair text, and be able to say for each change why it was made.

Then verify the intended values

Recovery ends with a valid file, but a valid file is not the goal. The goal is a file whose values match what the original author published. Unescaping is not a neutral operation: it changes characters, and sometimes the characters it changes were the data.

Consider a documentation payload whose example field legitimately contains the text "hello" — because the field documents how to write an HTML entity. A recovery pass that unescapes entities rewrites that value into "hello" with real quotation marks, destroying the very thing the field was demonstrating. The file still parses. A test that only checks for the presence of the key still passes. The data is now wrong in a way that will surface only when someone reads the rendered output.

The defense is a comparison against the source rendering. Open the page you copied from and look at how the suspicious value is displayed. If the page shows " as visible text, the entity is part of the published value and your recovered file is wrong. If the page shows a quotation mark — because the browser resolved the entity during display — then unescaping was correct. The same check settles the curly-quote question: a page that displays a genuinely curly quote intends a curly quote, and your normalization pass should have left it alone or re-inserted it. Where the source is ambiguous, a well-formed payload recovered from the same document's CSV export or the network panel can serve as the tiebreaker.

Verification takes two minutes for a payload of typical size. Skipping it has a cost profile nobody enjoys: minutes of repair work buying data that is valid and wrong.

Prevention beats recovery

The entire class of failure disappears when you change where you copy from. The rendered page is the worst possible source; better options exist at every layer of the stack.

View-source. Prefixing the URL with view-source: shows the document the server sent, entities and all — but entities in view-source are the markup's own escaping, which you can usually bypass entirely by finding the JSON block in a <script> element or a code container where it sits unmodified.

The network panel. For payloads the page fetched at runtime, the network panel's response tab shows the exact bytes the server returned. This is the gold standard: no rendering, no typography, no escaping layer of any kind. Copy from there and the paste is the payload.

The API itself. When the JSON originated from a documented endpoint, request it directly with the same client you will test with. You skip the browser entirely and inherit none of its display behavior.

Whichever source you use, paste the result into a strict inspector before anything consumes it. A strict parser catches entity-bearing values that a permissive one accepts, flags non-ASCII code points, and reports exact positions — turning silent corruption into an immediate, locatable error.

Test it yourself. Paste a suspect payload into the JSON Inspector and read the report before repairing anything: it parses strictly, pinpoints the exact line and column of the first failure, and surfaces the invisible characters — smart quotes, non-breaking spaces, zero-width space — that make entity-damaged payloads so hard to eyeball. Compare the character list against the diagnostic table above and you will have the full repair plan in under a minute.

Related field notes

Copying JSON out of structured documents causes sibling problems with sibling cures: Rescuing JSON That Traveled Through a CSV Cell covers the spreadsheet round trip, and reading JSON syntax errors by line and column helps when a repaired file still refuses to parse and the reported position refuses to make sense.

Reproduce every example locally with the JSON Inspector or the matching tool on the workbench. Nothing you paste leaves your browser.