1

Code

import json
file_name = "storing and reading JSON\user_number.json"
with open(file_name) as j_obj:
    num = json.load(j_obj)
    print("I know your favorite number, it's: " + str(num))

Error

error detail: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 24-25: truncated \uXXXX escape

pppery
  • 3,731
  • 22
  • 33
  • 46

1 Answers1

1

The issue is that you have accidently written an escape character in your file directory:

file_name = "storing and reading JSON\user_number.json"

Notice after storing and reading JSON you have \u? Python is interpreting it as an escape character and as a result it cannot load your JSON file.

The right way to write the directory would be to cancel out the escape sequence by writing a double backslash \\:

  file_name = "storing and reading JSON\\user_number.json"

For more information about escape characters

A. Smoliak
  • 438
  • 2
  • 17