Remove specific lines in json file using python

So I got a json file that looks like this :

[
    {
        "mint": "FVc2AoQDyzxQkrAaHUt7GdqBXng9YwhSGkqBJ2DAqkES",
        "holder": "8M6dq1ieLKeMQqsuHYynsy3mDKzPLJrMH5UcbJB7YfmE"
    },
    {
        "mint": "HBid7GNCZZwCtBktWcN6N6YuV47QEFKZWi6pRtwd7616"
    },
    {
        "mint": "AwJFMswcw9WmV1CjkuSRF5VqfsX2neSZUjqwXsqnQKcb"
    },
    {
        "mint": "BTXciaAzzcZ5ge4q43GweAAqSRF3VEXTPRTw5xtxA63J",
        "holder": "77KvrLhgAo5xc2rmyvVkknhS1yVCCUAf25dhXdSgAxup"
    },
]

I want to remove the following:

  • lines starting with "mint"
  • brackets {}
  • commas ,.

Expected output:

[
        "holder": "8M6dq1ieLKeMQqsuHYynsy3mDKzPLJrMH5UcbJB7YfmE"
        "holder": "77KvrLhgAo5xc2rmyvVkknhS1yVCCUAf25dhXdSgAxup"
]

It would be great if someone can help me do this with a python or JavaScript script. Thanks! 🙂

>Solution :

See if this works for you, your output is unclear but I gave it a shot

results = [
    {
        "mint": "FVc2AoQDyzxQkrAaHUt7GdqBXng9YwhSGkqBJ2DAqkES",
        "holder": "8M6dq1ieLKeMQqsuHYynsy3mDKzPLJrMH5UcbJB7YfmE"
    },
    {
        "mint": "HBid7GNCZZwCtBktWcN6N6YuV47QEFKZWi6pRtwd7616"
    },
    {
        "mint": "AwJFMswcw9WmV1CjkuSRF5VqfsX2neSZUjqwXsqnQKcb"
    },
    {
        "mint": "BTXciaAzzcZ5ge4q43GweAAqSRF3VEXTPRTw5xtxA63J",
        "holder": "77KvrLhgAo5xc2rmyvVkknhS1yVCCUAf25dhXdSgAxup"
    },
]

needed_list = []
for i in results:
    try:
        needed_list.append({'holder' : i['holder']})
    except:
        continue

print(needed_list)

output

[{'holder': '8M6dq1ieLKeMQqsuHYynsy3mDKzPLJrMH5UcbJB7YfmE'}, {'holder': '77KvrLhgAo5xc2rmyvVkknhS1yVCCUAf25dhXdSgAxup'}]

Leave a Reply