Thursday, August 13, 2020

Read data from json

 json sample:

{"name": "Bob", 
"languages": ["English", "Fench"]
}

Python code:

import json,os

script = os.path.dirname(os.path.realpath(__file__) )
print("SCript path:", script) 

with open(script + '/person.json') as f:
  data = json.load(f)

# Output: {'name': 'Bob', 'languages': ['English', 'Fench']}
print(data['name'])

Ref: 1 2 3

No comments:

Post a Comment