Skip to content

JSON from Text

AI models often return JSON wrapped in text: a ```json block, a sentence before and after, typographic quotes or a stray trailing comma. The JSON from Text node finds the first well-formed JSON object or list inside the text, turns it into data and, if you want, checks it has the required fields.

If you don’t set the field holding the text, the node uses the input itself or the first usual field of an AI or HTTP response: contenido, content, text, output, response, respuesta, message, result, reply (and choices[0].message.content). If the field already holds an object, it lets it through as is.

ParameterTypeRequiredDescription
pathtextNoPath to the text containing the JSON. Empty = the input or the first usual field
expectselectNoauto (whatever is there), object (only an object { }) or array (only a list [ ])
requiredFieldstextNoComma-separated required fields (paths like author.name work). If any is missing or empty, the result is invalid
fallbackFieldtextNoIf the AI answers with plain text and no JSON, the whole text is used as this field (for example contenido_html) instead of failing, and jsonRespaldo: true is returned. Required fields are still checked
onInvalidselectNoerror (default: stops the run with an error) or continue (goes on with jsonOk = false)
errorMessagetextNoText that heads the error when it stops
spreadbooleanNoBesides the output field, copies each field of the object to the top level ({{title}} instead of {{json.title}})
outputKeytextNoField where the JSON is stored (default json)

The node keeps the incoming data and adds:

{
"contenido": "Here you go: ```json {\"title\":\"Hello\"} ```",
"json": { "title": "Hello" },
"jsonOk": true
}

With onInvalid: continue and an invalid result: jsonOk is false, json is the JSON found (or null) and jsonFaltan lists the required fields that were missing. Use it with a decision node on data.jsonOk.

  • ```json or ``` blocks, and text before or after.
  • Braces and brackets inside text strings.
  • Trailing commas ({"a":1,}) and typographic quotes (“ ”).
  • Several blocks: it ignores the ones that are not valid JSON and takes the first that is (and meets expect).
{
"label": "Parse the response",
"path": "contenido",
"expect": "object",
"requiredFields": "title, content_html",
"errorMessage": "The AI did not return a usable article",
"spread": true
}

Later nodes can use {{title}} and {{content_html}}. If the AI does not return JSON with those fields, the run stops with a clear message.

  • validate (Validator - to check and clean the content)
  • editFields (Edit Fields - to shape the result)
  • decision (Decision node - to act on jsonOk)