ESPHome 2026.3.0-dev
Loading...
Searching...
No Matches
esphome::json Namespace Reference

Data Structures

class  JsonBuilder
 Builder class for creating JSON documents without lambdas. More...
 
class  SerializationBuffer
 Buffer for JSON serialization that uses stack allocation for small payloads. More...
 
struct  SpiRamAllocator
 

Typedefs

using json_parse_t = std::function<bool(JsonObject)>
 Callback function typedef for parsing JsonObjects.
 
using json_build_t = std::function<void(JsonObject)>
 Callback function typedef for building JsonObjects.
 

Functions

SerializationBuffer build_json (const json_build_t &f)
 Build a JSON string with the provided json build function.
 
bool parse_json (const std::string &data, const json_parse_t &f)
 Parse a JSON string and run the provided json parse function if it's valid.
 
bool parse_json (const uint8_t *data, size_t len, const json_parse_t &f)
 Parse JSON from raw bytes and run the provided json parse function if it's valid.
 
JsonDocument parse_json (const uint8_t *data, size_t len)
 Parse a JSON string and return the root JsonDocument (or an unbound object on error)
 
JsonDocument parse_json (const std::string &data)
 Parse a JSON string and return the root JsonDocument (or an unbound object on error)
 

Typedef Documentation

◆ json_build_t

using esphome::json::json_build_t = std::function<void(JsonObject)>

Callback function typedef for building JsonObjects.

Definition at line 151 of file json_util.h.

◆ json_parse_t

using esphome::json::json_parse_t = std::function<bool(JsonObject)>

Callback function typedef for parsing JsonObjects.

Definition at line 148 of file json_util.h.

Function Documentation

◆ build_json()

SerializationBuffer esphome::json::build_json ( const json_build_t & f)

Build a JSON string with the provided json build function.

Returns SerializationBuffer for stack-first allocation; implicitly converts to std::string.

Definition at line 18 of file json_util.cpp.

◆ parse_json() [1/4]

JsonDocument esphome::json::parse_json ( const std::string & data)
inline

Parse a JSON string and return the root JsonDocument (or an unbound object on error)

Definition at line 165 of file json_util.h.

◆ parse_json() [2/4]

bool esphome::json::parse_json ( const std::string & data,
const json_parse_t & f )

Parse a JSON string and run the provided json parse function if it's valid.

Definition at line 27 of file json_util.cpp.

◆ parse_json() [3/4]

JsonDocument esphome::json::parse_json ( const uint8_t * data,
size_t len )

Parse a JSON string and return the root JsonDocument (or an unbound object on error)

Definition at line 41 of file json_util.cpp.

◆ parse_json() [4/4]

bool esphome::json::parse_json ( const uint8_t * data,
size_t len,
const json_parse_t & f )

Parse JSON from raw bytes and run the provided json parse function if it's valid.

Definition at line 32 of file json_util.cpp.