diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc index 75f272f8c5c5c2088cb24cc33018560c862f50a9..2b9e3efaeab02e8a1bf3d04e8b7f458bb015d97e 100644 --- a/src/DynamicModel.cc +++ b/src/DynamicModel.cc @@ -6895,18 +6895,24 @@ void DynamicModel::writeJsonVariableMapping(ostream &output) const { output << R"("variable_mapping":[)" << endl; - int ii = 0; - int end_idx_map = static_cast<int>(variableMapping.size()-1); - for (const auto &variable : variableMapping) + for (auto it = variableMapping.begin(); it != variableMapping.end(); ++it) { - output << R"({"name": ")" << symbol_table.getName(variable.first) << R"(", "equations":[)"; - int it = 0; - int end_idx_eq = static_cast<int>(variable.second.size())-1; - for (const auto &equation : variable.second) + if (it != variableMapping.begin()) + output << ", "; + auto [var, eqs] = *it; + output << R"({"name": ")" << symbol_table.getName(var) << R"(", "equations":[)"; + bool first_eq = true; + for (auto it2 = eqs.begin(); it2 != eqs.end(); ++it2) for (const auto &equation_tag : equation_tags) - if (equation_tag.first == equation && equation_tag.second.first == "name") - output << R"(")" << equation_tag.second.second << (it++ == end_idx_eq ? R"("])" : R"(", )"); - output << (ii++ == end_idx_map ? R"(})" : R"(},)") << endl; + if (equation_tag.first == *it2 && equation_tag.second.first == "name") + { + if (first_eq) + first_eq = false; + else + output << ", "; + output << '"' << equation_tag.second.second << '"'; + } + output << "]}" << endl; } output << "]"; }