Skip to content

Commit 9fc86f9

Browse files
authored
Merge pull request #558 from geeksville/pr-fixjson
Pretty indent --info JSON output (see below for details)
2 parents e5999f5 + 7fe98bc commit 9fc86f9

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

meshtastic/mesh_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def showInfo(self, file=sys.stdout) -> str: # pylint: disable=W0613
134134
# use id as dictionary key for correct json format in list of nodes
135135
nodeid = n2["user"]["id"]
136136
nodes[nodeid] = n2
137-
infos = owner + myinfo + metadata + mesh + json.dumps(nodes)
137+
infos = owner + myinfo + metadata + mesh + json.dumps(nodes, indent=2)
138138
print(infos)
139139
return infos
140140

meshtastic/node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ def showInfo(self):
6464
"""Show human readable description of our node"""
6565
prefs = ""
6666
if self.localConfig:
67-
prefs = message_to_json(self.localConfig)
67+
prefs = message_to_json(self.localConfig, multiline=True)
6868
print(f"Preferences: {prefs}\n")
6969
prefs = ""
7070
if self.moduleConfig:
71-
prefs = message_to_json(self.moduleConfig)
71+
prefs = message_to_json(self.moduleConfig, multiline=True)
7272
print(f"Module preferences: {prefs}\n")
7373
self.showChannels()
7474

meshtastic/util.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,8 @@ def check_if_newer_version():
627627

628628
return pypi_version
629629

630-
def message_to_json(message):
631-
"Return protobuf message as JSON. Always print all fields, even when not present in data."
632-
return stripnl(MessageToJson(message, always_print_fields_with_no_presence=True))
630+
631+
def message_to_json(message, multiline=False):
632+
"""Return protobuf message as JSON. Always print all fields, even when not present in data."""
633+
json = MessageToJson(message, always_print_fields_with_no_presence=True)
634+
return stripnl(json) if not multiline else json

0 commit comments

Comments
 (0)