0

I created a JSON file using pandas and not able to open the file as a dictionary, just as a string. Using windows, anaconda, python, pandas, and Jupyter notebooks.

I have checked StackOverflow for the issues and not able to find a useful solution. I did confirm with a simple json file the print(type(json.load(file)) does in fact produce a "class 'dict'"

'''

books = books[["AuthorName", "BookNumber", "BookTitle" ]]
books.head(10)

books_json = books.to_json(orient='index')

with open(path + 'books\\books_json.json', 'w' 
          ) as out_put:
    json.dump(books_json, out_put)  

with open(path + 'books\\books_json.json', 'r'
         ) as out_put:
    print(json.load(out_put))
    print(type(json.load(out_put)))

error is:
JSONDecodeError: Expecting value: line 1 column 1 (char 0)

'''

I expect to see "class 'dict'" as the type when the "print(type(json.load(out_put)))" command is run, currently receiving an error.

Error is "JSONDecodeError: Expecting value: line 1 column 1 (char 0)"

Joe Larson
  • 53
  • 1
  • 7
  • The created json file has this putput : "{\"0\":{\"AuthorName\":\" Mary Wollstonecraft (Godwin) Shelley\",\"BookNumber\":\" 84\",\"BookTitle\":\" Frankenstein, or the Modern Prometheus\"},\"1\":{\"AuthorName\":\" Charles Dickens\",\"BookNumber\":\" 730\",\"BookTitle\":\" Oliver Twist or the Parish Boy's Progress\"},\"4\":{\"AuthorName\":\" James Joyce\",\"BookNumber\":\" 4300\",\"BookTitle\":\" Ulysses\"}}" – Joe Larson Oct 07 '19 at 22:46

1 Answers1

0

pandas JSON are saved as a series or string, not a dictionary. in 0.24, the word dictionary have very limited usage and is not offered as an output data type.

see Convert pandas data frame to series

Joe Larson
  • 53
  • 1
  • 7