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

Data Structures

class  JsonArena
 Bump allocator over a fixed buffer for a document built and serialized in one scope. More...
 
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

 ESPHOME_LOG_TAG (TAG, "json")
 
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)
 
ArduinoJson::Allocator * heap_json_allocator ()
 The allocator a JsonBuilder uses by default (PSRAM first when available)
 
JsonString linked (const char *s)
 
JsonString linked (const char *s, size_t len)
 
JsonString linked (const std::string &s)
 
JsonString linked (std::string &&)=delete
 
ProgmemStr linked (ProgmemStr s)
 
JsonDocument parse_json (const std::string &data)
 Parse a JSON string and return the root JsonDocument (or an unbound object on error)
 
JsonString linked (const StringRef &s)
 
ProgmemStr linked (const ProgmemStringRef &s)
 

Variables

constexpr size_t JSON_POOL_BYTES = ARDUINOJSON_POOL_CAPACITY * sizeof(ArduinoJson::detail::VariantData)
 Size of one ArduinoJson slot pool, the first allocation every document makes (1 KB on 32 bit targets)
 
constexpr size_t JSON_ARENA_SIZE = JSON_POOL_BYTES + 1152
 One pool plus room for copied string nodes; a 40 option select with linked options fits.
 

Typedef Documentation

◆ json_build_t

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

Callback function typedef for building JsonObjects.

Definition at line 164 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 161 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 19 of file json_util.cpp.

◆ ESPHOME_LOG_TAG()

esphome::json::ESPHOME_LOG_TAG ( TAG ,
"json"  )

◆ heap_json_allocator()

ArduinoJson::Allocator * esphome::json::heap_json_allocator ( )

The allocator a JsonBuilder uses by default (PSRAM first when available)

Definition at line 72 of file json_util.cpp.

◆ linked() [1/7]

JsonString esphome::json::linked ( const char * s)
inline

Definition at line 24 of file json_util.h.

◆ linked() [2/7]

JsonString esphome::json::linked ( const char * s,
size_t len )
inline

Definition at line 25 of file json_util.h.

◆ linked() [3/7]

JsonString esphome::json::linked ( const ProgmemStringRef & s)
inline

Definition at line 359 of file string_ref.h.

◆ linked() [4/7]

JsonString esphome::json::linked ( const std::string & s)
inline

Definition at line 26 of file json_util.h.

◆ linked() [5/7]

JsonString esphome::json::linked ( const StringRef & s)
inline

Definition at line 356 of file string_ref.h.

◆ linked() [6/7]

ProgmemStr esphome::json::linked ( ProgmemStr s)
inline

Definition at line 30 of file json_util.h.

◆ linked() [7/7]

JsonString esphome::json::linked ( std::string && )
delete

◆ 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 178 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 28 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 42 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 33 of file json_util.cpp.

Variable Documentation

◆ JSON_ARENA_SIZE

size_t esphome::json::JSON_ARENA_SIZE = JSON_POOL_BYTES + 1152
constexpr

One pool plus room for copied string nodes; a 40 option select with linked options fits.

Definition at line 189 of file json_util.h.

◆ JSON_POOL_BYTES

size_t esphome::json::JSON_POOL_BYTES = ARDUINOJSON_POOL_CAPACITY * sizeof(ArduinoJson::detail::VariantData)
constexpr

Size of one ArduinoJson slot pool, the first allocation every document makes (1 KB on 32 bit targets)

Definition at line 187 of file json_util.h.