Bblanchon/ArduinoJson: JSON Library For Arduino And ... - GitHub

ArduinoJson

GitHub Workflow Status Continuous Integration Fuzzing Status Coveralls branch GitHub stars GitHub Sponsors

ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).

Features

  • JSON deserialization
    • Optionally decodes UTF-16 escape sequences to UTF-8
    • Optionally supports comments in the input
    • Optionally filters the input to keep only desired values
    • Supports single quotes as a string delimiter
    • Compatible with NDJSON and JSON Lines
  • JSON serialization
    • Can write to a buffer or a stream
    • Optionally indents the document (prettified JSON)
  • MessagePack serialization
  • MessagePack deserialization
  • Efficient
    • Twice smaller than the "official" Arduino_JSON library
    • Almost 10% faster than the "official" Arduino_JSON library
    • Consumes roughly 10% less RAM than the "official" Arduino_JSON library
    • Deduplicates strings
  • Versatile
    • Supports custom allocators (to use external RAM chip, for example)
    • Supports String, std::string, and std::string_view
    • Supports Stream and std::istream/std::ostream
    • Supports Flash strings
    • Supports custom readers and custom writers
    • Supports custom converters
  • Portable
    • Usable on any C++ project (not limited to Arduino)
    • Compatible with C++11, C++14 and C++17
    • Support for C++98/C++03 available on ArduinoJson 6.20.x
    • Zero warnings with -Wall -Wextra -pedantic and /W4
    • Header-only library
    • Works with virtually any board
      • Arduino boards: Uno, Due, Micro, Nano, Mega, Yun, Leonardo...
      • Espressif chips: ESP8266, ESP32
      • Lolin (WeMos) boards: D1 mini, D1 Mini Pro...
      • Teensy boards: 4.0, 3.2, 2.0
      • Particle boards: Argon, Boron, Electron, Photon...
      • Texas Instruments boards: MSP430...
      • Soft cores: Nios II...
    • Tested on all major development environments
      • Arduino IDE
      • Atmel Studio
      • Atollic TrueSTUDIO
      • Energia
      • IAR Embedded Workbench
      • Keil uVision
      • MPLAB X IDE
      • Particle
      • PlatformIO
      • Sloeber plugin for Eclipse
      • Visual Micro
      • Visual Studio
    • Even works with online compilers like wandbox.org
    • CMake friendly
  • Well designed
    • Elegant API
    • Thread-safe
    • Self-contained (no external dependency)
    • const friendly
    • for friendly
    • TMP friendly
    • Handles integer overflows
  • Well tested
    • Unit test coverage close to 100%
    • Continuously tested on
      • Visual Studio 2017, 2019, 2022
      • GCC 4.8, 5, 6, 7, 8, 9, 10, 11, 12
      • Clang 3.9, 4.0, 5.0, 6.0, 7, 8, 9, 10, 11, 12, 13, 14, 15
    • Continuously fuzzed with Google OSS Fuzz
    • Passes all default checks of clang-tidy
  • Well documented
    • Tutorials
    • Examples
    • How-tos
    • FAQ
    • Troubleshooter
    • Book
    • Changelog
  • Vibrant user community
    • Most popular of all Arduino libraries on GitHub
    • Used in hundreds of projects
    • Responsive support

Quickstart

Deserialization

Here is a program that parses a JSON document with ArduinoJson.

const char* json = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}"; JsonDocument doc; deserializeJson(doc, json); const char* sensor = doc["sensor"]; long time = doc["time"]; double latitude = doc["data"][0]; double longitude = doc["data"][1];

See the tutorial on arduinojson.org

Serialization

Here is a program that generates a JSON document with ArduinoJson:

JsonDocument doc; doc["sensor"] = "gps"; doc["time"] = 1351824120; doc["data"][0] = 48.756080; doc["data"][1] = 2.302038; serializeJson(doc, Serial); // This prints: // {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}

See the tutorial on arduinojson.org

Sponsors

ArduinoJson is thankful to its sponsors. Please give them a visit; they deserve it!

Programming Electronics Academy

1technophile LArkema

If you run a commercial project that embeds ArduinoJson, think about sponsoring the library's development: it ensures the code that your products rely on stays actively maintained. It can also give your project some exposure to the makers' community.

If you are an individual user and want to support the development (or give a sign of appreciation), consider purchasing the book Mastering ArduinoJson ❤, or simply cast a star ⭐.

Từ khóa » Thư Viện Arduinojson