From 15565229509455527de9ce7cbb9530e2b31d043b Mon Sep 17 00:00:00 2001 From: Lyonel Vincent Date: Wed, 27 May 2020 01:07:16 +0200 Subject: [PATCH 20/65] clean-up JSON output --- src/core/hw.cc | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/core/hw.cc b/src/core/hw.cc index ab345fe..6aea7cf 100644 --- a/src/core/hw.cc +++ b/src/core/hw.cc @@ -1650,13 +1650,20 @@ string hwNode::asJSON(unsigned level) resources.clear(); } - for (unsigned int i = 0; i < countChildren(); i++) + if(!::enabled("output:list") && countChildren()>0) { - out << getChild(i)->asJSON(visible(getClassName()) ? level + 2 : 1); - if (visible(getChild(i)->getClassName())) + out << "," << endl; + out << spaces(2*level+2); + out << "\"children\" : ["; + for (unsigned int i = 0; i < countChildren(); i++) { - out << "," << endl; + out << getChild(i)->asJSON(visible(getClassName()) ? level + 2 : 1); + if (visible(getChild(i)->getClassName()) && i0) + { + bool needcomma = visible(getClassName()); + for (unsigned int i = 0; i < countChildren(); i++) + { + string json = getChild(i)->asJSON(visible(getClassName()) ? level + 2 : 1); + + if(needcomma && strip(json)!="") + out << "," << endl; + out << getChild(i)->asJSON(visible(getClassName()) ? level + 2 : 1); + needcomma |= strip(json)!=""; + } + } + if (::enabled("output:list") && level == 0) { out << endl << "]" << endl; -- 2.33.1