FastLED 3.10.8
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 13 of file serial.cpp.hpp.

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

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

Referenced by createSerialResponseSink().

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