Your question is a little vague...
Are you looking for this?
$json = array('type' => $thetype, 'msg' => $themsg);
$json_data = json_encode($json);
That will set $json_data to a string like what you described:
<?php
$thetype = 'something';
$themsg = 'something else';
$json = array('type' => $thetype, 'msg' => $themsg);
$json_data = json_encode($json);
var_dump($json_data);
Would print:
string(43) "{"type":"something","msg":"something else"}"
See the PHP manual for json_encode.
You could try and build the string by hand, like this:
$json_data = '{"type":"'. addcslashes($thetype,"\"'\n").'","msg":"'. addcslashes($themsg,"\"'\n").'"}';
But, you'll generally be better off using json_encode, as it's designed for this purpose and is much less likely to produce invalid JSON.