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.


$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);


$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.



What is wrong?

Have I wrong something in translate the origin code?

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



Pass JSON_HEX_QUOT as a second parameter to wp_json_encode to escape the double quotes without a slash. See: and for more details.