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

4
  • 2
    Possible duplicate of Parse JSON in Python Commented Jan 13, 2017 at 10:02
  • Possible duplicate of Parsing values from a JSON file? Commented Jan 13, 2017 at 10:03
  • OH PLEASE, IT IS READ TXT ,not duplicated Commented Jan 13, 2017 at 10:04
  • Also, if your .txt is in JSON format, you should rename it ".json". Commented Jan 13, 2017 at 10:04

1 Answer 1

16

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.