title: JSON Parse error when reading json object from file
body: <p>Observing random crash when reading JSON file data to a JSON object.
  Here is the summary of the crash.
  The crash point is always consistent.</p>
  <p>Description:</p>
  <p>One process takes care of the following:</p>
  <ol>
  <li><p>[Library Call] --&gt; Returns serialised JSON key-value pair as char *, which is placed
  in std::string
  Example : <code>std:string testString = libCall();</code>
  testString now holds a string like this {&quot;IS_JSON_FLAGON&quot;: true}</p>
  </li>
  <li><p>To ensure there are no additional characters and to adhere to the JSON object
  compatibility, the std::string is parsed and then assigned to a JSON object</p>
  </li>
  </ol>
  <p>Example:   <code> nlohmann::json jWriteObj = nlohmann::json::parse(testString .c_str());</code></p>
  <ol start="3">
  <li>The JSON object is then written to JSON file</li>
  </ol>
  <p>Example :</p>
  <pre><code>    mutex mLock; //global variable 
      upDateFlagsFile()
      {
          fstream fileDesc;
          mLock.lock();
          fileDesc.open(&lt;filepath&gt;, trunc mode);
          fileDesc &lt;&lt; jWriteObj;
          fileDesc.close();
          mLock.unlock();
      }
  
  </code></pre>
  <p>this creates/updates the file with .json extension
  Example: flagsFile.json with data {&quot;IS_JSON_FLAGON&quot;:true}</p>
  <p>In another process, the file written by the previous process is read</p>
  <ol>
  <li><p>Modules want to know the Flag value, so calls isFlagOn(&quot;IS_JSON_FLAGON&quot;)
  which then opens the file and reads the data to a json object</p>
  <p>Example:  [Module reading the flag value] ----&gt;isFlagOn(&quot;IS_JSON_FLAGON&quot;)
  definition for isFlagOn()</p>
  </li>
  </ol>
  <pre><code>    extern mutex mLock; //using the same lock for read and write
      isFlagOn(char* flagName)
      {
         istream fileDesc;
         bool flagValue = false; 
         nlohmann::json jReadObj;
      try{
         mLock.lock();   
         fileDesc.open();
         fileDesc &gt;&gt; jReadObj; //  ---&gt; Crash occurs randomly at this line
         flagValue = jReadObj[flagName].get&lt;bool&gt;();
         fileDesc.close();
         mLock.unlock();
        }
         catch(nlohmann::json::exception &amp;e)
         {
             std:cout&lt;&lt; &quot;Exception caught&quot;;
         }
         return flagValue;
      }
  
  </code></pre>
  <p>The crash is very random on Ubuntu 20.04 and points to the line highlighted.
  The surprising part is the exception is not getting caught inspite of using the wildcard exception approach
  Any suggestions on what needs to be corrected in this would help.</p>