0

I am getting stack corruption saying "Run-Time Check Failure #2 - Stack around the variable 'root' was corrupted." with following code:

#include <json/json.h>
#include <fstream>
#include <iostream>
#include <string>

int main() {
  Json::Value root;
  Json::Reader reader;
  ifstream file("input.json");
  if (!reader.parse(file, root)) {
    cout << "Failed to parse configuration\n"
      << reader.getFormattedErrorMessages();
    return 0;
  }

  file.close();
  cout << root << endl;

  return 0;
}

File input.json contains:

[
  {
    "id": "id"
  }
]

Any idea why this may be happening and how can I debug this?

Thanks in advance!!

  • 1
    What is the JSON. Hard to reproduce the issue without the input. – Martin York Mar 03 '21 at 19:22
  • 1
    Looks like you're working from an older version or using the deprecated `Reader` class. Can't be certain, but you may have just found one of the reasons it's been slated for removal from the library. – user4581301 Mar 03 '21 at 19:26
  • Have you tried ThorsSerializer?: https://gist.github.com/Loki-Astari/d0c0abd877dea82ee1af0c4114e92446 – Martin York Mar 03 '21 at 19:38

1 Answers1

1

Reader class in jsoncpp seems outdated. Refer to the latest example on https://github.com/open-source-parsers/jsoncpp/blob/master/example/readFromStream/readFromStream.cpp