title: Convert object to json in angular
body: <p>I am trying to convert object as json In my <code>updateDetails</code> method But am getting <code>undefined</code> in <code>console.log</code> after converting as <code>json</code>.<br>Whats wrong here?my cod is..<br><br>
  HTML:</p>
  
  <pre><code>&lt;body ng-app="myApp" ng-controller="myCtrl" ng-init="init()"&gt;
  
                  &lt;form id="show_details" ng-repeat="data in editProjDetails"&gt;
                      &lt;div&gt;
                          &lt;label&gt;&lt;input type="text" class="form-control projectName required onlyAlphaNumeric" ng-model="data.ProjectName" ng-disabled="all"&gt;&lt;/label&gt;
                      &lt;/div&gt;
                      &lt;div&gt;
                          &lt;label&gt;&lt;input type="text" class="form-control client required onlyAlphabets" ng-model="data.Client" ng-disabled="all"&gt;&lt;/label&gt;
                      &lt;/div&gt;
                      &lt;div id="projectCoOrdBlock"&gt;
                          &lt;label&gt;&lt;input type="text" class="form-control projectCoOrd  onlyAlphabets" ng-model="data.ProjectCoordinator" ng-disabled="true"&gt;&lt;/label&gt;
                      &lt;/div&gt;
                      &lt;div&gt;
                          &lt;label&gt;&lt;input type="text" class="form-control required onsiteCoOrd onlyAlphabets" ng-model="data.OnsiteCoordinator" ng-disabled="all"&gt;&lt;/label&gt;
                      &lt;/div&gt;
                      &lt;div id="resourceBlock"&gt;
                          &lt;label&gt;&lt;input type="text"  class="form-control resource  onlyNumeric" ng-model="data.ResourceAllocated" ng-disabled="true"&gt;&lt;/label&gt;
                      &lt;/div&gt;
                      &lt;div&gt;
                          &lt;span class="pull-right btnMarginTop"&gt;
                              &lt;button class="btn btn-primary" id="projectDetailsEdit" ng-if="!editMode" ng-click="editDetails()"&gt;Edit&lt;/button&gt;
                              &lt;button class="btn btn-primary" id="projectDetailsUpdate" ng-if="editMode" ng-click="updateDetails(data)"&gt;Update&lt;/button&gt;
                          &lt;/span&gt;
                      &lt;/div&gt;
                  &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>SCRIPT<br><br></p>
  
  <pre><code>var app = angular
                      .module("myApp", [])
                      .controller("myCtrl", function ($scope, $http) {
                          $scope.editMode = false;
                          $scope.all = true;
                          $scope.init = function () {
                              $scope.getId();
                          }
                          $scope.getId = function () {
                              var url = document.URL;
                              var id = /id=([^&amp;]+)/.exec(url)[1];
                              var result = id ? id : ' ';
                              $scope.getProjectDetails(result);   
                          }
  
                          $scope.goEvent = function () {
                              $scope.editMode = !$scope.editMode;
                          } 
                          $scope.updateDetails = function (data) {
                             debugger
                              $scope.editedArrayDetails = [];
                              $scope.editedArrayDetails.push(data);
                              $scope.json = angular.toJson($scope.data);
                              console.log($scope.data)
                              $scope.goEvent();
                          }
                      })
  </code></pre>
  
  <p>This is my json fromat:</p>
  
  <p><a href="https://i.stack.imgur.com/HgRNR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HgRNR.png" alt="enter image description here"></a></p>
  
  <p>I want to save my data with these names</p>
  
  <pre><code>if ($scope.json) {
                                  $scope.json = { "project_id": Id, "name": ProjectName, "client": Client, "onsite_coordinator": OnsiteCoordinator };
                              }
  </code></pre>
  
  <p>But am getting <code>Id</code>,<code>ProjectName</code>,<code>Client</code>,<code>OnsiteCoordinator</code> is undefined.</p>