cancel
Showing results for 
Search instead for 
Did you mean: 

range error invalid string length at json.stringify

0 Kudos

Hi ,

I am facing issue at this line in my xsjs file

$.response.setBody(JSON.stringify(result));

ERROR MSG:range error invalid string length at json.stringify



pfefferf
Active Contributor

Can you show what value your result variable contains.

0 Kudos

Its a array of object . . Multiple rows will be return from the data base query. . I am juz trying to pass it to front end . .

pfefferf
Active Contributor

Again, please show the content/structure of the result variable.

0 Kudos

Hi Florian,

Same error for me also.
Attached screenshot.

Thanks & Regards,
Yaswanth

invalid-string-length.png

0 Kudos

This happens only when we have huge data in the array.

pfefferf
Active Contributor
0 Kudos

Seems that your node process runs out of memory during serialization of the "huge array" data. You can try to do the serialization in chunks or increase the memory for the node process.

0 Kudos

How can it could be done ?
can you please elaborate a little bit
Any reference code will be helpful

Accepted Solutions (0)

Answers (1)

Answers (1)

pfefferf
Active Contributor
0 Kudos

As mentioned in the comments above, the error ususally appears because runnining into a memory issue.

You can try

  • to process the serialization of your large array in chunks (e.g. if you have 1000 entries in your array, to a stepwise serialization per 100 entries for instance and concatenate the result).
  • increase the memory of your node process aka application (assuming you are using an XSA node module). You can do that via the deployment descriptor or manually (for test reasons) via the SAP HANA XSA Cockpit or the XS CLI (check the scaling options for memory here)