#!/usr/bin/python3 # import json module import json import re # import pprint module from pprint import pprint # read json file and create an python dictionary with open('/home/scripts/ffluxbot/nodes.json') as f: data = json.load(f) # print whole json file # pprint (data) # print specific value of speciifc item of json fle #pprint (data["nodes"][0]["nodeinfo"]) # print keys #x = data.keys() #pprint (x) regex = re.compile('fd4e.*') #y = data.items() #pprint (y) #z = data.values() #pprint (z) # print hostnames and IPV6 addresses of all nodes for each in data['nodes']: hostname = each['nodeinfo']['hostname'] iplist = each['nodeinfo']['network']['addresses'] IP = str(list(filter(regex.match,iplist))[0]) print('{} {}'.format(IP, hostname))