title: How do you truncate a String to a max number of bytes in Google Apps Script?
body: <p>I am parsing a JSON object obtained by <code>URLFetchApp.fetch()</code> and need to truncate a string value to a max number of bytes. It seems like some combination of the Google Apps Script <code>Utilities Class</code> and <code>HTTPResponse Class</code> is where I will find the answer, but I can not figure out which methods to use and how to put them together.</p>
  <pre><code>{object: {key: 'string'}}
  </code></pre>
  <p>something like:</p>
  <pre><code>object.key.string.toBytes().substringAsBytes(0,maxBytes).backToString()
  </code></pre>
  <p><a href="https://developers.google.com/apps-script/reference/utilities" rel="nofollow noreferrer">https://developers.google.com/apps-script/reference/utilities</a></p>
  <p><a href="https://developers.google.com/apps-script/reference/url-fetch/http-response" rel="nofollow noreferrer">https://developers.google.com/apps-script/reference/url-fetch/http-response</a></p>