""" Examine the JSON structure to understand the format """ import grpc import sys import io import json sys.path.append(r'C:\DEV\COPILOT\geutebruck-api\src\api') if sys.platform == 'win32': sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8') from protos import configuration_pb2 from protos import configuration_pb2_grpc print("="*70) print("EXAMINING JSON STRUCTURE") print("="*70) channel = grpc.insecure_channel('localhost:50051') stub = configuration_pb2_grpc.ConfigurationServiceStub(channel) # Export configuration as JSON print("\n1. Exporting configuration as JSON...") export_request = configuration_pb2.ExportJsonRequest() export_response = stub.ExportConfigurationJson(export_request) if not export_response.success: print(f" [ERROR] {export_response.error_message}") sys.exit(1) print(f" JSON size: {export_response.json_size} bytes") # Parse JSON config = json.loads(export_response.json_data) # Show top-level structure print("\n2. Top-level JSON keys:") for key in config.keys(): print(f" - {key}: {type(config[key]).__name__}") # If it's a simple structure, show first few entries if isinstance(config, dict): print("\n3. Sample of data:") count = 0 for key, value in config.items(): if count < 5: print(f" {key}: {str(value)[:100]}...") count += 1 # Save to file for manual inspection output_file = "config_structure_sample.json" with open(output_file, 'w', encoding='utf-8') as f: # Just save first 50 entries to keep it manageable if isinstance(config, dict): sample = dict(list(config.items())[:50]) json.dump(sample, f, indent=2) else: json.dump(config, f, indent=2) print(f"\n4. Saved sample to {output_file} for inspection") print("="*70)