Instead of handwriting your own JSON string, you should absolutely be using PHP's built-in functions to make your like at least 483% easier:
// Use a native PHP array to store your data; it will preserve the new lines
$input = [
"Parameter1" => "<style>
#label-9 {
display: block;
text-align: left;
color: #fff;
}
</style>",
"HistoryPosition" => "1"
];
// This function will preserve everything in your strings
$encoded_value = json_encode($input);
// See your properly formatted JSON string
echo $encoded_value.'<br><br>';
// Decode the string back into an associative PHP array
echo '<pre>';
print_r(json_decode($encoded_value, true));
echo '</pre>';
Update per new info about DB retrieval
json_last_error_msg(); produces this error:
Control character error, possibly incorrectly encoded
If you do not care about preserving newlines then this will work:
<?php
$db_data = '{
"Parameter1":"<style>
#label-9 {
display: block;
text-align: left;
color: #fff;
}
</style>",
"HistoryPosition":"1"
}';
$db_data = str_replace("\r", "", $db_data);
$db_data = str_replace("\n", "", $db_data);
echo '<pre>';
print_r(json_decode($db_data, true));
echo '</pre>';
json_last_error_msgand see if that shows any problems.Parameter1with\n, so for example the first parameter would look like this:<style>\n #label-9. That way you'll preserve the line breaks when you e.g. pull it from a database and output it into a webpage. You should expand your question though, as it's unclear if you have access to the string as-is, or if you have access to individual values as well.