Description

The macro ARDUINOJSON_ENABLE_COMMENTS controls the support of comments in JSON input documents. The JSON format doesn’t support comments, but they are very handy for configuration files. Here is an example:

{
  // The machine we want to ping
  "host": "arduinojson.org",

  /* The port we should connect to */
  "port": 80
}

When ARDUINOJSON_ENABLE_COMMENTS is set to 1, deserializeJson() ignores all comments in the input, both block comments (/* this is a block comment */) and trailing comments (// this is a trailing comment).

When ARDUINOJSON_ENABLE_COMMENTS is set to 0, deserializeJson() returns InvalidInput if the input contains a comment.

Only 0 and 1 are valid. Any other value (like false or true) will produce a compilation error.

Default value

The default value is 0, which means that comments are disabled by default; it’s an opt-in feature.

How to enable comments in ArduinoJson?

If your input document contains comments, you must set ARDUINOJSON_ENABLE_COMMENTS to 1 before including the library:

#define ARDUINOJSON_ENABLE_COMMENTS 1
#include <ArduinoJson.h>

Several .ino or .cpp files?

Be careful if several compilation units compose your program, i.e., if your project contains several .ino or .cpp files.

You should define the same value of ARDUINOJSON_ENABLE_COMMENTS in each compilation unit; otherwise, the executable will be much bigger because it will contain two variants of the library.