0

I am new to python but I have learned lots of stuff, but I found difficulty to read a JSON file. I need to read it in a way to access a particular data in this file. The file contain a data as follow:

[
    29723,
    5426523,
    "this book need to be printed",
    "http://amzn.to/U60TaF"
][
    29723,
    807242528,
    "ready for shipping",
    "http://nblo.gs/HNpn"
]

my code is:

FI = open(file_name, 'r')
for line in FI:
    tweet = json.loads(line)
    print(tweet)

The output is only the last line which is the link, I don't know way.

2
  • 1
    If it "looks like a json file", but isn't a json file, then you cannot use json to read it. You need to have a specification of the file, and then use a reader made for that. If it does not exist, you have to write you own. There is no "almost like a X" in programming. Computers are too precise for that. Commented Oct 12, 2016 at 19:45
  • Thanks, you probably right Commented Oct 13, 2016 at 22:22

1 Answer 1

2

Try

data = json.load(open(file_name))
Sign up to request clarification or add additional context in comments.

3 Comments

@AlghamdiBandar can you share the error you are getting?
There is no error, it just gave the last line of each block which is the link
Can you share link to your sample code and sample file which you are trying to parse? You can use pastebin.com/index.php for sharing code.

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.