Fetches a URL and extracts structured data according to a provided JSON schema
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"
}