title: Receive JSON POST with PHP
body: <p>I’m trying to receive a JSON POST on a payment interface website, but I can’t decode it.</p>
  
  <p>When I print :</p>
  
  <pre><code>echo $_POST;
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>Array
  </code></pre>
  
  <p>I get nothing when I try this:</p>
  
  <pre><code>if ( $_POST ) {
      foreach ( $_POST as $key =&gt; $value ) {
          echo "llave: ".$key."- Valor:".$value."&lt;br /&gt;";
      }
  }
  </code></pre>
  
  <p>I get nothing when I try this:</p>
  
  <pre><code>$string = $_POST['operation'];
  $var = json_decode($string);
  echo $var;
  </code></pre>
  
  <p>I get NULL when I try this:</p>
  
  <pre><code>$data = json_decode( file_get_contents('php://input') );
  var_dump( $data-&gt;operation );
  </code></pre>
  
  <p>When I do:</p>
  
  <pre><code>$data = json_decode(file_get_contents('php://input'), true);
  var_dump($data);
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>NULL
  </code></pre>
  
  <p>The JSON format is (according to payment site documentation):</p>
  
  <pre><code>{
     "operacion": {
         "tok": "[generated token]",
         "shop_id": "12313",
         "respuesta": "S",
         "respuesta_details": "respuesta S",
         "extended_respuesta_description": "respuesta extendida",
         "moneda": "PYG",
         "monto": "10100.00",
         "authorization_number": "123456",
         "ticket_number": "123456789123456",
         "response_code": "00",
         "response_description": "Transacción aprobada.",
         "security_information": {
             "customer_ip": "123.123.123.123",
             "card_source": "I",
             "card_country": "Croacia",
             "version": "0.3",
             "risk_index": "0"
         }
      }
  }
  </code></pre>
  
  <p>The payment site log says everything is OK. What’s the problem?</p>