ArduinoJson can decode Unicode escape sequences (\uXXXX) in JSON documents, but you can disable this feature to reduce the library’s size.

Description

When ARDUINOJSON_DECODE_UNICODE is set to 1, deserializeJson() converts the Unicode escape sequences to UTF-8 characters.

When ARDUINOJSON_DECODE_UNICODE is set to 0, deserializeJson() returns NotSupported when the input contains a Unicode escape sequence.

The default value is 1.

The default value used to be 0. It changed to 1 in ArduinoJson 6.16

Impact on code size

This feature increases the library’s size; that’s why it used to be disabled by default. The size increase depends on the microcontroller’s architecture, as you can see in the table below.

Architecture Code size Boards (non exhaustive)
ARM Cortex-M0 236 bytes
ARM Cortex-M3 256 bytes
ARM Cortex-M4 640 bytes
ARM Cortex-M7 576 bytes
AVR 334 bytes
megaAVR 330 bytes
ESP32 284 bytes
ESP8266 304 bytes

These results depend on the compiler version.

How to disable support for Unicode characters in ArduinoJson?

If your input doesn’t contain any Unicode escape sequence, you remove this feature to reduce the library’s size. To do so, simply define ARDUINOJSON_DECODE_UNICODE to 0 before including ArduinoJson.h.

#define ARDUINOJSON_DECODE_UNICODE 0
#include <ArduinoJson.h>

Example

StaticJsonDocument<300> doc;

deserializeJson(doc, "{'firstname':'Beno\\u00EEt'}");
    
Serial.println(doc["firstname"].as<char*>()); // Benoît

👨‍🏫 Try this example online

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_DECODE_UNICODE in each compilation unit; otherwise, the executable will be much bigger because it will contain two variants of the library.