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

◆ json()

fl::json fl::net::http::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 649 of file fetch.cpp.hpp.

649 {
650 if (!mJsonParsed) {
651 if (is_json() || mBody.find("{") != fl::string::npos || mBody.find("[") != fl::string::npos) {
653 } else {
654 FL_WARN("Response is not JSON: " << mBody);
655 mCachedJson = fl::json(nullptr); // Not JSON content
656 }
657 mJsonParsed = true;
658 }
659
660 return mCachedJson.has_value() ? *mCachedJson : fl::json(nullptr);
661}
bool is_json() const
Check if response appears to contain JSON content.
Definition fetch.h:122
fl::json parse_json_body() const
Parse JSON from response body with error handling.
Definition fetch.h:152
fl::optional< fl::json > mCachedJson
Definition fetch.h:148
static constexpr fl::size npos
Definition string.h:195
#define FL_WARN(X)
Definition log.h:276

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

Referenced by test_get_endpoint(), and test_json_endpoint().

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