title: Having trouble POSTing nested JSON using PHP
body: <p>I'm trying to send some form data as a JSON object to a <a href="https://cmsamp.secure.force.com/GenericApp/services/apexrest/GenericApp" rel="nofollow">sample app on Force.com</a>. I get the form data using jQuery and POST it to a PHP file on my server which then sends it to the sample app linked above. The response I get from the sample app however tells me that I'm making some mistakes along the way. </p>
  
  <p><strong>The PHP file that talks to the sample Force.com app:</strong></p>
  
  <pre><code>&lt;?php
  
      $url = 'https://cmsamp.secure.force.com/GenericApp/services/apexrest/GenericApp';
      $data = $_POST[ 'data'];
  
      $options = array('http' =&gt; array('method'  =&gt; 'POST','content' =&gt; http_build_query($data)));
      $context  = stream_context_create($options);
      $result = file_get_contents($url, false, $context);
  
      echo $result;
  
  ?&gt;
  </code></pre>
  
  <p><strong>Client-side jQuery code that posts form data to the PHP file:</strong></p>
  
  <pre><code>var sample_form_data = {"attributes":{"type":"Generic_App__c"},"Application_Type__c":"iPay","Return_Email__c":"lsmith@cmsrep.com","Name":"Bus Test","ACHRejectFee__c":"123456789","ApplicationDate__c":"2000-01-01","BusinessPhone__c":"(555) 123-4567","Email__c":"thetest@testemail.com","InternetPercentage2__c":"0","MailingState__c":"CA","MOTO7__c":"true","NumOfLocations__c":"15"};
  
  $.post( url, { data: JSON.stringify( sample_form_data ) }, function( result ) { 
      console.log( result );
  });
  </code></pre>
  
  <p><strong>The response from I get from the Force.com app:</strong></p>
  
  <pre><code>"No content to map to Object due to end of inputInsert failed. 
  First exception on row 0; 
  first error: REQUIRED_FIELD_MISSING, 
  Required fields are missing: [Name]: [Name]"
  </code></pre>
  
  <p><strong>Desired "success" response:</strong></p>
  
  <pre><code>"Success: 
  Generic App Object: Bus Test; was successfully created and inserted"
  </code></pre>
  
  <p>This is the output of <code>var_dump($data)</code> in the php code (line breaks added for readability:</p>
  
  <pre><code>string(405)
      "{\"attributes\":
          {\"type\":\"Generic_App__c\"},
      \"Application_Type__c\":\"iPay\",
      \"‌​Return_Email__c\":\"lsmith@cmsrep.com\",
      \"Name\":\"Bus Test\",
      \"ACHRejectFee__c\":\"123456789\",
      \"ApplicationDate__c\":\"2000-01-01\",
      \"B‌​usinessPhone__c\":\"(555) 123-4567\",
      \"Email__c\":\"thetest@testemail.com\",
      \"InternetPercentage2__c\":\"0\"‌​,
      \"MailingState__c\":\"CA\",
      \"MOTO7__c\":\"true\",
      \"NumOfLocations__c\":\"15\"
      }" 
  </code></pre>
  
  <p>The generic app just expects to get a JSON object with the proper fields. When I submit the following through a REST client it works as intended (again, line breaks added for readability):</p>
  
  <pre><code>{"attributes":
      {"type":"Generic_App__c"},
  "Application_Type__c":"iPay",
  "Return_Email‌​__c":"test@example.org",
  "Name":"Bus Test",
  "ACHRejectFee__c":"123456789",
  "ApplicationDate__c":"2000-01-01",
  "BusinessPho‌​ne__c":"(555) 123-4567",
  "Email__c":"thetest@testemail.com",
  "InternetPercentage2__c":"0",
  "Mailing‌​State__c":"CA",
  "MOTO7__c":"true",
  "NumOfLocations__c":"15"} 
  </code></pre>
  
  <p>Anyone have ideas on how to solve this?</p>