2

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???

HiPownedBi
  • 195
  • 2
  • 8
  • 18

1 Answers1

12

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.

MattMS
  • 1,106
  • 1
  • 16
  • 32