I am using blender on windows, following the tutorial: Visualize JSON Data in blender but I am stuck trying to open the JSON file.
My code (windows):
import json
with open('C:\Users\Franktabs\Documents\export.json') as f:
j = json.load(f)
print(j)
His code(linux):
import json
with open('/home/chris/Downalds/tutorial.son') as f:
j = json.load(f)
print(j)
Error Message:
Python: File "C:\Users\Franktabs\Documents\Json2.blend\My Script", line 3
with open('C:\Users\Franktabs\Documents\export.json') as f:
^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
location: <unknown location>:-1
Solutions Tried:
- Using import bpy
- Using double \
- Using 'r'
- Using utf-8
- Checking the file type is actually .json
- Checking the route and name of the file in properties
Solutions sources from a person with the same problem: post1,post2
\to forward slashes/.os.path.joinshould be used instead.os.path.joinis still going to need a base path, which will almost certainly include\U..., which is what is triggering the unicode error. Forward slashes are perfectly acceptable in Windows path literals, and OP claimed to have tried\\andrliterals (which I doubt were done correctly, as they failed, but that's another topic). It's just something else to try without changing the actual code.