Almost every API doc page has the same block: "Example response", followed by 80 lines of JSON that nobody reads
past line 12. Here are three ways to show a response, from the simplest to the most interactive, and when each one
fits.

1. A plain code block, trimmed

For short responses this is still the best option. It works everywhere (READMEs, docs generators, blogs), it is
searchable, and readers can copy it.

Two habits make it much easier to read:

  • Pretty-print with a 2-space indent. Four spaces push nested objects off the right edge on phones.
  • Trim arrays to two or three items and say so in the text, so readers know it is a sample, not the full shape.
{ "id": 1042, "name": "Desk lamp", "price": 35.5, "inStock": true, "tags": ["lighting", "office"], "dimensions": { "heightCm": 45, "weightKg": 1.2 }, "supplier": null } 

Keep null fields in the example. A reader who never sees "supplier": null will write code that breaks on it.

2. A <details> block per section

When a response is long but has clear parts (a data array, meta, links, errors), fold each part into
an HTML <details> element. It needs no script, and many Markdown renderers (GitHub included) pass it through.

<details> <summary><code>meta</code>: paging information</summary> ```json { "page": 2, "perPage": 20, "total": 134 } ``` </details> 

Put the most important part first and open: <details open>. Check how your docs platform renders it before you
rely on it; some strip raw HTML.

3. A collapsible JSON tree in an iframe

For large or deeply nested responses that readers explore rather than read, a tree they can open and close level
by level works better than any static block.

Disclosure: I made this one. It is a free widget on my site, JSON Editor Free:

  1. Open https://jsoneditorfree.com/embed/?utm_source=devto&utm_medium=article&utm_campaign=arlen-marketing and paste your JSON.
  2. Pick the theme (Auto follows the reader's light or dark setting), how many levels start open, and the height.
  3. Copy the snippet: one <iframe> and one credit line, and paste it into any page that accepts an iframe.

What to know before you use it:

  • Up to 200 KB of JSON per snippet. The JSON is compressed into the iframe address, and long addresses fail in some browsers and content systems.
  • The JSON goes after the # in the address, and browsers never send that part to a server. The viewer reads it in the reader's browser. It sets no cookies and shows no ads.
  • To change the JSON, make a new snippet. Nothing is stored on a server, so there is nothing to update there.
  • GitHub READMEs do not allow iframes. Use option 1 or 2 there.

Which one when

Response Platform Use
Under about 30 lines anywhere 1. trimmed code block
Long, with clear sections Markdown that allows HTML (GitHub included) 2. <details> per section
Large or deeply nested, meant to be explored your own site or a docs platform that allows iframes 3. collapsible tree

Whichever you choose, show a real response, not a hand-written one: hand-written examples drift from the API
within a release or two.

If your response is too big for any of these, here is how to open huge JSON files (hundreds of MB and more) in a
browser: https://jsoneditorfree.com/docs/large-documents/?utm_source=devto&utm_medium=article&utm_campaign=arlen-marketing