diff --git a/src/json.hpp b/src/json.hpp
index 09880b9e..5356966b 100644
--- a/src/json.hpp
+++ b/src/json.hpp
@@ -2040,6 +2040,9 @@ class basic_json
     /// a random access iterator for the basic_json class
     class iterator : public std::iterator<std::random_access_iterator_tag, basic_json>
     {
+        // allow basic_json class to access m_it
+        friend class basic_json;
+
       public:
         /// the type of the values when the iterator is dereferenced
         using value_type = basic_json::value_type;
@@ -2529,6 +2532,9 @@ class basic_json
     /// a const random access iterator for the basic_json class
     class const_iterator : public std::iterator<std::random_access_iterator_tag, const basic_json>
     {
+        // allow basic_json class to access m_it
+        friend class basic_json;
+
       public:
         /// the type of the values when the iterator is dereferenced
         using value_type = basic_json::value_type;
diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c
index 36bb0e00..b78afcd5 100644
--- a/src/json.hpp.re2c
+++ b/src/json.hpp.re2c
@@ -2040,6 +2040,9 @@ class basic_json
     /// a random access iterator for the basic_json class
     class iterator : public std::iterator<std::random_access_iterator_tag, basic_json>
     {
+        // allow basic_json class to access m_it
+        friend class basic_json;
+
       public:
         /// the type of the values when the iterator is dereferenced
         using value_type = basic_json::value_type;
@@ -2529,6 +2532,9 @@ class basic_json
     /// a const random access iterator for the basic_json class
     class const_iterator : public std::iterator<std::random_access_iterator_tag, const basic_json>
     {
+        // allow basic_json class to access m_it
+        friend class basic_json;
+
       public:
         /// the type of the values when the iterator is dereferenced
         using value_type = basic_json::value_type;