How to find the size of a json object? #2557
Replies: 4 comments 5 replies
-
|
Beta Was this translation helpful? Give feedback.
-
|
I have a similar question, due to trying to track down the cause of a stack overflow --- I specifically want the size of the json object (along with all its sub objects, etc.) in memory. |
Beta Was this translation helpful? Give feedback.
-
|
I need to use http bulk API that limits the size of json text representation I can send. So I would like to have an efficient way of doing something like json bulk;
size_t upperBound = 0;
for (const auto& event : json_events)
{
upperBound += event.upper_bound_size();
if (upperBound < threshold)
bulk.push_back(event);
else
break;
}
send(bulk); |
Beta Was this translation helpful? Give feedback.
-
|
What you want to limit is not the in-memory object size, but the serialized size (i.e. how many bytes it occupies when written or transmitted). That means the correct unit is UTF-8 byte length of the serialized JSON string. ✅ Correct approach (language-agnostic concept)
✅ Example (JavaScript / Node.js) ✅ Browser-compatible approach This matches:
✅ Best practice |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to limit the size of the JSON object to 16KB. Is it possible to check the size of the JSON object and cap it to 16KB?
Beta Was this translation helpful? Give feedback.
All reactions