22
33This arduino library is based on [ libyaml] ( https://github.com/yaml/libyaml ) .
44
5- It provides several ways to serialize/deserialize YAML<=>JSON using cJSON or ArduinoJson objects.
5+ It provides several ways to convert YAML<=>JSON using libyaml, cJSON or ArduinoJson objects.
66
77Supported platforms (some untested):
88
9- - esp32
10- - esp8266
11- - samd
12- - rp2040
9+ - ESP32
10+ - RP2040
11+ - ESP8266
12+ - SAMD
13+
1314
1415
1516### Usage
1617
17- #### cJSON
18+ ``` cpp
19+ #include < ArduinoYaml.h>
20+
21+ ```
22+
23+ or
24+
25+ ``` cpp
26+ #include < YAMLDuino.h>
27+
28+ ```
29+
30+
31+
32+
33+ #### pure libyaml
34+
35+ YAML is a superset of JSON, so native conversion from JSON is possible without any additional JSON library.
1836
1937``` cpp
20- #include < cJSON.h> // note: cJSON is built-in with esp32
2138#include < ArduinoYaml.h>
2239
23- // cJSON object to YAML string
24- size_t serializeYml ( cJSON* src_obj, String &dest_string );
25- // cJSON object to YAML stream
26- size_t serializeYml( cJSON* src_obj, Stream &dest_stream );
27- // JSON stream to cJSON object to YAML stream, disabled on some architectures
40+ // JSON stream to YAML stream
2841 size_t serializeYml ( Stream &json_src_stream, Stream &yml_dest_stream );
2942
30- // YAML string to cJSON object
31- int deserializeYml( cJSON* dest_obj, const char* src_yaml_str );
32- // YAML stream to cJSON object
33- int deserializeYml( cJSON* dest_obj, Stream &src_stream );
3443```
3544
45+
3646#### ArduinoJson
3747
3848
3949```cpp
40-
41- #include <ArduinoJson.h>
50+ #include <ArduinoJson.h> // include this first or functions will be disabled
4251#include <ArduinoYaml.h>
4352
4453 // ArduinoJSON object to YAML string
4554 size_t serializeYml( JsonVariant src_obj, String &dest_string );
4655 // ArduinoJSON object to YAML stream
4756 size_t serializeYml( JsonVariant src_obj, Stream &dest_stream );
48- // JSON stream to JsonObject to YAML stream, disabled on some architectures
49- size_t serializeYml( Stream &json_src_stream, Stream &yml_dest_stream );
5057 // Deserialize YAML string to ArduinoJSON object
5158 DeserializationError deserializeYml( JsonObject &dest_obj, const char* src_yaml_str );
5259 // Deserialize YAML stream to ArduinoJSON object
@@ -60,15 +67,40 @@ Supported platforms (some untested):
6067
6168
6269
70+ #### cJSON
71+
72+ ⚠️ cJSON has a memory leak with floats, the leak happens only once though, and may be
73+ avoided by quoting the float, which won't affect yaml output.
74+
75+
76+ ``` cpp
77+ // #include <cJSON.h> // no need to include, cJSON is built-in with esp32 and also bundled with ArduinoYaml
78+ #include < ArduinoYaml.h>
79+
80+ // cJSON object to YAML string
81+ size_t serializeYml ( cJSON* src_obj, String &dest_string );
82+ // cJSON object to YAML stream
83+ size_t serializeYml( cJSON* src_obj, Stream &dest_stream );
84+ // YAML string to cJSON object
85+ int deserializeYml( cJSON* dest_obj, const char* src_yaml_str );
86+ // YAML stream to cJSON object
87+ int deserializeYml( cJSON* dest_obj, Stream &src_stream );
88+
89+ ```
90+
91+
92+
93+
94+
6395### Credits and special thanks to:
6496
65- - [ libyaml] ( https://github.com/yaml/libyaml )
66- - [ yaml2json] ( https://github.com/vikman90/yaml2json )
67- - [ @bblanchon ] ( https://github.com/bblanchon )
97+ - [@yaml](https://github.com/yaml)
6898 - [@DaveGamble](https://github.com/DaveGamble)
69- - [ @espressif ] ( https://github.com/espressif )
99+ - [@bblanchon](https://github.com/bblanchon)
100+ - [@vikman90](https://github.com/vikman90/yaml2json)
70101
71102### Additional resources:
72103
73104 - ArduinoJson : https://github.com/bblanchon/ArduinoJson
74105 - cJSON : https://github.com/DaveGamble/cJSON
106+ - libyaml : https://github.com/yaml/libyaml
0 commit comments