Skip to main content

parse_json_from_opencode_text

Function parse_json_from_opencode_text 

Source
pub fn parse_json_from_opencode_text<T: DeserializeOwned>(
    text: &str,
) -> Result<T, String>
Expand description

Parse a JSON value from opencode output text.

Opencode has no --output-schema, so the LLM may include markdown fences or explanation text around the JSON. This function tries:

  1. Direct JSON parse of the full text
  2. Extract JSON from markdown code fences
  3. Find the first { to last } substring