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

◆ json()

fl::Json fl::response::json ( ) const

Response body parsed as JSON (JavaScript-like API)

Returns
fl::Json object for safe, ergonomic access
Note
Automatically parses JSON on first call, caches result
Returns null JSON object for non-JSON or malformed content

Definition at line 319 of file fetch.cpp.

319 {
320 if (!mJsonParsed) {
321 if (is_json() || mBody.find("{") != fl::string::npos || mBody.find("[") != fl::string::npos) {
323 } else {
324 FL_WARN("Response is not JSON: " << mBody);
325 mCachedJson = fl::Json(nullptr); // Not JSON content
326 }
327 mJsonParsed = true;
328 }
329
330 return mCachedJson.has_value() ? *mCachedJson : fl::Json(nullptr);
331}
fl::string mBody
Definition fetch.h:149
fl::Json parse_json_body() const
Parse JSON from response body with error handling.
Definition fetch.h:157
bool mJsonParsed
Definition fetch.h:154
fl::optional< fl::Json > mCachedJson
Definition fetch.h:153
bool is_json() const
Check if response appears to contain JSON content.
Definition fetch.h:127
static const fl::size npos
Definition str.h:597
#define FL_WARN
Definition warn.h:12

References FL_WARN, is_json(), mBody, mCachedJson, mJsonParsed, fl::string::npos, and parse_json_body().

Referenced by test_json_await(), and test_json_response().

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