Manual formating Json

Hallo all, i am a newbie in this topic
i have a project, i extract 4 sensor values send it via ESP-NOW
And i want to save these in Jsonformat to a sd card, e.g. in txt file

{"sensorData"=[1,2,3,4]} -> the reading from sensor when i print it to serial (1,2,3,4 are values from sensor, it just examples XD)

the data must be formated in json and to avoid too large jsonbuffer (ArduinoJson) i think i need to manually format Json, why?
-option 1:
to avoid too large json buffer capacity, i will write each line with FILE_APPEND
the file should look like this then


it is not a valid Json format

-option 2:
to add values to array:

  • it is a valid json format
    -problem is the array will get bigger and bigger and consume the RAM of ESP32 and make it lag

can i manually format the json format for example like the 2nd option(valid json format)? with String message and so on
i still have problem with the logic / flow chart,
my idea is e.g. i want to write the sensor datas every hour in a file, that means
hour 1, datas go to the 1.txt
hour 2, next datas go to the 2.txt
and so on,... an wenn the capcity of sd card full, the older files (e.g. 1.txt, 2.txt) should be deleted to free memory

can i do that? thanks so much for the help

I saw a few days ago about data traffic on ESP8266, see if the websocket helps you with anything:

Long polling in communication with Ajax generates traffic for wifi. In this case it is not good for ESP8266. We will solve this problem with WebSocket technology. Websocker is a full duplex protocol and does not send data over long polls, such as ajax. Toggles connection data connection on / off. Thus traffic is reduced. The following code is an example written with WebSocket technology.

WebSocket Server and Client for Arduino: