title: Converting JSON format string into a real object in Angular
body: <p>I have an JSON format string which I want to add like a parameter to atach to a post request.</p>
  
  <p>I'm trying to do the reques, when I do the request I get this error from my web service:</p>
  
  <pre><code>#0 /opt/assets/WS/ws.php(48): Slim\Slim::handleErrors(8, 'Trying to get p...', '/opt/assets/WS/...', 48, Array)
  #1 [internal function]: {closure}()
  #2 /opt/assets/WS/vendor/slim/slim/Slim/Route.php(468): call_user_func_array(Object(Closure), Array)
  #3 /opt/assets/WS/vendor/slim/slim/Slim/Slim.php(1357): Slim\Route-&gt;dispatch()
  #4 /opt/assets/WS/vendor/slim/slim/Slim/Middleware/Flash.php(85): Slim\Slim-&gt;call()
  #5 /opt/assets/WS/vendor/slim/slim/Slim/Middleware/MethodOverride.php(92): Slim\Middleware\Flash-&gt;call()
  #6 /opt/assets/WS/vendor/slim/slim/Slim/Middleware/PrettyExceptions.php(67): Slim\Middleware\MethodOverride-&gt;call()
  #7 /opt/assets/WS/vendor/slim/slim/Slim/Slim.php(1302): Slim\Middleware\PrettyExceptions-&gt;call()
  #8 /opt/assets/WS/ws.php(59): Slim\Slim-&gt;run()
  #9 {main}
  </code></pre>
  
  <p>It's like the request doesn't contains a real JSON object. How can I transform it? I did some tricks but seems doesn't work.
  That's my script:</p>
  
  <pre><code>assets.controller('AfegirTipusActiusCtrl', function ($scope, $http){
  
                      // Camps formulari text pla
                   /*   $scope.nomAtribut = "&lt;input type='text' name='firstname'&gt;";
                      $scope.mida = "&lt;input type='number' name='firstname'&gt;";
                      $scope.obligatori = "&lt;input type='checkbox' name='vehicle' value='yes'&gt;";   */
  
                      // Construeix combo
                      $http.get('http://10.0.203.73/WS/ws.php/getCombo/1').success(function(data) {
                          $scope.options = data;
                      });
  
                      $scope.atributs = [];
  
                      $scope.addRow = function(){
                          var newRow = {
                              nomAtribut: "",
                              tipus: "",
                              mida: "",
                              prioritat: "",
                              obligatori: "",
                              observacions: ""
                          }
                          $scope.atributs.push(newRow);
                      }
  
                     /* $scope.addField = function() {
                          $scope.atributs.push(newRow);
                      };*/
  
                      $scope.prioritat = $scope.atributs.length;
  
                      // Envia atributs a WS
                      $scope.sendRow = function(){
                          var d = "{'nomAtribut': 'marca','tipus': 'String','mida': '15','prioritat': '1','obligatori': 'No'}";
                          $http.post("http://10.0.203.73/WS/ws.php/tipusactius/alta", angular.toJson(d)).success(function(data){
                              $scope.status = data;
                          })
                      }
              });
  </code></pre>
  
  <p>Edit:</p>
  
  <p>Also I add the php Slim function which parse the request:</p>
  
  <pre><code> $app-&gt;post('/tipusactius/alta', function () use ($app) {
          $json = $app-&gt;request-&gt;getBody();
          header("Content-Type: application/json");
          $json_decode = json_decode($json); // $json_decode conte l'bjecte format a partir del json del request
          echo $json_decode-&gt;{'tipus'};
  
       //   $sql = "INSERt INTO atributs_actiu (nomAtribut, midaAtribut, tipus_actius_idtipus_actius, atributObligatori, ordre, tipusAtributs_idTipus, observacions
       //                  , combo_idcombo, combo_codi) values ('".$json_decode-&gt;{'nomAtribut'}."', '".$json_decode-&gt;{'mida'}."', 1, '0', 1, 1, 'atribut de prova', 1, 1)";
          $sql = "INSERt INTO atributs_actiu (nomAtribut, midaAtribut, tipus_actius_idtipus_actius, atributObligatori, ordre, tipusAtributs_idTipus, observacions
                         , combo_idcombo, combo_codi) values ('".$json_decode-&gt;{'nomAtribut'}."', '3', 1, '0', 1, 1, 'atribut de prova', 1, 1)";
  
          $mysqli=getDB();
          $result = $mysqli-&gt;query($sql);
   });
  </code></pre>
  
  <p>Solved:
  Like @vidriduch told:</p>
  
  <pre><code>$scope.sendRow = function() {
      var d = {
          'nomAtribut': 'marca',
          'tipus': 'String',
          'mida': '15',
          'prioritat': '1',
          'obligatori': 'No'
      };
  
      $http.post("http://10.0.203.73/WS/ws.php/tipusactius/alta", angular.toJson(d)).success(function(data) {
          $scope.status = data;
  })};
  </code></pre>