Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to read json.txt and parse json python READ TXT PYTHON

Tags:

python

json

I have one txt file: resultJSON.txt

the data in the txt file is in JSON format.

{
    "term": "dog",
    "results": [{
        "filename": "1.jpg",
        "numberID": "D12"
    }, {
        "filename": "23.jpg",
        "number": "E52"
    }]
}

I would like to read the txt into python and parse the JSON.

How to read the txt???

like image 862
HiPownedBi Avatar asked Aug 11 '26 00:08

HiPownedBi


1 Answers

Make sure the following code is in the same folder as resultJSON.txt:

import json
with open('resultJSON.txt') as f:
    json_data = json.load(f)

Your data will be in json_data.

like image 177
MattMS Avatar answered Aug 13 '26 12:08

MattMS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!