import json

def check_item(item, path="root"):
    if 'item' in item:
        if not isinstance(item['item'], list):
            print(f"ERROR: {path} > item is not a list! Type: {type(item['item'])}")
        else:
            for i, child in enumerate(item['item']):
                check_item(child, f"{path} > item[{i}]")
    
    if 'request' in item:
        req = item['request']
        if 'header' in req and not isinstance(req['header'], list):
            print(f"ERROR: {path} > request > header is not a list!")
        
        if 'url' in req:
            url = req['url']
            if isinstance(url, dict):
                if 'host' in url and not isinstance(url['host'], list):
                    print(f"ERROR: {path} > request > url > host is not a list!")
                if 'path' in url and not isinstance(url['path'], list):
                    print(f"ERROR: {path} > request > url > path is not a list!")
            elif not isinstance(url, str):
                print(f"ERROR: {path} > request > url is not a dict or str!")

    if 'response' in item:
        resps = item['response']
        if not isinstance(resps, list):
            print(f"ERROR: {path} > response is not a list!")
        else:
            for i, resp in enumerate(resps):
                if 'header' in resp and not isinstance(resp['header'], list):
                    print(f"ERROR: {path} > response[{i}] > header is not a list!")

def main():
    try:
        with open('apidog_collection.json', 'r') as f:
            data = json.load(f)
            check_item(data)
            print("Validation complete.")
    except Exception as e:
        print(f"Failed to load or parse JSON: {e}")

if __name__ == "__main__":
    main()
