|
|
66f3ee |
commit 135a853c60582b14c5b67e5cd988a8062d9896f4
|
|
|
66f3ee |
Author: Lyonel Vincent <lyonel@ezix.org>
|
|
|
66f3ee |
Date: Fri Apr 28 16:54:42 2017 +0200
|
|
|
66f3ee |
|
|
|
66f3ee |
Fix JSON output format
|
|
|
66f3ee |
|
|
|
66f3ee |
cf. https://github.com/lyonel/lshw/pull/28
|
|
|
66f3ee |
|
|
|
66f3ee |
diff --git a/src/core/hw.cc b/src/core/hw.cc
|
|
|
66f3ee |
index 68e5912..9defd26 100644
|
|
|
66f3ee |
--- a/src/core/hw.cc
|
|
|
66f3ee |
+++ b/src/core/hw.cc
|
|
|
66f3ee |
@@ -1368,9 +1368,14 @@ string hwNode::asJSON(unsigned level)
|
|
|
66f3ee |
config = getConfigKeys();
|
|
|
66f3ee |
resources = getResources("\" value=\"");
|
|
|
66f3ee |
|
|
|
66f3ee |
+ if (level == 0)
|
|
|
66f3ee |
+ {
|
|
|
66f3ee |
+ out << "[" << endl;
|
|
|
66f3ee |
+ }
|
|
|
66f3ee |
+
|
|
|
66f3ee |
if(visible(getClassName()))
|
|
|
66f3ee |
{
|
|
|
66f3ee |
- out << "{" << endl;
|
|
|
66f3ee |
+ out << spaces(2*level) << "{" << endl;
|
|
|
66f3ee |
out << spaces(2*level+2) << "\"id\" : \"" << getId() << "\"," << endl;
|
|
|
66f3ee |
out << spaces(2*level+2) << "\"class\" : \"" << getClassName() << "\"";
|
|
|
66f3ee |
|
|
|
66f3ee |
@@ -1613,20 +1618,13 @@ string hwNode::asJSON(unsigned level)
|
|
|
66f3ee |
resources.clear();
|
|
|
66f3ee |
}
|
|
|
66f3ee |
|
|
|
66f3ee |
-
|
|
|
66f3ee |
- if(countChildren()>0)
|
|
|
66f3ee |
+ for (unsigned int i = 0; i < countChildren(); i++)
|
|
|
66f3ee |
{
|
|
|
66f3ee |
- if(visible(getClassName()))
|
|
|
66f3ee |
- out << "," << endl << spaces(2*level+2) << "\"children\" : [" << endl;
|
|
|
66f3ee |
-
|
|
|
66f3ee |
- for (unsigned int i = 0; i < countChildren(); i++)
|
|
|
66f3ee |
+ out << getChild(i)->asJSON(visible(getClassName()) ? level + 2 : 1);
|
|
|
66f3ee |
+ if (visible(getChild(i)->getClassName()))
|
|
|
66f3ee |
{
|
|
|
66f3ee |
- out << spaces(2*level+4) << getChild(i)->asJSON(visible(getClassName()) ? level + 2 : 1);
|
|
|
66f3ee |
- if(visible(getChild(i)->getClassName()) && (i < countChildren()-1)) out << "," << endl;
|
|
|
66f3ee |
+ out << "," << endl;
|
|
|
66f3ee |
}
|
|
|
66f3ee |
-
|
|
|
66f3ee |
- if(visible(getClassName()))
|
|
|
66f3ee |
- out << endl << spaces(2*level+2) << "]";
|
|
|
66f3ee |
}
|
|
|
66f3ee |
|
|
|
66f3ee |
if(visible(getClassName()))
|
|
|
66f3ee |
@@ -1635,6 +1633,12 @@ string hwNode::asJSON(unsigned level)
|
|
|
66f3ee |
out << "}";
|
|
|
66f3ee |
}
|
|
|
66f3ee |
|
|
|
66f3ee |
+ if (level == 0)
|
|
|
66f3ee |
+ {
|
|
|
66f3ee |
+ out.seekp(-2, std::ios_base::end);
|
|
|
66f3ee |
+ out << endl << "]" << endl;
|
|
|
66f3ee |
+ }
|
|
|
66f3ee |
+
|
|
|
66f3ee |
return out.str();
|
|
|
66f3ee |
}
|
|
|
66f3ee |
|