Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI Tools · Function

useObject

useObject consumes a streamed JSON response and parses it into a structured object according to a supplied schema. It is intended for AI SDK UI applications that progressively render generated structured data.

How it works

useObject is an AI SDK UI hook for consuming a streamed JSON response and incrementally parsing it into an object that conforms to a supplied schema. Provide an endpoint that emits schema-matching JSON as chunked text, then use the returned object and controls to submit input and render progressive results.

Syntax

useObject({ api, schema, id? })

Parameters

NameTypeDescription
apistringEndpoint that generates the object and streams schema-matching JSON as chunked text. It may be a relative path beginning with / or an absolute URL.
schemaZod Schema | JSON SchemaSchema describing the complete object; use a Zod schema or JSON Schema with the jsonSchema function.
idstringOptional unique identifier. A random identifier is generated when omitted.

Returns

A hook result for submitting input and consuming the progressively parsed structured object, including the generated object and request controls.

Key points

  • useObject consumes streamed text representing JSON and parses it into a schema-conforming object.
  • The hook is documented for React, Svelte, Vue, and the SolidJS community integration.
  • Angular uses the equivalent StructuredObject service rather than this hook.
  • The api option identifies the server endpoint responsible for generating the object.
  • The schema option defines the expected shape of the completed object.
  • The optional id gives the request a unique identifier; when omitted, the SDK generates one randomly.

Common mistakes

  • The endpoint must return JSON matching the schema as chunked text; a normal completed JSON response does not satisfy the documented streaming contract.
  • The schema must be either a Zod schema or a JSON schema created with the documented JSON-schema helper.

Example: Stream a structured object

import { useObject } from 'ai';
import { z } from 'zod';

export default function Recipe() {
  const { object, submit } = useObject({
    api: '/api/recipe',
    schema: z.object({
      title: z.string(),
      ingredients: z.array(z.string()),
    }),
  });

  return (
    <main>
      <button onClick={() => submit('pasta')}>Generate</button>
      {object?.title && <h1>{object.title}</h1>}
      <ul>{object?.ingredients?.map(item => <li key={item}>{item}</li>)}</ul>
    </main>
  );
}

This React component submits a prompt and renders the structured object as partial fields arrive.

When to use it

Streaming structured content

Progressively render generated recipe fields while the model is still producing the object.

Interactive structured-data UI

Build forms or dashboards that display typed JSON results as they arrive.

Classification interfaces

Classify or categorize input using a predefined structured output schema.

  • streamText
  • Output.object()
  • jsonSchema
  • StructuredObject
  • useChat
  • useCompletion

Source: useObject. Checked 2026-10-15.