#! /usr/local/bin/python import json import netCDF4 as nc import os # Setup save directory and file save_dir = '.' ncml_file='/Users/knuth/Desktop/first_in_class/Cabled_Array/RS01SBPS/RS01SBPS-SF01A/RS01SBPS-SF01A-3D-SPKIRA101/computed_provenance/RS01SBPS-SF01A-3D-SPKIRA101-streamed-spkir_data_record-20150709T000000-20150709T055959.nc' # grab file name for saving of json file file_name = os.path.basename(ncml_file) print "Printing provenance information for " + file_name print "key : Value" file_load = nc.Dataset(ncml_file) # only list the provenance variables in the netcdf files prov_list = [s for s in file_load.variables if 'provenance' in s] # grab the provenance var = 'computed_provenance' qp = nc.chartostring((file_load.variables[var][:])) # convert character to string using netcdf4 toolbox parsed_json = json.loads(qp[0]) # load string into json # save the provenance save_file = os.path.join(save_dir, file_name) # create save file name outfile = open(save_file + "-" + var + ".json", "w") #create json file json.dump(parsed_json, outfile) # dump json data into the .json file outfile.close() # close the file.