I need to get my size of the JSON going as response.I am using recent REST API's of salesforce using apex annotations like @HTTPGET .Can someone please point me out how will i see the size of output JSON using REST EXPLORER of workbench or someother tools if needed .

  • Do you mean the length of the JSON string itself? Or are you asking about the number of objects or fields in the response or something? – Jeremy Nottingham Oct 3 '12 at 14:37
  • No i know the limit of response is 3MB .I want way of measuring the response size . – Mohith Shrivastava Oct 3 '12 at 14:53
    global static List<Account> getAccounts() {
       List<Account> accounts = [select id, name from Account];
        return accounts;

The code above just does the JSON serialisation that SF is going to do automatically, but does it before hand and logs it out to the debug log. It's a bit wasteful and really only for informal checking

Realistically, I would use Curl from the command line as documented here:



You can look at the Content Length HTTP header to get the length of the response body in bytes. In Workbench REST Explorer, click on Show Raw Response to see the headers on the right hand side of the output.

  • HTTP/1.1 200 OK Server: Content-Encoding: gzip Content-Type: application/json; charset=UTF-8 Transfer-Encoding: chunked Date: Wed, 03 Oct 2012 15:27:28 GMT .................. The content length is missing in workbench in the header – Mohith Shrivastava Oct 3 '12 at 15:28
  • Please note that the following headers aren't allowed: cookie set-cookie set-cookie2 content-length authorization If any of these are used, an Apex exception will be thrown. – Mohith Shrivastava Oct 3 '12 at 15:34

Can you try this

convert the responsebody to a string ( RESPONSE Body (corrected ) is a blob use .tostring())

string name = 'hello this is a test message to find bytes of the string ';
blob encode = EncodingUtil.base64Decode(name);
system.debug('%%%%' + encode.size());


Execute Anonymous: string name = 'hello this is a test message to find bytes of the string';
Execute Anonymous: blob encode = EncodingUtil.base64Decode(name);
Execute Anonymous: system.debug('%%%%' + encode.size());

10:51:47.092 (92605000)|VARIABLE_ASSIGNMENT|[1]|name|"hello this is a test (36 more) ..."
10:51:47.092 (92619000)|STATEMENT_EXECUTE|[2]
10:51:47.093 (93020000)|SYSTEM_METHOD_ENTRY|[2]|system.EncodingUtil.base64Decode(String)
10:51:47.093 (93165000)|SYSTEM_METHOD_EXIT|[2]|system.EncodingUtil.base64Decode(String)
10:51:47.093 (93469000)|VARIABLE_ASSIGNMENT|[2]|encode|BLOB(33 bytes)

10:51:47.093 (93676000)|SYSTEM_METHOD_ENTRY|[3]|System.debug(ANY)
10:51:47.093 (93693000)|USER_DEBUG|[3]|DEBUG|%%%%33
10:51:47.093 (93702000)|SYSTEM_METHOD_EXIT|[3]|System.debug(ANY)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.