Skip to main content
Open in Kaggle  Open in Colab  Download Notebook
This documentation page is also available as an interactive notebook. You can launch the notebook in Kaggle or Colab, or download it for use with an IDE or local Jupyter installation, by clicking one of the above links.
Parse and access specific fields from structured JSON responses returned by language models.

Problem

LLM APIs return nested JSON responses with metadata you don’t need. You want to extract just the text content or specific fields for downstream processing.

Solution

What’s in this recipe:
  • Extract text content from chat completions
  • Access nested JSON fields
  • Create separate columns for different fields
You use JSON path notation to extract specific fields from API responses and store them in computed columns.

Setup

Create prompts table

Connected to Pixeltable database at: postgresql+psycopg://postgres:@/pixeltable?host=/Users/pjlb/.pixeltable/pgdata
Created directory ‘json_demo’.
<pixeltable.catalog.dir.Dir at 0x313d7a150>
Created table ‘prompts’.
Inserting rows into `prompts`: 2 rows [00:00, 325.83 rows/s]
Inserted 2 rows with 0 errors.
2 rows inserted, 2 values computed.

Get LLM responses

Added 2 column values with 0 errors.
2 rows updated, 2 values computed.

Extract specific fields

Use dot notation to access nested JSON fields:
Added 2 column values with 0 errors.
Added 2 column values with 0 errors.
2 rows updated, 2 values computed.

Explanation

Common extraction patterns:
Accessing JSON fields:
  • Use dot notation for object properties: response.usage
  • Use brackets for array elements: choices[0]
  • Chain them: response.choices[0].message.content
Extracted columns are computed: Changes to the source data automatically update all extracted fields.

See also

Last modified on June 24, 2026