Can't read json

import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *
import sys
sys.path.append(r’C:\Program Files (x86)\IronPython 2.7\DLLs’)
sys.path.append(r’C:\Program Files (x86)\IronPython 2.7\Lib’)
import json

jsonPath = IN[0]


#Load Json
with open(jsonPath, "r") as read_file:
   	    data = json.load(read_file)
    
for item in data:
    Name = item["Naam"]
    Location = item["Locatie"]

        
OUT = Location

i am using this code, but it won’t read my Json

{ 
"Naam": "Arno", 
"Locatie":"D:\00_Algemeen\DynamoLogs" 
}

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 15, in
File “C:\Program Files\Autodesk\Revit 2020\AddIns\DynamoForRevit\IronPython.StdLib.2.7.8\json_init_.py”, line 287, in load
File “C:\Program Files\Autodesk\Revit 2020\AddIns\DynamoForRevit\IronPython.StdLib.2.7.8\json_init_.py”, line 339, in loads
File “C:\Program Files\Autodesk\Revit 2020\AddIns\DynamoForRevit\IronPython.StdLib.2.7.8\json\decoder.py”, line 364, in decode
File “C:\Program Files\Autodesk\Revit 2020\AddIns\DynamoForRevit\IronPython.StdLib.2.7.8\json\decoder.py”, line 380, in raw_decode
File “C:\Program Files\Autodesk\Revit 2020\AddIns\DynamoForRevit\IronPython.StdLib.2.7.8\json\scanner.py”, line 37, in _scan_once
File “C:\Program Files\Autodesk\Revit 2020\AddIns\DynamoForRevit\IronPython.StdLib.2.7.8\json\decoder.py”, line 194, in JSONObject
File “C:\Program Files\Autodesk\Revit 2020\AddIns\DynamoForRevit\IronPython.StdLib.2.7.8\json\scanner.py”, line 35, in _scan_once
File “C:\Program Files\Autodesk\Revit 2020\AddIns\DynamoForRevit\IronPython.StdLib.2.7.8\json\decoder.py”, line 123, in py_scanstring
ValueError: Invalid \escape: ‘N’: line 3 column 26 (char 47)

I think it is a problem with special characters “\” in your path. Try to replace them with “/” or “\\”.
See here:

2 Likes

thanks that got me a bit further.

only problem now:

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 18, in
TypeError: expected index value, got str

for item in data:
    Name = item["Naam"]
    Location = item["Locatie"]

line 18 is the location

try this:

with open(path,"r") as read_file:
	data=json.load(read_file)
	location = data["Locatie"]
1 Like

Maciek,

of course stupid mistake … thanks for your help