SCRIPTS NAMELISTS jsonΒΆ

# -*-Python-*-
# Created by bgrierson at 10 Jun 2017  07:04

"""
This script shows how to use a JSON format file like a namelist.

"""

# Set up the OMFIT tree to store the output from this script
root['OUTPUTS'].setdefault('NAMELISTS', OMFITtree())

# Create a JSON format file
json1 = OMFITjson('json1.json')

# Fill the file with basic data types
json1['str'] = 'text'
json1['num'] = 1.0
json1['arr'] = np.array([1.0, 2.0])
json1['list'] = ['one', 1]
json1['dict'] = {'one': 1.0}

# One key capability for OMFIT is storing a list of lists, which is (20170610) not allowed
# or would need to be stored as a pickle file.
json1['list2'] = [[1, 2], [1], []]

root['OUTPUTS']['NAMELISTS']['json'] = json1