Replace() function in Set Variable / Parse JSON not stripping markdown code fences (backticks) from Claude API response

:bullseye: What is your goal?

Strip leading json and trailing markdown code fences from an Anthropic Claude API text response, so it can be parsed by the Parse JSON module.

:thinking: What is the problem & what have you tried?

I’m processing news articles through the Anthropic Claude module, then trying to parse the response as JSON using the Parse JSON module. The issue: Claude’s text response is sometimes wrapped in markdown code fences (json ... ), which breaks Parse JSON with “Source is not valid JSON. Code: DataError”.

I added a system prompt instruction telling Claude not to use markdown formatting, but the wrapper still appears occasionally.

What I’ve tried to strip the fences using replace():

  1. Typed directly into Parse JSON’s “JSON string” field as text with an inserted variable chip:
    replace(replace(10. Text Response; “json"; ""); "”; “”)
    Result: the entire expression

Open the anthropic module, toggle advanced settings and tell it to return the output as a JSON file instead of text.