title: How to iterate over a JSON in JSON for modern c++
body: <p>I would like to iterate over each of entries in a json object, but I am getting one incomprehensible error after the other. How to correct the following example?</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  #include &lt;nlohmann/json.hpp&gt;
  
  using json = nlohmann::json;
  
  void bla(std::string a) {
      std::cout &lt;&lt; a &lt;&lt; '\n'; 
  }
  
  int main() {
      json RecentFiles;
  
      RecentFiles["1"]["Name"] = "test1.txt";
      RecentFiles["1"]["Last modified"] = "monday";
      RecentFiles["1"]["Score"] = 5.0f;
  
      RecentFiles["2"]["Name"] = "test2.txt";
      RecentFiles["2"]["Last modified"] = "tuesday";
      RecentFiles["2"]["Score"] = 5.0f;
  
  
      for (auto it = RecentFiles.begin(); it != RecentFiles.end(); ++it) {
             bla("JSON: Recent file = " + it.value()["Name"]);    
      }
  
      std::cout &lt;&lt; RecentFiles; }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>prog.cc: In function 'int main()':
  prog.cc:18:31: error: invalid conversion from 'const char*' to 'nlohmann::detail::iter_impl&lt;nlohmann::basic_json&lt;&gt; &gt;::difference_type {aka long int}' [-fpermissive]
           std::cout &lt;&lt; it["Name"];
                                 ^
  In file included from prog.cc:2:0:
  ./nlohmann/json.hpp:4418:15: note: initializing argument 1 of 'nlohmann::detail::iter_impl&lt;BasicJsonType&gt;::reference nlohmann::detail::iter_impl&lt;BasicJsonType&gt;::operator[](nlohmann::detail::iter_impl&lt;BasicJsonType&gt;::difference_type) const [with BasicJsonType = nlohmann::basic_json&lt;&gt;; nlohmann::detail::iter_impl&lt;BasicJsonType&gt;::reference = nlohmann::basic_json&lt;&gt;&amp;; nlohmann::detail::iter_impl&lt;BasicJsonType&gt;::difference_type = long int]'
       reference operator[](difference_type n) const
                 ^
  </code></pre>
  
  <p>The above is done in the sandbox</p>
  
  <pre><code>https://wandbox.org/permlink/LNck7Gktm14bmPy0
  </code></pre>
  
  <p>This is not actual code that I am using, I just want to see if I can understand how to do the various basic things that I  need to do with JSON. </p>
  
  <p>Currently I understand so little, that I do not know if what I am doing is essentially correct but just breaks due to something stupid, or if I am doing something fundamentally wrong.</p>