Skip to content
This repository was archived by the owner on Mar 5, 2026. It is now read-only.

Commit 781bddf

Browse files
gerald-guionyme-no-dev
authored andcommitted
json response is more human readable with PrettyAsyncJsonResponse class (me-no-dev#398)
* Update AsyncJson.h Adding PrettyAsyncJsonResponse class * Update AsyncJson.h * Adding a PrettyAsyncJsonResponse class json response is more human readable than with AsyncJsonResponse
1 parent d55dd73 commit 781bddf

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

src/AsyncJson.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class ChunkPrint : public Print {
7878
};
7979

8080
class AsyncJsonResponse: public AsyncAbstractResponse {
81-
private:
81+
protected:
8282

8383
#ifdef ARDUINOJSON_5_COMPATIBILITY
8484
DynamicJsonBuffer _jsonBuffer;
@@ -140,6 +140,21 @@ class AsyncJsonResponse: public AsyncAbstractResponse {
140140
}
141141
};
142142

143+
class PrettyAsyncJsonResponse: public AsyncJsonResponse {
144+
public:
145+
PrettyAsyncJsonResponse (bool isArray=false) : AsyncJsonResponse{isArray} {}
146+
size_t setLength () {
147+
_contentLength = _root.measurePrettyLength ();
148+
if (_contentLength) {_isValid = true;}
149+
return _contentLength;
150+
}
151+
size_t _fillBuffer (uint8_t *data, size_t len) {
152+
ChunkPrint dest (data, _sentLength, len);
153+
_root.prettyPrintTo (dest);
154+
return len;
155+
}
156+
};
157+
143158
typedef std::function<void(AsyncWebServerRequest *request, JsonVariant &json)> ArJsonRequestHandlerFunction;
144159

145160
class AsyncCallbackJsonWebHandler: public AsyncWebHandler {

0 commit comments

Comments
 (0)