title: How to extract JSON object in a Google Apps Script web app?
body: <p>Can someone point out why this function would not work?</p>
  <pre><code> function doPost(e) {
          var contents = JSON.parse(e.postData.contents);
          var data = JSON.stringify(contents,null,4);
          var x = data[&quot;inboundSMSMessageList&quot;];
          var y= x.inboundSMSMessage[0].senderAddress;
          GmailApp.sendEmail(&quot;sample.email@gmail.com&quot;, &quot;test5&quot;, y); 
          }
  </code></pre>
  <p>It takes an event listener, e, parses its contents and then stringily the contents using JSON.parse() and JSON.stringify() respectively. This is a sample stringified data:</p>
  <pre><code>var data = {
      &quot;inboundSMSMessageList&quot;: {
          &quot;inboundSMSMessage&quot;: [
              {
                  &quot;dateTime&quot;: &quot;Sun Jan 03 2021 01:25:03 GMT+0000 (UTC)&quot;,
                  &quot;destinationAddress&quot;: &quot;tel:21585789&quot;,
                  &quot;messageId&quot;: &quot;5ff11cef73cf74588ab2a735&quot;,
                  &quot;message&quot;: &quot;Yes&quot;,
                  &quot;resourceURL&quot;: null,
                  &quot;senderAddress&quot;: &quot;tel:+63917xxxxx&quot;
              }
          ],
          &quot;numberOfMessagesInThisBatch&quot;: 1,
          &quot;resourceURL&quot;: null,
          &quot;totalNumberOfPendingMessages&quot;: 0
      }
  }
  </code></pre>
  <p>The script seems to fail on the second to the last line (var y); but when I run it on the sample data, I'm able to access the key and value pair Im targeting- which is the sender address (it sends &quot;tel:+63917xxxxx: to my email). Anybody has an idea why it's failing when it's ran as a web app?</p>