def parse_responses(self, received): print(received) # Only take up to semicolon received = received.split(";")[0] # Should get json back try: response = json.loads(received) except json.JSONDecodeError as e: print(e) # If it fails, return 'null' circuit return Circuit() # Start building the circuit circuit = Circuit() # Check for root_component if "root" in response: root_component = response["root"] else: root_component = "" circuit.set_root(root_component) # Get the connections if "connections" in response: for connection in response["connections"]: # Double check the format is correct if "-" in connection: circuit.add_connection( Connection( connection.split("-")[0], connection.split("-")[1])) return circuit