FastLED 3.10.8
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 651 of file fetch.cpp.hpp.

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

References fl::FL_NO_EXCEPT, 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: