def json_mapping_parser(path, template):
 mapping_blocks = {}
 with open(path, 'r') as handle:
  for (tid, rows) in json.load(handle).iteritems():
   mappings = {}
   for (key, values) in rows.iteritems():
    mapping = {template.get(k, k): v for (k, v) in values.iteritems()}
    mappings[int(key)] = mapping
   mapping_blocks[tid] = mappings
 return mapping_blocks

def json_mapping_parser ( path , template ) : mapping_blocks = { } with open ( path , 'r' ) as handle : for ( tid , rows ) in json . load ( handle ) . iteritems ( ) : mappings = { } for ( key , values ) in rows . iteritems ( ) : mapping = { template . get ( k , k ) : v for ( k , v ) in values . iteritems ( ) } mappings [ int ( key ) ] = mapping mapping_blocks [ tid ] = mappings return mapping_blocks
given a json file of the the mapping data for a modbus device .