How to fix ArduinoJson error: DynamicJsonBuffer is a class from ArduinoJson 5

When you see an error message like

Compiling .pio\build\d1_mini\src\main.cpp.o
src\main.cpp:22:11: error: DynamicJsonBuffer is a class from ArduinoJson 5. Please see arduinojson.org/upgrade to learn how to upgrade your program to ArduinoJson version 6
       DynamicJsonBuffer jsonBuffer;

in your PlatformIO or Arduino project using the ArduinoJson library, your code was written for an old version of ArduinoJson.

According to the official ArduinoJson 5 to ArduinoJson 6 migration guide, you need to use DynamicJsonDocument instead. Note that DynamicJsonDocument uses a slightly different API compared to DynamicJsonDocument, hence you might need to adjust more than just changing the class names. But as a first step, replace e.g.

DynamicJsonBuffer json;

by

DynamicJsonDocument json(1024);