ArduinoJson: F.A.Q

What are the differences between StaticJsonBuffer and DynamicJsonBuffer?

  StaticJsonBuffer DynamicJsonBuffer
Size fixed variable :+1:
Location stack :warning: (1) heap
Memory overhead small :+1: big
Code size small :+1: big
Speed fast :+1: slow(3)
Cleanup automatic automatic
Reusable no(2) no(2)

(1) :warning: on most platforms, the stack cannot occupy all the RAM; for instance, it’s limited to 4KB on the ESP8266.

(2) there is a workaround (see How to reuse a JsonBuffer? if you are looking for troubles).

(3) A DynamicJsonBuffer calls malloc() to allocate its memory, and it may have to do this several times if it needs to grow. However, you can specify an initial size to the constructor, so as to make sure that the buffer is big enough and that no further allocation will be needed.

:information_source: As a general rule, if your StaticJsonBuffer is bigger than 2KB, then it may be a good time to switch to a DynamicJsonBuffer.

Fork me on GitHub