-1

I have a vector which consist of a struct, see below:

struct FileInformation
  {
    String name;
    size_t filesize;
  };
    
std::vector<FileInformation> FileInformations;

How do I get JSON out of it the easiest way?

1
  • 1
    for cycle and print? Commented Dec 23, 2022 at 13:38

1 Answer 1

1

Using ArduinoJson:

DynamicJsonDocument doc(2048);
for (const FileInformation& item : FileInformations) {
  JsonObject& obj = doc.createNestedObject();
  obj["name"] = item.name;
  obj["filesize"] = item.filesize;
}
serializeJson(doc, Serial);

This will produce a JSON document that looks like this:

[
  {"name": "command.com", "filesize": 1234},
  {"name": "config.sys", "filesize": 2345},
  {"name": "autoexec.bat", "filesize": 3456}
]

Please read the tutorial for more information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.