Size of JSON Payload

Posted by Ligar Mugi Syahid on May 28, 2019
1 min read · Last Modified: January 21, 2024

without calculating the “key” size,

use sizeof npm package

and the final touch from here

function formatByteSize(bytes) {
        if(bytes < 1024) return bytes + " bytes";
        else if(bytes < 1048576) return(bytes / 1024).toFixed(3) + " KiB";
        else if(bytes < 1073741824) return(bytes / 1048576).toFixed(3) + " MiB";
        else return(bytes / 1073741824).toFixed(3) + " GiB";
}

Tags: [ javascript  ]