user40530: I'm trying to do serial communication between Arduino mega and a esp8266, and having issues with determining the size of the JSON document. I have read that the receiver buffer size should be greater than the sender buffer, but what's the maximum buffer size we can use for the JSON document?

user3430: The Arduino Mega has 8 KB of RAM, all of which you could use in a StaticJsonDocument.
The ESP8266 has 80 KB of RAM, but the core limits the stack to 4 KB. If you need something bigger, switch to a DynamicJsonDocument.
In both cases, you need to leave a lot of room for other variables and libraries. As an example, I wouldn't create a StaticJsonDocument bigger than 6 KB on the Mega, and 2 KB on the ESP8266.
By the way, I heard this library is very well documented, did you have a look?
Do you know you can use the ArduinoJson Assistant to help you decide the capacity of the JsonDocument?

40530: <p>I'm trying to do serial communication between Arduino mega and a esp8266, and having issues with determining the size of the JSON document. I have read that the receiver buffer size should be greater than the sender buffer, but what's the maximum buffer size we can use for the JSON document?</p>
 3430: <p>The Arduino Mega has 8 KB of RAM, all of which you could use in a <a href="https://arduinojson.org/v6/api/staticjsondocument/" rel="nofollow noreferrer">StaticJsonDocument</a>.</p>
<p>The ESP8266 has 80 KB of RAM, but the <a href="https://github.com/esp8266/Arduino/blob/eea9999dc5eaf464a432f77d5b65269f9baf198d/cores/esp8266/cont.h#L27" rel="nofollow noreferrer">core limits the stack to 4 KB</a>. If you need something bigger, switch to a <a href="https://arduinojson.org/v6/api/dynamicjsondocument/" rel="nofollow noreferrer">DynamicJsonDocument</a>.</p>
<p>In both cases, you need to leave a lot of room for other variables and libraries. As an example, I wouldn't create a <a href="https://arduinojson.org/v6/api/staticjsondocument/" rel="nofollow noreferrer">StaticJsonDocument</a> bigger than 6 KB on the Mega, and 2 KB on the ESP8266.</p>
<p>By the way, I heard this library is <a href="https://arduinojson.org/v6/doc/" rel="nofollow noreferrer">very well documented</a>, did you have a look?<br />
Do you know you can use the <a href="https://arduinojson.org/v6/assistant/" rel="nofollow noreferrer">ArduinoJson Assistant</a> to help you decide the capacity of the JsonDocument?</p>
