diff --git a/DynamicModel.cc b/DynamicModel.cc
index 8d92a5642cf944d8010e43a263b3a947c7059b52..be0dd601c207898d6d365a4f3eee3378deae1805 100644
--- a/DynamicModel.cc
+++ b/DynamicModel.cc
@@ -5537,16 +5537,15 @@ DynamicModel::writeJsonOutput(ostream &output) const
 }
 
 void
-DynamicModel::writeJsonXrefs(ostream &output) const
+DynamicModel::writeJsonXrefsHelper(ostream &output, const map<pair<int, int>, set<int> > &xrefs) const
 {
-  output << "\"xrefs\": {"
-         << "\"parameters\": [";
-  for (map<pair<int, int>, set<int> >::const_iterator it = xref_param.begin();
-       it != xref_param.end(); it++)
+  for (map<pair<int, int>, set<int> >::const_iterator it = xrefs.begin();
+       it != xrefs.end(); it++)
     {
-      if (it != xref_param.begin())
+      if (it != xrefs.begin())
         output << ", ";
-      output << "{\"parameter\": \"" << symbol_table.getName(it->first.first) << "\""
+      output << "{\"name\": \"" << symbol_table.getName(it->first.first) << "\""
+             << ", \"shift\": " << it->first.second
              << ", \"equations\": [";
       for (set<int>::const_iterator it1 = it->second.begin();
            it1 != it->second.end(); it1++)
@@ -5557,63 +5556,23 @@ DynamicModel::writeJsonXrefs(ostream &output) const
         }
       output << "]}";
     }
+}
+
+void
+DynamicModel::writeJsonXrefs(ostream &output) const
+{
+  output << "\"xrefs\": {"
+         << "\"parameters\": [";
+  writeJsonXrefsHelper(output, xref_param);
   output << "]"
          << ", \"endogenous\": [";
-  for (map<pair<int, int>, set<int> >::const_iterator it = xref_endo.begin();
-       it != xref_endo.end(); it++)
-    {
-      if (it != xref_endo.begin())
-        output << ", ";
-      output << "{\"endogenous\": \"" << symbol_table.getName(it->first.first) << "\""
-             << ", \"shift\": " << it->first.second
-             << ", \"equations\": [";
-      for (set<int>::const_iterator it1 = it->second.begin();
-           it1 != it->second.end(); it1++)
-        {
-          if (it1 != it->second.begin())
-            output << ", ";
-          output << *it1 + 1;
-        }
-      output << "]}";
-    }
+  writeJsonXrefsHelper(output, xref_endo);
   output << "]"
          << ", \"exogenous\": [";
-  for (map<pair<int, int>, set<int> >::const_iterator it = xref_exo.begin();
-       it != xref_exo.end(); it++)
-    {
-      if (it != xref_exo.begin())
-        output << ", ";
-      output << "{\"exogenous\": \"" << symbol_table.getName(it->first.first) << "\""
-             << ", \"shift\": " << it->first.second
-             << ", \"equations\": [";
-      for (set<int>::const_iterator it1 = it->second.begin();
-           it1 != it->second.end(); it1++)
-        {
-          if (it1 != it->second.begin())
-            output << ", ";
-          output << *it1 + 1;
-        }
-      output << "]}";
-    }
+    writeJsonXrefsHelper(output, xref_exo);
   output << "]"
          << ", \"exogenous_deterministic\": [";
-  for (map<pair<int, int>, set<int> >::const_iterator it = xref_exo_det.begin();
-       it != xref_exo_det.end(); it++)
-    {
-      if (it != xref_exo_det.begin())
-        output << ", ";
-      output << "{\"exogenous_det\": \"" << symbol_table.getName(it->first.first) << "\""
-             << ", \"shift\": " << it->first.second
-             << ", \"equations\": [";
-      for (set<int>::const_iterator it1 = it->second.begin();
-           it1 != it->second.end(); it1++)
-        {
-          if (it1 != it->second.begin())
-            output << ", ";
-          output << *it1 + 1;
-        }
-      output << "]}";
-    }
+  writeJsonXrefsHelper(output, xref_exo_det);
   output << "]}" << endl;
 }
 
diff --git a/DynamicModel.hh b/DynamicModel.hh
index 3692661199716237a35515472c533afdb271f96e..e5b9be490bd41c7dd4d951fe0d447543025de5c4 100644
--- a/DynamicModel.hh
+++ b/DynamicModel.hh
@@ -264,6 +264,7 @@ public:
 
   //! Write cross reference output if the xref maps have been filed
   void writeJsonXrefs(ostream &output) const;
+  void writeJsonXrefsHelper(ostream &output, const map<pair<int, int>, set<int> > &xrefs) const;
 
   //! Return true if the hessian is equal to zero
   inline bool checkHessianZero() const;