Hi Sara,
I would appreciate your comments about this issue
Background:
1- In page 66 Build_Web_Servers_ESP32_ESP8266_V2.pdf you suggest installing Arduino_JSON
2- In tutorial https://randomnerdtutorials.com/esp32-http-get-post-arduino/
you wrote “You also need to install the Arduino_JSON library”
But later in the same tutorial (https://randomnerdtutorials.com/esp32-http-get-post-arduino/)
the code for json request is
// If you need an HTTP request with a content type: application/json, use the following:
//http.addHeader(“Content-Type”, “application/json”);
//int httpResponseCode = http.POST(“{\”api_key\”:\”tPmAT5Ab3j7F9\”,\”sensor\”:\”BME280\”,\”value1\”:\”24.25\”,\”value2\”:\”49.54\”,\”value3\”:\”1005.14\”}”);
Code that I do not found user friendly.
Looking for alternatives I found this code
// Prepare JSON document
DynamicJsonDocument doc(2048);
doc[“hello”] = “world”;
// Serialize JSON document
String json;
serializeJson(doc, json);
WiFiClient client; // or WiFiClientSecure for HTTPS
HTTPClient http;
// Send request
http.begin(client, “http://httpbin.org/post”);
http.POST(json);
But it seems that this code does not work Arduino_JSON
My questions:
1- What is your opinion about replacing Arduino_JSON with ArduinoJson.
2- Are there any licensing issues?
3- How to implement a more friendly code for a POST request with json and Arduino_JSON library
Thanks in advance for your help
Hi.
Arduino_JSON is one of the most simple libraries for JSON. It works fine for simple projects. It works for me for most of the projects without adding much complexity because I don’t need to do complex stuff with JSON objects.
AduinoJSON has more advanced functions. You can find many examples and explanations about how to use it on the website: https://arduinojson.org/
You can use one or the other. It will depend on your preferences. You just need to take into account, that one library is not compatible with the other.
Regards,
Sara