I'm still curious what this meant..

anyway, if you meant this was a bad code, remember it was intended to be understood by a newbie
As a python dev, I highly appreciate the readability of code, so defining a json structure in a form of a string is making your code ugly and unreadable

You have a lot of builtin functions to work with data structures, so make the objects and arrays and use builtin functions to represent them as strings when needed...
If you still want to use a long multi line string, I'd advice to use a heredoc to maintain the readability.
Ex:
PHP:
$val1 = '94';
$val2 = '......';
$val3 = 'This is a test message';
$val4 = 'abc12';
$ds = <<<TEXT
{
"messages":[
{
"a1": "$val1",
"a2": "$val2",
"a3": "$val3",
"a4":"$val4"
}
]
}
TEXT;
echo $ds;
</div>
Clean and Tidy