ArduinoJson buffer gets overwritten I have not that much experience with native languages like c/c++ and I'm facing a strange issue, which drives me crazy. So I'm using an Wemos D1 mini (ESP8266) which uses a class calles ConfigManager to read a configuration file from eeprom. The config file is formatted as json, so I'm using ArduinoJson to parse the content. I have declared a StaticJsonBuffer and pointer to a JsonObject in the header, like you can see in the code example:

//FILE: ConfigManager.h
#ifndef ConfigManager_H
#define ConfigManager_H

#include &lt;Arduino.h&gt;
#include &lt;ArduinoJson.h&gt;
#include &lt;FS.h&gt;
#include "Logger.h"

class ConfigManager {
public:

    Settings *settings;  

    ConfigManager();

    void read_from_eeprom();

private:

    File configFile;
    JsonObject *json;
    StaticJsonBuffer&lt;200&gt; jsonBuffer;

    void open_file(const char *permission);

    void read_json();

    void recreate_file();

    void create_json();

    void check_success();

    void populate_settings();

    void clean_up();
};

#endif


When the function read_from_eeprom is invoked, it opens the file and invokes the functionread_json:

void ConfigManager::read_json() {
    size_t size = configFile.size();
    Log.verbose("[ConfigManager] Config file size: %d", size);

    std::unique_ptr&lt;char[]&gt; buf(new char[size]);
    configFile.readBytes(buf.get(), size);
    Log.verbose("[ConfigManager] File content: %s", buf.get());

    Log.verbose("[ConfigManager] Parsing json");
    json = &amp;jsonBuffer.parseObject(buf.get());

    Log.notice("[ConfigManager] Json is:");
    json-&gt;printTo(Serial);
    Serial.println();
}


Which is followed by a call to check_success()

void ConfigManager::check_success() {
    Log.notice("[ConfigManager] Json is:");
    json-&gt;printTo(Serial);
    Serial.println();


    bool should_recreate = true;
    if (json-&gt;success()) {
        Log.notice("[ConfigManager] Parsed json successfully");

        auto version = json-&gt;get&lt;const char*&gt;("version");
        if (version) {
            if (strcmp(version, Settings::current_version) == 0) {
                Log.notice("[ConfigManager] Config version is up2date");
                should_recreate = false;
            } else {
                Log.warning("[ConfigManager] Config version outdated");
            }
        } else {
            Log.warning("[ConfigManager] Invalid config file");
        }
    } else {
        Log.warning("[ConfigManager] Config file is not valid json");
    }

    if (should_recreate) {
        Log.notice("[ConfigManager] Recreating config file");
        recreate_file();
        create_json();
    }

    Log.notice("JSON IS: ");
    json-&gt;prettyPrintTo(Serial);

    Log.notice("[ConfigManager] Sucessfully read json");
}


So what I noticed is that the file content is fine. E.g. {"version":"0.2","led_count":"64"}. 

Then the json is parsed, which succeeds and logs the json object, which is again {"version":"0.2","led_count":"64"}. 

Afterwards the function returns, and calls check_success, which again prints the content of the json object to the log, but this time it seems that something has overwritten the JsonBuffer, which causes the json object to be corrupted. This time the logged content is {"v␂":"0.2","led_count":"64"} (with some strange unicorn characters that change as the source code changes). I'm trying to figure out whats going on for many hours now, but I'm stuck. Can someone please point me in the right direction to solve this problem? Thank you!
the ArduinoJson library doesn't copy the strings, it only stores pointers and writes terminating zeros into input buffer. And your buffer buf is disposed by std::unique_ptr at the end of read_json() function