PDF-app not properly parsing content, JSONEscape erring

The simplest way to ask my question: Why does message.content work in my debug Set Variable step, but not in the PDF-app step? … And when I include EscapeJSON, why does it work in debug but not in PDF-app?

I suppose it’s the ** that are throwing it off here



Escape JSON isn’t erring too though

Hi Ryan3001, add quotes "" around the array string "content": "content Array"

@Jonathan_Escobar Thanks so much for your reply. Unfortunately, I tried this already. Set Variable step works.

It fails again in the PDF-app step.

IMLError

Function ‘parseJSON’ finished with error! Bad control character in string literal in JSON at position 58

Here’s the error output. Curiously, I see the content there starting with “Summary of Symptoms:”. Can you have a look there? Does this mean the content is coming through, it’s just that the PDF-app is not able to use it to create a PDF?

This will replace the newline with a “\n” to make a JSON string
Try: "content": "{{replace(valueHere; newline; "\n")}}"
Or you could try the Transform to Json module

Thanks @Jonathan_Escobar
I had success with the replace function, but ran into other JSON issues. So as a test, I’ve simplified the message coming from ChatGPT into a single paragraph. Now I’m getting this 500 error. Could you advise on how to debug this one?

I can’t see the error code

Welcome to the Make community!

Most of the time, you cannot directly map variables containing text content into another JSON string without escaping them, as the variable might contain characters that have a special meaning in JSON.

Special characters in strings needs to be specified (escaped) as a “literal” character (instead of a special metacharacter), otherwise they make the whole JSON invalid when you map the variable value when creating another JSON string.

You can escape string variables by passing the text into the JSON “Transform to JSON” module —

Transforms any object to JSON.

Then, you can map the output of the “Transform to JSON” module into your JSON string. (Do note that when using the “Transform to JSON” module, the output should already contain the double quotes " " around your text, so when you map this output into your JSON, you should not need to wrap another pair of double quotes around it.)

Alternatively, you can use the built-in function replace to replace those special characters with their escaped versions, as discussed here.

For more information on escaping JSON strings, see: Understanding JSON Escape: A Comprehensive Guide

Hope this helps! Let me know if there are any further questions or issues.

@samliew