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

ArduinoJson doesn’t handle NUL correctly: in your input contains \u0000, the string will be truncated.

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.

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

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
  • Adafruit Circuit Playground Express
  • Arduino MKR ZERO
  • Arduino MKR1000
  • Arduino MKR WiFi 1010
  • Arduino NANO 33 IoT
  • Arduino MKR WAN 1300
  • Arduino MKR WAN 1310
  • Arduino MKR GSM 1400
  • Arduino MKR Vidor 4000
  • Nucleo-32
  • Nucleo-64
  • STM32 Discovery
  • Teensy LC
ARM Cortex-M3 256 bytes
  • Arduino Due
  • Nucleo-144
  • Maple Mini
ARM Cortex-M4 640 bytes
  • Teensy 3.2
  • Teensy 3.5
  • Teensy 3.6
ARM Cortex-M7 576 bytes
  • Teensy 4.0
AVR 334 bytes
  • Adafruit Feather 32u4 Bluefruit LE
  • Adafruit Metro Mini 328
  • Arduino Mega 2560
  • Arduino UNO
  • Arduino UNO WiFi
  • Arduino Leonardo
  • Arduino Micro
  • Arduino Nano
  • Arduino Yún
  • SparkFun RedBoard
  • Teensy 2.0
  • Teensy++ 2.0
megaAVR 330 bytes
  • Arduino Nano Every
  • Arduino UNO WiFi Rev 2
ESP32 284 bytes
  • Adafruit HUZZAH32
  • LoLin D32 Pro
ESP8266 304 bytes
  • Adafruit HUZZAH
  • SparkFun ESP8266 Thing
  • WeMos D1 Mini

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

JsonDocument doc;

deserializeJson(doc, "{'firstname':'Beno\\u00EEt'}");
    
Serial.println(doc["firstname"].as<const 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.

Global warming stripes by Professor Ed Hawkins (University of Reading)