Debug json : now valid compact JSON (RFC 4627)

This commit is contained in:
Pierrick C 2018-08-03 20:38:46 +02:00
parent f07f998771
commit 588a0e815c

View File

@ -117,14 +117,27 @@ class Data:
def json(self):
"""Serialize data to json-formatted string"""
output = "{"
output = '{'
first_source = True
for source in self.data.keys():
output = "".join((output, "'", source, "': \n"))
if first_source:
first_source = False
comma_src = ""
else:
comma_src = ","
output = '{}{}"{}":'.format(output, comma_src, source)
if not self.data[source] == None:
output = output + '{'
first_data = True
for d in self.data[source].items():
output = "".join((output, " {'{}': '{}'}}\n".format(d[0], d[1])))
output = output + "}, \n"
output = output + "}"
if first_data:
comma = ""
first_data = False
else:
comma = ","
output = '{}{}"{}":"{}"'.format(output, comma, d[0], d[1])
output = output + '}'
output = output + '}'
return output
def atmo2rgb(self):
@ -279,7 +292,7 @@ while True:
data.update()
if print_data:
data.show()
# print(data.json())
print(data.json())
if backup_data:
data.write_on_flash()
if data_to_neopixel: