Skip to content

Instantly share code, notes, and snippets.

@cchurch
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cchurch/a4c5778f5f8ced0b01d7 to your computer and use it in GitHub Desktop.
Save cchurch/a4c5778f5f8ced0b01d7 to your computer and use it in GitHub Desktop.
{
"log": {
"id": "http://192.168.43.81:8080/api/collections/nodes/node1/log",
"name": "log"
},
"tags": [],
"facts": {
"hardwareisa": "x86_64",
"macaddress": "08:00:27:e7:06:4d",
"architecture": "x86_64",
"hardwaremodel": "x86_64",
"processor0": "Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz",
"processorcount": "1",
"interfaces": "enp0s17,lo",
"ipaddress_enp0s17": "192.168.1.63"
}
}
import json
# Option 1: Read JSON directly from file object:
data = json.load(open('data.json'))
# Option 2: Read file into string, then parse as JSON:
s = open('data.json').read()
data = json.loads(s)
# Read the MAC address from the data, or set to None if it can't be found.
try:
macaddress = data['facts']['macaddress']
except KeyError:
macaddress = None
print(macaddress)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment