FastLED 3.9.15
Loading...
Searching...
No Matches

◆ formatJsonResponse()

fl::string fl::formatJsonResponse ( const fl::json & response,
const char * prefix = "" )

Serialize JSON response to a string.

Parameters
responseJSON response object
prefixOptional prefix to prepend (default: "")
Returns
Formatted string ready to be written to output
Note
Generic JSON serialization - works for any JSON, not just JSON-RPC

Definition at line 12 of file serial.cpp.hpp.

12 {
13 // Use sstream to minimize allocations
14 fl::sstream ss;
15
16 // Add prefix if provided
17 if (prefix && prefix[0] != '\0') {
18 ss << prefix;
19 }
20
21 // Serialize to compact JSON
22 fl::string jsonStr = response.to_string();
23
24 // Stream copy with inline filtering (replace newlines with spaces)
25 for (size_t i = 0; i < jsonStr.size(); ++i) {
26 char c = jsonStr[i];
27 ss << ((c == '\n' || c == '\r') ? ' ' : c);
28 }
29
30 return ss.str();
31}
fl::size size() const FL_NOEXCEPT
string str() const FL_NOEXCEPT
Definition strstream.h:43

References fl::basic_string::size(), and fl::sstream::str().

Referenced by createSerialResponseSink(), printJsonRaw(), and printStreamRaw().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: