blob: 0d9c65d13eb909365fcb952dd03f409274350442 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
From 15565229509455527de9ce7cbb9530e2b31d043b Mon Sep 17 00:00:00 2001
From: Lyonel Vincent <lyonel@ezix.org>
Date: Wed, 27 May 2020 01:07:16 +0200
Subject: [PATCH] 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()) && i<countChildren()-1)
+ {
+ out << "," << endl;
+ }
}
+ out << "]";
}
if(visible(getClassName()))
@@ -1665,6 +1672,20 @@ string hwNode::asJSON(unsigned level)
out << "}";
}
+ if(::enabled("output:list") && countChildren()>0)
+ {
+ 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;
|