2

I'm working with a large json file that is currently encoded as one long line.

This makes it unintelligable for other people to work with, so I want to render it using pprint.

At the moment I'm trying to import the full file and print as pprint but my output looks like this:

<_io.TextIOWrapper name='hash_mention.json' mode='r' encoding='UTF-8'>

My question is- what is that showing? How can I get it to output the json data as pprint?

The code I've written looks like this:

import pprint

with open('./hash_mention.json', 'r') as input_data_file:

    pprint.pprint(input_data_file)
4
  • 1
    pprint.pprint(input_data_file) --> pprint.pprint(input_data_file.read()) Commented Jul 1, 2017 at 16:24
  • 1
    what's your OS? Commented Jul 1, 2017 at 16:25
  • 1
    I'm using MacOs Commented Jul 1, 2017 at 16:26
  • 1
    you could use this answer... HTH Commented Jul 1, 2017 at 16:26

1 Answer 1

1

You opened the file in read mode but forgot to read the file contents.

Just change pprint.pprint(input_data_file) with pprint.pprint(input_data_file.read()) and voila!

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.