Failed to post on WP (code block failure)

I customized the template flow to post long-form content to Wordpress but it keep throwing an error at the code block.

Note: this same issue happens when I use the exact template flow to post on Wordpress and test step 3 (code block)

The block that keeps failing is the code block with error:

“"Unexpected token ` in JSON at position 0"”

code:

export const code = async (params) => {
return { …JSON.parse(params.chatgpt), num: Math.floor(Math.random() * 100000) };
};

Feel like I am overlooking something simple but can’t quite pin it down. Thanks for your input!

Hello @Rabbit9 , Can you check the output of step 5 it should be valid JSON string?

Thank you, forgot to include that output:

json\n{\n \"title\": \"B2B Leads Genereren in 2024: Effectieve Strategieën en Tips\",\n \"outline\": [\n \"Waarom B2B Leads Genereren Cruciaal is in 2024\",\n \"De Kracht van Doelgerichte Marketing in B2B\",\n \"Gebruik van Sociale Media voor Leadgeneratie\",\n \"Optimaliseren van je Website voor Meer Leads\",\n \"Metingen en Analyse: Succesvol Leadbeheer\"\n ]\n}\n

The “json” at the start of the string is causing an error with JSON.parse. Can you provide instructions for Step 5 so that the AI only returns a valid JSON string or object?

Thanks for your reply.

Here is the prompt for step 5:

Act as an SEO expert speaking fluent Dutch to write only headings (h1, h2 and h3) for an article with this title and about this subject, in Dutch: “{“logoUrl”:“https://cdn.activepieces.com/pieces/google-sheets.png",“displayText”:"4. Find No 0 values A”,“serverValue”:”{{step_17[0][‘values’][‘A’]}}“}”

Return strictly only a valid JSON object that contains the attribute “title” with a rephrased SEO-optimized article title, and another attribute called “outline” that contains a flat array of exactly 5 items, each item is a top level (h2) headline of an article paragraph. The array will contain string items only. Don’t include the word “h2” in any of the items, don’t wrap titles in quotation marks, each heading is only the text of the heading. Everything must be in Dutch.

Hey @Rabbit9 I am no expert when it comes to coding, but I have included the last part of my GPT request, and I get a proper formatted json array as needed for the code block to work without issues. To be honest not sure if this is the best method, but it does work for me and rarely throws any errors on the code block. I also do not think you need the HTML calls in your GPT request. Not even sure the code block will keep the formatting? Later in your flow, format accordingly prior to last step in your flow. Sometimes depending on model or AI (OpenAI, Gemini, etc…, ) you may have to add or change brackets accordingly. replace [ ] with { }. Claude I had to use grouping in order to get the JSON array to format correctly.

The end of my GPT call to create my JSON Array…


response will need to be in a JSON array , the array will have sting items. Follow the format below

[
“title”,
“summary”,
“image”
]
Do not wrap content "

Hope this helps you out.