title: I'm getting a [json.exception.type_error.302] for some reason in my code. I know what the error means but I don't know where there's a fault
body: <p>My code goes through the values of each sample in a JSON file and gives out the number of sorting comparisons, the amount of memory, and time it takes for the sorting to happen. But for some reason the code is throwing me an error. Would love it if someone could help me out.
  I'm getting a [json.exception.type_error.302] for some reason in my code. I know what the error means but I don't know where there's a fault</p>
  
  <p>To be exact, this is the error I'm getting - "libc++abi.dylib: terminating with uncaught exception of type nlohmann::detail::type_error: [json.exception.type_error.302] type must be number, but is null"</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include "json.hpp"
  #include "mergesort.h"
  #include "insertionsort.h"
  #include "quicksort.h"
  #include &lt;ctime&gt;
  #include &lt;iomanip&gt;
  
  int main(int argc, char* argv[]) {
    std::ifstream file;
    file.open(argv[1]);
    nlohmann::json jsonObject;
    if (file.is_open()) {
      file &gt;&gt; jsonObject;
    } else {
      std::cout &lt;&lt; "Invalid Argument" &lt;&lt; std::endl;
    }
  
    clock_t mergeTime, quickTime, insertTime;
    extern int insertMemAccesses, insertCompare, mergeMemAccesses, mergeCompare, quickCompare, quickMemAccesses;
  //    std::cout &lt;&lt; jsonObject;
  //    nlohmann::json jsonOutput;
  
    std::cout &lt;&lt; "Sample,InsertSortTime,InsertionSortCompares,InsertionSortMemaccess,MergeSortCompares,MergeSortMemaccess,QuickSortTime,QuickSortCompares,QuickSortMemaccess";
  
    int arraysize = jsonObject["metadata"]["arraySize"];
    int numsamples = jsonObject["metadata"]["numSamples"];
  
  
    for (int i = 0; i &lt;= numsamples; i++) {
      std::string sample;
      if (i &lt; 9) {
        sample = "Sample0" + std::to_string(i+1);
      } else {
        sample = "Sample" + std::to_string(i+1);
      }
  
      std::vector&lt;int&gt; insertion;
      std::vector&lt;int&gt; merge;
      std::vector&lt;int&gt; quick;
  
      for(int j = 0; j &lt;= arraysize; j++){
        insertion.push_back(jsonObject[sample][j]);
        merge.push_back(jsonObject[sample][j]);
        quick.push_back(jsonObject[sample][j]);
      }
  
      insertTime = clock();
      InsertionSort(&amp;insertion);
      insertTime = clock() - insertTime;
  
      insertTime = ((unsigned long)insertTime)/CLOCKS_PER_SEC;
  
      mergeTime = clock();
      MergeSort(&amp;merge);
      mergeTime = clock() - mergeTime;
  
      mergeTime = ((unsigned long)mergeTime)/CLOCKS_PER_SEC;
  
      quickTime = clock();
      QuickSort(&amp;quick);
      quickTime = clock() - quickTime;
  
      quickTime = ((unsigned long)quickTime)/CLOCKS_PER_SEC;
  
      std::cout&lt;&lt;sample&lt;&lt;",";
      printf("%.6lu,%d,%d,%.6lu,%d,%d,%.6lu,%d,%d\n",insertTime,insertCompare,insertMemAccesses,mergeTime,mergeCompare,mergeMemAccesses,quickTime,quickCompare,quickMemAccesses);
  
  
      insertCompare = 0;
      insertMemAccesses = 0;
      mergeCompare = 0;
      mergeMemAccesses = 0;
      quickCompare = 0;
      quickMemAccesses = 0;
  
    }
    return 0;
  }
  </code></pre>