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())
    – cs95
    Jul 1, 2017 at 16:24
  • 1
    what's your OS? Jul 1, 2017 at 16:25
  • 1
    I'm using MacOs
    – kanglais
    Jul 1, 2017 at 16:26
  • 1
    you could use this answer... HTH 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!

Not the answer you're looking for? Browse other questions tagged or ask your own question.