Skip to content
Get started

JSON

client.Extract.Json(ctx, body) (*ExtractJsonResponse, error)
POST/extract/json

Fetches a URL and extracts structured data according to a provided JSON schema

ParametersExpand Collapse
body ExtractJsonParams
JsonSchema param.Field[any]

JSON schema definition that describes the structure of data to extract.

URL param.Field[string]

URL to fetch and extract data from

formaturi
Effort param.Field[ExtractJsonParamsEffort]Optional

Fetch effort level controlling speed vs. capability tradeoff. “min”: fastest, no fallback (1-5s). “standard”: balanced with enhanced reliability (default, 3-15s). “max”: full browser rendering for JS-heavy sites (15-60s).

const ExtractJsonParamsEffortMin ExtractJsonParamsEffort = "min"
const ExtractJsonParamsEffortStandard ExtractJsonParamsEffort = "standard"
const ExtractJsonParamsEffortMax ExtractJsonParamsEffort = "max"
GeoTarget param.Field[ExtractJsonParamsGeoTarget]Optional

Optional geotargeting parameters for proxy requests

Country stringOptional

Country code using ISO 3166-1 alpha-2 standard (2 letters, e.g., “US”, “GB”, “JP”). See: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2

Nocache param.Field[bool]Optional

Bypass cache and force fresh data retrieval

ReturnsExpand Collapse
type ExtractJsonResponse map[string, any]

JSON

package main

import (
  "context"
  "fmt"

  "github.com/stainless-sdks/tabstack-go"
  "github.com/stainless-sdks/tabstack-go/option"
)

func main() {
  client := tabstack.NewClient(
    option.WithAPIKey("My API Key"),
  )
  response, err := client.Extract.Json(context.TODO(), tabstack.ExtractJsonParams{
    JsonSchema: map[string]any{
    "properties": map[string]any{
    "stories": map[string]any{
    "items": map[string]any{
    "properties": map[string]any{
    "author": map[string]any{
    "description": "Author username",
    "type": "string",
    },
    "points": map[string]any{
    "description": "Story points",
    "type": "number",
    },
    "title": map[string]any{
    "description": "Story title",
    "type": "string",
    },
    },
    "type": "object",
    },
    "type": "array",
    },
    },
    "type": "object",
    },
    URL: "https://news.ycombinator.com",
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", response)
}
{
  "foo": "bar"
}
{
  "error": "invalid JSON request body"
}
{
  "error": "json schema must be a valid object"
}
{
  "error": "json schema is required"
}
{
  "error": "url is required"
}
{
  "error": "failed to fetch URL"
}
{
  "error": "failed to generate JSON"
}
{
  "error": "web page is too large"
}
Returns Examples
{
  "foo": "bar"
}
{
  "error": "invalid JSON request body"
}
{
  "error": "json schema must be a valid object"
}
{
  "error": "json schema is required"
}
{
  "error": "url is required"
}
{
  "error": "failed to fetch URL"
}
{
  "error": "failed to generate JSON"
}
{
  "error": "web page is too large"
}