Can't apply json_decode to inputs...?

Options
Erin
Erin Member

My app has a simple messaging feature. It turns out that if a user puts line breaks in their message, I get the error "Error parsing JSON: Control character error, possibly incorrectly encoded"

I tried replacing "\n" with " " before decoding, but still got the error. In "Run & Debug", I rewrote the message totally from scratch in case there were invisible control characters (apparently that's a thing?). It still failed as soon as I put in "\n".

I'm successfully decoding "\n" in other parts of the app. Why does it give me trouble when trying to apply that to an input?

Tagged:

Answers

  • Erin
    Erin Member
    Options

    For anyone encountering the same issue:

    1. I saved the input as a new variable (sms_body)with the json_encode filter.
    2. For a postscript I needed to add to the end, I saved the text in a variable like this: "\n\nReply STOP" (include the quotation marks in the text!).
    3. In my API request, I put in the new variable with the json_encode filter, then concatted the postscript with its own json_decode: