How to write to a json file

In simple terms i want to know how i can write to a already existing json file (i have tried looking up some stuff)

It’s just a text file, so just like any other file. Ensure you honor the JSON syntax.

Alternatively you can use https://arduinojson.org/ and serialize / deserialize

i can't figure this out i tried everything but i can't seem to write to a json file.

show us everything you tried... You did not read much of the doc probably...

because really it's just a matter of calling serializejson() (see serializeJson() | ArduinoJson 6) on the stream representing your file....

there is even a snippet on that page

File file = SD.open(filename, FILE_WRITE);
StaticJsonDocument<256> doc;
doc["hello"] = "world";
serializeJson(doc, file);
file.close();

this creates a new json file i wanna write to a json file in a specific path

it writes to a stream wherever is the current position... so open the file with the path you want, move the cursor where you want to write, then call serializeJson()....

there is nothing wrong with exploring a bit.... try stuff

so i just have to hover over a json file that is opened and it will send stuff to it?

I don't know what you mean with "hover over"

just give it a try. Open an existing file, move to the end, then call serializeJson() with that file as parameter and close the file. Then have a look at what got written...

how would you get the file?

just as in the example

File file = SD.open(filename, FILE_WRITE);

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.