How to encode json with drupal_http_request in drupal 7

In lots of places you will see how to use drupal_http_request with drupal_http_build_query used on data, which is fine if you want to build regular query data (like the ones you have in URLs when using GET) but if you want to send JSON, you shouldn't use that, instead you need  json_encode function on data.

$data = array(
'public_key' => 'pub_IFkw95vEzk4asdsF8JD2131imyoGAlFvkC',
'private_key' => pr_vZ4sfI213mxTvOdsbygeeHadsdsUl4Sd,
);

$options = array(
'headers' => array('Content-Type' => 'application/json'),
'method' => 'POST',
'data' =>json_encode($data),
);


$result = drupal_http_request('https://sandbox.gateway.site.com/v1/authentication', $options);