Atom

JSON configuration loader

Save as load-config.atom and run atom run load-config.atom. Optionally pass a file path with -- settings.json, for example a file containing {"theme":"dark","volume":55}. Requires JSON and libuv.

load-config.atom
use json
use os

func load_settings(source):
    record = json.decode(source)
    assert(type(record) == dict, 'settings must be an object')
    volume = convert(i64, get(record, 'volume', 70))
    assert(volume >= 0 and volume <= 100, 'volume outside 0 to 100')
    return {theme = record.theme ?? 'light', volume = volume}

payload = '\{"theme":"dark","volume":55}'
if count(os.args) > 0:
    payload = read(os.args[0])
config = load_settings(payload)
print(json.encode(config, true))