https://github.com/tharushaudana/esp-idf-heapless-json-stream-parser
The ESP-IDF Heapless JSON Stream Parser is a memory-efficient library for ESP-IDF that allows parsing JSON streams without using dynamic memory allocation. It simplifies parsing JSON data directly from a stream, making it ideal for memory-constrained ESP32 projects.
https://github.com/tharushaudana/esp-idf-heapless-json-stream-parser
esp-idf esp32 esp8266 heapless json-parser
Last synced: about 1 month ago
JSON representation
The ESP-IDF Heapless JSON Stream Parser is a memory-efficient library for ESP-IDF that allows parsing JSON streams without using dynamic memory allocation. It simplifies parsing JSON data directly from a stream, making it ideal for memory-constrained ESP32 projects.
- Host: GitHub
- URL: https://github.com/tharushaudana/esp-idf-heapless-json-stream-parser
- Owner: tharushaudana
- License: mit
- Created: 2023-10-25T11:10:49.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-16T17:40:53.000Z (about 2 years ago)
- Last Synced: 2025-03-11T13:52:44.184Z (about 1 year ago)
- Topics: esp-idf, esp32, esp8266, heapless, json-parser
- Language: C++
- Homepage:
- Size: 26.4 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ESP-IDF Heapless JSON Stream Parser
This library provides a heapless JSON stream parser for ESP-IDF, allowing you to parse JSON streams without using dynamic memory allocation (heap).
## Features
- Parse JSON streams without using heap memory
- Minimal memory footprint
- Simple integration into ESP-IDF projects
- Supports parsing JSON objects and arrays
- Handles parsing of JSON events from an event source stream
## Usage
1. Include the library in your ESP-IDF project:
```bash
git clone https://github.com/your-username/esp-idf-heapless-json-stream-parser.git
```
2. Include the library in your component makefile:
```makefile
COMPONENT_SRCDIRS += path/to/esp-idf-heapless-json-stream-parser
```
3. Initialize the JSON stream parser with a callback function to handle parsed JSON objects or arrays:
```cpp
#include "esp_heapless_json_stream_parser.h"
json_stream_parser jparser([](std::string path, json_val_t value) {
// Handle parsed JSON tokens here
});
```
4. Initialize the event source stream parser with callbacks for events and data:
```cpp
#include "event_source_stream_parser.h"
event_source_stream_parser eparser("event", "data", [](std::string event) -> on_evts_data_char_cb_t {
// Handle event parsing and return a data callback
return [&](char c) {
jparser.parse(c); // Parse JSON data from the event
};
});
```
5. Parse JSON data as it becomes available in your stream input:
```cpp
// Example: Parsing JSON data from an event source stream
size_t s = strlen(event_source_str);
int i = 0;
while (i < s) {
eparser.parse(event_source_str[i]);
i++;
}
```
6. Cleanup the parser handle when finished:
```cpp
// No cleanup necessary for heapless JSON stream parser
```
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.