Skip to content

Function: extractJson()

Makaio Framework


Makaio Framework / utils / extractJson

extractJson(text): string

Defined in: ../../../packages/utils/src/extract-json.ts:12

Extract a JSON object from text that may contain surrounding content.

LLM responses often wrap JSON in markdown fences or prose. This function finds the first { and last } in the text and returns the substring between them (inclusive).

Returns the original text unchanged when no valid brace pair is found.

string

Raw text potentially containing a JSON object

string

Extracted JSON substring, or the original text if no braces found