The following Python code snippet uses the JSON output to try to reset all SEGGER J-Link devices and print the result of the operation for each device:
import json
import subprocess;
# Run reset operation on all connected jlink devices and collect the output
output = subprocess.run(["nrfutil", "device", "reset", "--json", "--traits", "jlink"],
capture_output=True)
stdout_as_lines = output.stdout.decode("utf-8").split("\n")[0:-1]
for line in stdout_as_lines:
parsed_line = json.loads(line)
# Find the lines indicating that a task ended
if parsed_line["type"] == "task_end":
# Print the results of the operation
print("{}: {}".format(parsed_line["data"]["task"]["description"],
parsed_line["data"]["result"]))