Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Get the byte size of an object after JSON.stringify

License

NotificationsYou must be signed in to change notification settings

a179346/json-sizeof

Repository files navigation

Get the byte size of an object after JSON.stringify

📩 Installation

npm i json-sizeof

🔗 Links

npm package
Github page

📋 Usage

Example

const{ jsonSizeOf}=require('json-sizeof');constobj={str1:'I am a string!',obj1:{str2:456,obj2:null,obj3:undefined},};constbytes=jsonSizeOf(obj);// expected 57

📌 Why

jsonSizeOf(obj) equals to Buffer.byteLength(JSON.stringify(obj)).
but isfaster andless likely to cause "Javascript heap out of memory"

constobj={};for(leti=0;i<8000000;i++){obj['test'+i]='ABCDEFGHIJKLMNOPQRSTUVWXYZ';}// expected: 342888891jsonSizeOf(obj);// The following line will cause "JavaScript heap out of memory" fatal error// if you do not maually increase the memory usage of node app.Buffer.byteLength(JSON.stringify(obj));

[8]ページ先頭

©2009-2025 Movatter.jp