spacepy.datamodel.toJSONheadedASCII(fname, insd, metadata=None, depend0=None, order=None, **kwargs)[source]

Write JSON-headed ASCII file of data with metadata from SpaceData object


Filename to write to (can also use a file-like object) None can be given in conjunction with the returnString keyword to skip writing output


SpaceData with associated attributes and variables in dmarrays

Other Parameters
depend0str (optional)

variable name to use to indicate parameter on which other data depend (e.g. Time)

orderlist (optional)

list of key names in order of start column in output JSON file

metadata: str or file-like (optional)

filename with JSON header to use (or file-like with JSON metadata)

delimiter: str

delimiter to use in ASCII output (default is whitespace), for tab, use ‘ ‘


>>> import spacepy.datamodel as dm
>>> data = dm.SpaceData()
>>> data.attrs['Global'] = 'A global attribute'
>>> data['Var1'] = dm.dmarray([1,2,3,4,5], attrs={'Local1': 'A local attribute'})
>>> data['Var2'] = dm.dmarray([[8,9],[9,1],[3,4],[8,9],[7,8]])
>>> data['MVar'] = dm.dmarray([7.8], attrs={'Note': 'Metadata'})
>>> dm.toJSONheadedASCII('outFile.txt', data, depend0='Var1', order=['Var1'])
#Note that not all field names are required, those not given will be listed
#alphabetically after those that are specified