diff --git a/circuitpython/code/main.py b/circuitpython/code/main.py index 986fc1f..fb6ef79 100644 --- a/circuitpython/code/main.py +++ b/circuitpython/code/main.py @@ -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: