// n8n Code Node: "Claude JSON extrahieren" // Erwartet die Antwort der Anthropic Messages API. const response = $json; if (response.stop_reason === 'refusal') { throw new Error('Claude hat die Anfrage abgelehnt. Es wird kein Report erzeugt.'); } if (response.stop_reason === 'max_tokens') { throw new Error('Claude-Ausgabe wurde wegen max_tokens abgeschnitten. max_tokens erhoehen und erneut ausfuehren.'); } const textBlock = Array.isArray(response.content) ? response.content.find(block => block.type === 'text') : null; if (!textBlock?.text) { throw new Error('Anthropic-Antwort enthaelt keinen Textblock.'); } let content; try { content = JSON.parse(textBlock.text); } catch (error) { throw new Error(`Claude-Ausgabe ist kein valides JSON: ${error.message}`); } return [{ json: { content, claudeMeta: { id: response.id, model: response.model, stop_reason: response.stop_reason, usage: response.usage } } }];