Given that you have complete control over the payload’s content, try sending a JSON string that is not terminated by a newline (or anything else for that matter). I’m curious to know if it makes any difference here.
As for the failed regex_findall_index, I won’t bother delving into what caused its failure (and how to correct it) because, in this case, you have control over the payload. However, know that in cases where Home Assistant cannot interpret the JSON string (and you don’t have control over the string’s content), the regex technique is the standard ‘Plan B’.
I believe I just learned the reason why the regex function failed and it is probably due to the way the backslashes are handled in the regex pattern. pnbruckner explains it here:
In a nutshell, there are two interpreters at work (YAML and Jinja2) and the first one (YAML) interprets the escape sequence when it is meant for use by the second one (Jinja2). Therefore you have to escape the escape
(use double backslashes) so that its meaning is retained when evaluated by the Jinja2 interpreter.