Skip to content

print_mongo_paths #44

@swuecho

Description

@swuecho
def print_mongo_paths(json_object, current_path=""):
    if isinstance(json_object, dict):
        for key, value in json_object.items():
            new_path = f"{current_path}.{key}" if current_path else key
            print_mongo_paths(value, new_path)
    elif isinstance(json_object, list):
        for i, item in enumerate(json_object):
            new_path = f"{current_path}.{i}" if current_path else str(i)
            print_mongo_paths(item, new_path)
    else:
        print(current_path)

# Example JSON object
example_json = {
    "file": [
        {
            "extraction": {
                "signature": {
                    "extraction": [
                        {
                            "signature": {
                                "extraction": {
                                    "normalized_value": "example_value"
                                }
                            }
                        }
                    ]
                }
            }
        }
    ]
}

# Print paths in MongoDB query format
print_mongo_paths(example_json)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions