0

a json file = a.json

{"xt_Adminserver_URL": "10.0.1.5:2346"}.
{"LinuxAdServer": "10.0.1.6"}.
{"WindowsAdminServer": "10.0.1.8"}.
{"JlLmsServer": "12.17.10.81:1688 "}.
{"token": "KT99999"}.
{"WONumber": "WO0000123456"}.
{"VMbuilderID": "A12G456"}.
{"QAreviewerID": "B65I321"}.
{"utilization": "n"}.
{"static_fqdn": "False"}.
{"branch": "new_dev"}

I'm trying to bring each one in as a variable in a python script, what is the correct way to read this and assign variables?

xpun8
  • 1
  • 2
  • Does this answer your question? [convert dictionary entries into variables - python](https://stackoverflow.com/questions/18090672/convert-dictionary-entries-into-variables-python) – Bhavani Ravi May 19 '20 at 03:57

1 Answers1

0

Firstly you would need to import json module and then use it's load method to load the specified file.

import json 

f = open ('dataFile.json', "r") 
data = json.loads(f.read()) 

Then you can this data object like normal dictionaries in python.

If you just want to deserialize a json string to dictionary. You can pass the string to json.loads(jsonString) and it would convert it to a dictionary. Hope this helps.