How can i calculate the size of JSON response in R...
# suitescript
r
How can i calculate the size of JSON response in Restlet
b
sounds weird, but try stringifying the response and start counting bytes
if you have to be robust and support above ascii character points, go find something on npm like https://www.npmjs.com/package/byte-length
r
@battk stringifying gives json data format. I am trying to measure the size to limit 10 mb response
b
Whats your input content type
r
Have not decided yet but can be simple get call or put request with list of record ids. I mean can be simple get call or put request with json data as input
b
If json is your input, then a object must be your output
Stringify your output to estimate the number of bytes in it
r
Stringify convert json to string but is there any JavaScript function to convert the strings into number of bytes
b
Not in suitescript 2
You can try seeing if 2.1 has TextEncoder
And use that instead
But honestly you should probably be trying to limit your output by using paging
r
Sorry did not get to limit output using paging. External application want to call restlet and if understand correctly from external application mAke multiple calls to restlet and provide the response in smaller formats
b
No idea what that means
r
You have suggested to limit the output using paging. Just trying to understand what does it mean
b
Assuming you are working with a search
Divide your output into pages and make the request specify which page to return
For example , if there are 1000 search results, divide them into 10 pages of 100 search results
Return 1 page at a time and make the request specify which page to return
r
So external application to make first request to call the search and get the number of results say 1000 results and then make another 10 calls to the restlet to get 100 results each
b
plenty of ways to do it, the basic idea is to divide up your results
ill simply say that the usual approach is to return results in the first response and have the response include information that there are additional pages
r
You are right. Actually client is asking to have only one call to the rest let and it returns everything in one call which is technically not a scalable solution
@battk thank you