Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix JSON output format
cf. #28
  • Loading branch information
lyonel committed Apr 28, 2017
1 parent b1eab63 commit 135a853
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/core/hw.cc
Expand Up @@ -1368,9 +1368,14 @@ string hwNode::asJSON(unsigned level)
config = getConfigKeys();
resources = getResources("\" value=\"");

if (level == 0)
{
out << "[" << endl;
}

if(visible(getClassName()))
{
out << "{" << endl;
out << spaces(2*level) << "{" << endl;
out << spaces(2*level+2) << "\"id\" : \"" << getId() << "\"," << endl;
out << spaces(2*level+2) << "\"class\" : \"" << getClassName() << "\"";

Expand Down Expand Up @@ -1613,20 +1618,13 @@ string hwNode::asJSON(unsigned level)
resources.clear();
}


if(countChildren()>0)
for (unsigned int i = 0; i < countChildren(); i++)
{
if(visible(getClassName()))
out << "," << endl << spaces(2*level+2) << "\"children\" : [" << endl;

for (unsigned int i = 0; i < countChildren(); i++)
out << getChild(i)->asJSON(visible(getClassName()) ? level + 2 : 1);
if (visible(getChild(i)->getClassName()))
{
out << spaces(2*level+4) << getChild(i)->asJSON(visible(getClassName()) ? level + 2 : 1);
if(visible(getChild(i)->getClassName()) && (i < countChildren()-1)) out << "," << endl;
out << "," << endl;
}

if(visible(getClassName()))
out << endl << spaces(2*level+2) << "]";
}

if(visible(getClassName()))
Expand All @@ -1635,6 +1633,12 @@ string hwNode::asJSON(unsigned level)
out << "}";
}

if (level == 0)
{
out.seekp(-2, std::ios_base::end);
out << endl << "]" << endl;
}

return out.str();
}

Expand Down

0 comments on commit 135a853

Please sign in to comment.