I have an absolute path to a json file which looks like this:
{
"name": "PyCharm",
"version": "2019.2.1",
"buildNumber": "192.6262.63",
"productCode": "PC",
"svgIconPath": "../bin/pycharm.svg",
"launch": [
{
"os": "macOS",
"launcherPath": "../MacOS/pycharm",
"javaExecutablePath": "../jbr/Contents/Home/bin/java",
"vmOptionsFilePath": "../bin/pycharm.vmoptions"
}
]
}
The absolute file looks like this:
data = os.path.abspath("/Applications/PyCharm\ CE.app/Contents/Resources/product-info.json")
I'm trying to access the "version" in the Json file using this :
pycharm_version = data["version"]
print(pycharm_version)
But anytime im running the program im getting an error;
TypeError: string indices must be integers
Does anyone have an idea of how to fix it?
datais read as astring. parse it asjsonwithjson.loads(data)before trying to get values out of it.abspathdoesn't read data from a file; it takes a relative path and returns the equivalent absolute path, based on the current working directory.