Learn R Programming

llmflow (version 3.0.2)

extract_json: Extract and parse JSONs from a string (LLM response)

Description

This function extracts JSON blocks from a string and parses them using `jsonlite::fromJSON()`. This can be used to extract all JSONs from LLM responses, immediately converting them to R objects.

Usage

extract_json(llm_response)

Value

A list of parsed JSON objects

Arguments

llm_response

A character string

Details

CRITICAL FIX: Now uses simplifyVector = FALSE to preserve array structure. This ensures that JSON arrays remain as R lists, preventing single-element arrays from being simplified to character vectors. This is essential for proper schema validation when used with auto_unbox = TRUE in toJSON().