Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[
        "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'}]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading