> ## Documentation Index
> Fetch the complete documentation index at: /llms.txt
> Use this file to discover all available pages before exploring further.

# JSON mode - Structured result

> Extract structured data from pages with AI

## Scrape and extract structured data with ScreenshotRender

ScreenshotRender reads the page and uses AI to pull out the data you describe, as JSON. Describe it with a schema, a prompt, or both.

## Extract structured data

### JSON mode via /scrape

Add a `json` format to `formats`, with a `schema` (a JSON Schema) and an optional `prompt`. In Python, the schema can be a Pydantic model. The data comes back in `data.json`, shaped like your schema.

```python Python
from pydantic import BaseModel
from screenshotrender import ScreenshotRender

screenshotrender = ScreenshotRender(api_key="sr-YOUR-API-KEY")

class Story(BaseModel):
    title: str
    points: int

class TopStories(BaseModel):
    stories: list[Story]

doc = screenshotrender.scrape(
    "https://news.ycombinator.com",
    formats=[{"type": "json", "prompt": "The top 3 stories", "schema": TopStories}],
)
print(doc.json)
```

```js Node
import ScreenshotRender from "screenshotrender";

const screenshotrender = new ScreenshotRender({ apiKey: "sr-YOUR-API-KEY" });

const schema = {
  type: "object",
  properties: {
    stories: {
      type: "array",
      items: {
        type: "object",
        properties: { title: { type: "string" }, points: { type: "number" } },
        required: ["title", "points"],
      },
    },
  },
  required: ["stories"],
};

const doc = await screenshotrender.scrape("https://news.ycombinator.com", {
  formats: [{ type: "json", prompt: "The top 3 stories", schema }],
});
console.log(doc.json);
```

```bash cURL
curl -s -X POST "https://www.screenshotrender.com/api/v1/scrape" \
  -H "Authorization: Bearer $SCREENSHOTRENDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://news.ycombinator.com",
    "formats": [
      {
        "type": "json",
        "prompt": "The top 3 stories",
        "schema": {
          "type": "object",
          "properties": {
            "stories": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "title": { "type": "string" },
                  "points": { "type": "number" }
                },
                "required": ["title", "points"]
              }
            }
          },
          "required": ["stories"]
        }
      }
    ]
  }'
```

Output:

```json Response
{
  "success": true,
  "data": {
    "json": {
      "stories": [
        {
          "title": "NSA advises immediate transition to post-quantum cryptography",
          "points": 2373
        },
        {
          "title": "Anatomy of an AI Kill Chain",
          "points": 240
        },
        {
          "title": "Show HN: misa77 – Up to 3x faster decompression than zstd, with better ratios",
          "points": 89
        }
      ]
    },
    "metadata": {
      "title": "Hacker News",
      "language": "en",
      "sourceURL": "https://news.ycombinator.com/",
      "url": "https://news.ycombinator.com/",
      "statusCode": 200,
      "contentType": "text/html; charset=utf-8",
      "proxyUsed": "basic",
      "cacheState": "hit",
      "cachedAt": "2026-12-03T12:15:08.498Z"
    }
  },
  "creditsUsed": 5
}
```

### Structured data without schema

Pass only a `prompt` and the AI chooses the structure of the data.

```bash cURL
curl -s -X POST "https://www.screenshotrender.com/api/v1/scrape" \
  -H "Authorization: Bearer $SCREENSHOTRENDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://news.ycombinator.com",
    "formats": [
      { "type": "json", "prompt": "The title of the top story and how many points it has" }
    ]
  }'
```

Output:

```json Response
{
  "success": true,
  "data": {
    "json": {
      "topStory": {
        "title": "Anatomy of an AI Kill Chain",
        "points": 240
      }
    },
    "metadata": {
      "title": "Hacker News",
      "language": "en",
      "sourceURL": "https://news.ycombinator.com/",
      "url": "https://news.ycombinator.com/",
      "statusCode": 200,
      "contentType": "text/html; charset=utf-8",
      "proxyUsed": "basic",
      "cacheState": "hit",
      "cachedAt": "2026-12-03T12:15:08.498Z"
    }
  },
  "creditsUsed": 5
}
```

### JSON format options

| Option | Type | Description |
| - | - | - |
| `type` | `"json"` | Required. |
| `schema` | object | A JSON Schema for the result. In Python, a Pydantic model works too. |
| `prompt` | string | What to extract, in plain words. |

> [!NOTE]
>
> JSON mode costs 5 credits per page: 1 for the page and 4 for the extraction.

## Tips for consistent extraction

* Name the fields you want and mark them `required` in the schema.
* Use a prompt to say which part of the page to read, like "The top 3 stories".
* Ask for a plain answer about the page with the [question format](/features/scrape.md#question-format) instead, when you need one value rather than an object.
