title: How can I extract an element from a returned json "record" in Javascript/jQuery (Meteor)?
body: <p>If a REST call returns this json:</p>
  
  <pre><code>{"success":true,"data":{"number":"0871632810","status":"YES","carrier_name":"ATT Mobility","carrier_id":"","sms_address":"0871632810@txt.att.net","mms_address":"0871632810@mms.att.net"}}
  </code></pre>
  
  <p>...how can I access one element from it - e.g., if I want the "sms_address" portion?</p>
  
  <p>This:</p>
  
  <pre><code>'getTextAddrAsEmailAddr': function(phone) {
      this.unblock();
      var restcall = 'http://www.reminder.com/phone.check.php?number=' + phone;
      console.log('restcall is '+ restcall);
      return Meteor.call("GET", restcall);
  }
  </code></pre>
  
  <p>...returns "undefined"</p>
  
  <p>When I took a flyer on this:</p>
  
  <pre><code>return Meteor.call("GET", restcall).sms_address;
  </code></pre>
  
  <p>...I got: "<em>Exception while simulating the effect of invoking 'insertPerson' TypeError: Cannot read property 'sms_address' of undefined
      at Meteor.methods.getTextAddrAsEmailAddr</em>"</p>
  
  <p>So what do I need to do get at that value?</p>
  
  <h2>UPDATE</h2>
  
  <p>I am now trying this:</p>
  
  <pre><code>function getTextAddrAsEmailAddr(scope, phone) {
      scope.unblock();
      var restcall = 'http://www.reminder.com/phone.check.php?number=' + phone;
      return HTTP.get(restcall);
  }
  
  Meteor.methods({
      'insertPerson': function(firstname, lastname, streetaddr1, streetaddr2, placename, stateorprov, zipcode, emailaddr, phone, notes) {
          console.log('insertPerson reached'); // TODO: Remove before deploying
          check(firstname, String);
          . . .
          console.log('phone is ' + phone);
          var textAddrAsEmailAddr = getTextAddrAsEmailAddr(this, phone);
          console.log('textAddrAsEmailAddr is ' + textAddrAsEmailAddr);
  
          People.insert({
              per_firstname: firstname,
              per_lastname: lastname,
              per_streetaddr1: streetaddr1,
              per_streetaddr2: streetaddr2,
              per_placename: placename,
              per_stateorprov: stateorprov,
              per_zipcode: zipcode,
              per_emailaddr: emailaddr,
              per_phone: phone,
              per_textaddrasemailaddr: phone,
              per_notes: notes,
              per_createdBy: this.userId
          });
          return true;
      }
  });
  </code></pre>
  
  <p>...but still get, "<em>Exception while simulating the effect of invoking 'insertPerson' Error: Can't make a blocking HTTP call from the client; callback required.(…) Error: Can't make a blocking HTTP call from the client; callback required.</em>"</p>
  
  <p>I don't know where this missing callback is supposed to go. insertPersion() is called like this:</p>
  
  <pre><code>Meteor.call('insertPerson', firstname, lastname, streetaddr1, streetaddr2, placename, stateorprov, zipcode, emailaddr, phone, notes, function(err) {
    if (err) {
      Session.set("lastErrMsg", err.message);
    } else {
      alert(firstname + ' ' + lastname + ' inserted');
      $('#firstName').val("");
      $('#lastName').val("");
      $('#streetAddress1').val("");
      $('#streetAddress2').val("");
      $('#placename').val("");
      $('#stateorprovince').val("");
      $('#postalcode').val("");
      $('#emailAddr').val("");
      $('#inputPhone').val("");
      $('#notes').val("");
  
      $('#firstName').focus();
    } // else
  }); // Meteor call
  </code></pre>
  
  <p>...from the template's events method:</p>
  
  <h2>UPDATE 2</h2>
  
  <p>So with this modified code (based on the suggestion to "change it to: if (Meteor.isServer)) {return HTTP.get(restcall); } else {return 'will_be_filled_in_on_server';}"):</p>
  
  <pre><code>function getTextAddrAsEmailAddr(scope, phone) {
      scope.unblock();
      var restcall = 'http://www.reminder.com/number.phone.php?number=' + phone;
      if (Meteor.isServer) {
        return HTTP.get(restcall);
      }
      else {
        return 'will_be_filled_in_on_server';
      }
  }
  
  Meteor.methods({
      'insertPerson': function(firstname, lastname, streetaddr1, streetaddr2, placename, stateorprov, zipcode, emailaddr, phone, notes) {
          console.log('insertPerson reached'); // TODO: Remove before deploying
          check(firstname, String);
          . . .
          console.log('phone is ' + phone);
          var textAddrAsEmailAddr = getTextAddrAsEmailAddr(this, phone);
          console.log('textAddrAsEmailAddr is ' + textAddrAsEmailAddr);
  </code></pre>
  
  <p>...I don't get err msgs, but for the last console.log, I get "<em>textAddrAsEmailAddr is will_be_filled_in_on_server</em>" </p>
  
  <p>I was hoping that would be the value from the REST call, but it simply falls through to the else clause.</p>
  
  <h2>UPDATE 3</h2>
  
  <p>I also tried this:</p>
  
  <pre><code>// function getTextAddrAsEmailAddr(scope, phone) {
  //   scope.unblock();
  //   var restcall = 'http://www.xminder.com/number.check.php?number=' + phone;
  //   if (Meteor.isServer) {
  //     return HTTP.get(restcall);
  //   } else {
  //     return 'will_be_filled_in_on_server';
  //   }
  // }
  
  Meteor.methods({
    'insertPerson': function(firstname, lastname, streetaddr1, streetaddr2, placename, stateorprov, zipcode, emailaddr, phone, notes) {
        console.log('insertPerson reached'); // TODO: Remove before deploying
        check(firstname, String);
        check(lastname, String);
        check(streetaddr1, String);
        check(streetaddr2, String);
        check(placename, String);
        check(stateorprov, String);
        check(zipcode, String);
        check(emailaddr, String);
        check(phone, String);
        check(notes, String);
  
        console.log('phone is ' + phone);
        var textAddrAsEmailAddr = getTextAddrAsEmailAddr(this, phone);
        Meteor.call("getTextAddrAsEmailAddr", phone, function(error, result) {
          if (error) {
            console.log(error.reason);
            return;
          }
        })
        console.log('textAddrAsEmailAddr is ' + textAddrAsEmailAddr);
  
        People.insert({
          per_firstname: firstname,
          per_lastname: lastname,
          per_streetaddr1: streetaddr1,
          per_streetaddr2: streetaddr2,
          per_placename: placename,
          per_stateorprov: stateorprov,
          per_zipcode: zipcode,
          per_emailaddr: emailaddr,
          per_phone: phone,
          per_textaddrasemailaddr: phone,
          per_notes: notes,
          per_createdBy: this.userId
        });
        return true;
      },
      'getTextAddrAsEmailAddr': function(phone) {
        return getTextAddrAsEmailAddr(this, phone);
           this.unblock();
          var restcall = 'http://www.reminder.com/phone.check.php?number=' + phone;
          console.log('restcall is '+ restcall);
          return Meteor.call("GET", restcall);
          //return Meteor.call("GET", restcall).sms_address;
      }
  });
  </code></pre>
  
  <p>...but both the browser console and the command prompt console complain, "<em>Exception while simulating the effect of invoking 'insertPerson' ReferenceError: getTextAddrAsEmailAddr is not defined(…) ReferenceError: getTextAddrAsEmailAddr is not defined
      at Meteor.methods.insertPerson</em>"</p>
  
  <p>But it's right there - as you can see above, the "getTextAddrAsEmailAddr" method <em>is</em> defined.</p>
  
  <p>Okay, I think "Meteor In Action" has a section on how to do this; I will try their methodology tonight or sometime this weekend.</p>