How to prevent wp_remote_post to add backslashes

To publish a plugin I must change my code to use the WordPress HTTP Api.

Therefore, I have translate my code.

Before.

$data = array("Param1" => 'ValueParam1', "Param2" => "ValueParam2");
$data_string = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($data_string)
));
        
$result = curl_exec($ch);

After

$data = array("Param1" => 'ValueParam1', "Param2" => "ValueParam2");
$data_string = json_encode($data);
$result = wp_remote_post($url, array(
    'headers'     => array('Content-Type' => 'application/json'),
    'body'        => wp_json_encode($data_string),
    'method'      => 'POST',
    'timeout'     => 60, // added
    'redirection' => 5,  // added
    'blocking'    => true, // added
    'httpversion' => '1.0',
    'sslverify' => false,
));

But with the function wp_remote_post I have this problem.

When JSON data is sended to remote host, the data has the backslashes inside.

Example:

{"Param1":"ValueParam1","Param2":"ValueParam2"}

What is wrong?

Have I wrong something in translate the origin code?

I need some help to send JSON data without these escaping characters.

Thanks.

Answer

Pass JSON_HEX_QUOT as a second parameter to wp_json_encode to escape the double quotes without a slash. See: https://developer.wordpress.org/reference/functions/wp_json_encode/ and https://www.php.net/manual/en/json.constants.php for more details.