0

I'm trying to filter all the data1 values from a json file and output them to a file. The json looks like this:

[
  {
    "data1": "1234", 
    "data2": "8972a" 
  },
  {
    "data1": "7531", 
    "data2": "5568b" 
  }
]

I'm still trying to open the file but I constantly get an error saying:

the JSON object must be str, bytes or bytearray, not TextIOWrapper

this is my code:

import json

filename = "C:\\Path\\To\\File\\file.json"
input_json = json.loads(open(filename, 'r'))

I'm trying to get a file with:

1234
7531

1 Answers1

0

Your JSON file is invalid. Try this:

[
  {
    "data1": "1234",
    "data2": "8972a"
  },
  {
    "data1": "7531",
    "data2": "5568b"
  }
]

Use this link to find out a possible solution: how to read json object in python

tcconstantin
  • 369
  • 1
  • 4