Skip to content
forked from tobozo/YAMLDuino

YAML <=> JSON converter for ESP32, ESP8266, RP2040 and possibly other devices

License

Notifications You must be signed in to change notification settings

BlynkGO/YAMLDuino

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ArduinoYaml A.K.A YAMLDuino

arduino-library-badge PlatformIO Registry

This arduino library is based on libyaml.

It provides several ways to convert YAML<=>JSON using libyaml, cJSON or ArduinoJson objects.

Supported platforms (some untested):

  • ESP32
  • RP2040
  • ESP8266
  • SAMD

Usage

#include <ArduinoYaml.h>

or

#include <YAMLDuino.h>

pure libyaml

YAML is a superset of JSON, so native conversion from JSON is possible without any additional JSON library.

#include <ArduinoYaml.h>

  // JSON stream to YAML stream
  size_t serializeYml( Stream &json_src_stream, Stream &yml_dest_stream );

ArduinoJson

#include <ArduinoJson.h> // include this first or functions will be disabled
#include <ArduinoYaml.h>

  // ArduinoJSON object to YAML string
  size_t serializeYml( JsonVariant src_obj, String &dest_string );
  // ArduinoJSON object to YAML stream
  size_t serializeYml( JsonVariant src_obj, Stream &dest_stream );
  // Deserialize YAML string to ArduinoJSON object
  DeserializationError deserializeYml( JsonObject &dest_obj, const char* src_yaml_str );
  // Deserialize YAML stream to ArduinoJSON object
  DeserializationError deserializeYml( JsonObject &dest_obj, Stream &src_stream );
  // Deserialize YAML string to ArduinoJSON document
  DeserializationError deserializeYml( JsonDocument &dest_doc, Stream &src_stream );
  // Deserialize YAML string to ArduinoJSON document
  DeserializationError deserializeYml( JsonDocument &dest_doc, const char *src_yaml_str) ;

cJSON

⚠️ cJSON has a memory leak with floats, the leak happens only once though, and may be avoided by quoting the float, which won't affect yaml output.

// #include <cJSON.h> // no need to include, cJSON is built-in with esp32 and also bundled with ArduinoYaml
#include <ArduinoYaml.h>

  // cJSON object to YAML string
  size_t serializeYml( cJSON* src_obj, String &dest_string );
  // cJSON object to YAML stream
  size_t serializeYml( cJSON* src_obj, Stream &dest_stream );
  // YAML string to cJSON object
  int deserializeYml( cJSON* dest_obj, const char* src_yaml_str );
  // YAML stream to cJSON object
  int deserializeYml( cJSON* dest_obj, Stream &src_stream );

Credits and special thanks to:

Additional resources:

About

YAML <=> JSON converter for ESP32, ESP8266, RP2040 and possibly other devices

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 92.3%
  • C++ 7.7%