Skip to content

Arduino JSON breaks starting with v 3.9.0 on Arduino #350

Description

@jfandl325

Platform

ESP32

IDE / Tooling

Arduino (IDE/CLI)

What happened?

My code was running fine, then I upgraded from 3.8.0 to 3.9.1 and all my "StaticJsonDocument<512> doc;"
would not compile any longer. I have #include <ArduinoJson.h> in my code.

I reverted back to 3.8.0 and everything works once again. I reinstalled 3.9.1 and it was broken again, then removed it and tested with 3.9.0 and had the same problem. It isn't until I put 3.8.0 back in that the issue goes away.

Stack Trace

I have the arduino nano so I have no debug option with this board.

Minimal Reproductible Example (MRE)

#include <ArduinoJson.h>

StaticJsonDocument<256> doc;
doc["modeTime"] = readModeTime;
doc["tempTarget"] = readTempTarget;

I confirm that:

  • I have read the documentation.
  • I have searched for similar discussions.
  • I have searched for similar issues.
  • I have looked at the examples.
  • I have upgraded to the lasted version of ESPAsyncWebServer (and AsyncTCP for ESP32).

Activity

  1. mathieucarbou commented on Nov 28, 2025

    @mathieucarbou
    Member

    Hi,
    Can you please try with this branch: https://github.com/ESP32Async/ESPAsyncWebServer/tree/issue-346 ?
    I fixed 2 bugs today that are not yet merged. See #349

  2. jfandl325 commented on Nov 28, 2025

    @jfandl325
    Author
  3. mathieucarbou commented on Nov 28, 2025

    @mathieucarbou
    Member

    I think you should add an else block to include ArduinoJson.h if not found. You code doesn’t handle automatic inclusion if it doesn’t find it before its loaded.

    That's more your IDE (Arduino IDE) that is not correctly working. If you use a real development environment like platformio on vscode, it works.

    Arduino IDE is parsing the .ino file to build its own compilation path based on the headers it finds and tries to match that with your common libraries fodler. That's a hack they do to facilitate non-dev people's life, but that's ugly and requires to know how it works.

    If you were using a real dev. env, it would correctly handle transitive dependencies with the library.json file (something that is not possible in arduino ide), and it would also build a correct compile path based on the sources and libraries in the project. Then, the macro #if __has_include("ArduinoJson.h") would correctly work.

    https://www.geeksforgeeks.org/cpp/__has_include-in-cpp-17/

    The __has_include is a special operator to work with preprocessor directives that allow you to check if a particular header file is available for inclusion in your program. It is a conditional compilation feature introduced in C++17 that helps you write portable code that can handle different environments or platforms.

    Arduino IDE not being a real dev. environment, there are many basic rules it does not adhere to, like this one sadly.

    So Option 2 is the right one for you.... You need to help your poor IDE to correctly work.

  4. mathieucarbou commented on Nov 28, 2025

    @mathieucarbou
    Member

    Also have a look at the examples in the project, especially this one:

    https://github.com/ESP32Async/ESPAsyncWebServer/blob/main/examples/Json/Json.ino

    you will see that ArduinoJson.h is not even included in the ino file. And it compiles.

    But compilation works with platformio because it is a correct c++ dev environment that correctly setups a build environment.

  5. nomakewan commented on Dec 3, 2025

    @nomakewan

    As a note, the Arduino IDE by default sets everything to C++11, which is why __has_include does not work (as it was introduced in C++17). There are several ways to override that should you so choose, see this discussion: https://forum.arduino.cc/t/which-version-of-c-is-currently-supported/1285868/16

  6. me-no-dev commented on Dec 3, 2025

    @me-no-dev
    Member

    In the Arduino core for ESP32 we set to -std=gnu++2a and use __has_include on many places. So far it works without issues. As long as your sketch includes ArduinoJson, then __has_include("ArduinoJson.h") should work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions