"SyntaxError: Expected end of stream at char..."

in September 16th, 2024
person using a laptop

This syntax error occurred when attempting to parse a response returned from a call made to a Suitelet.

About the Syntax Error

“SyntaxError: Expected end of stream at char 1427860”.

This error is an indication of an issue with the string that is being attempted to parse.

In my case, for an unknown reason, “/n/n/n/n” was appended to the end of the response object string being returned.

Resolving this Syntax Error

There are multiple ways of resolving this error. The way I found to be consistent was getting the last index of the closing bracket to the response body object and removing all characters after that index.

Resolve this issue by completing the following steps:

// get last index of closing bracket
var lastIndex = suiteletResponse.getBody().lastIndexOf('}');
if (lastIndex !== -1) {
  // trim characters after last index of closing bracket from response body
  var trimmedResponseBody = suiteletResponse.getBody().slice(0, lastIndex + 1);
}
var suiteletResponseBody = JSON.parse(trimmedResponseBody)

Parsing the trimmed response should give you a properly returned object!

Author: An Phan


Got stuck on a step in this article?

We like to update our blogs and articles to make sure they help resolve any troubleshooting difficulties you are having. Sometimes, there is a related feature to enable or a field to fill out that we miss during the instructions. If this article didn't resolve the issue, please use the chat and let us know so that we can update this article!

 
 

Want to keep learning?

Our team of NetSuite professionals has written articles on a wide variety of NetSuite topics, from SuiteCommerce tips, to recommended NetSuite solutions, to available support services, and more! 

Your cart