sciris.sc_fileio.savejson

savejson(filename=None, obj=None, folder=None, die=True, indent=2, keepnone=False, **kwargs)[source]

Convenience function for saving to a JSON file.

Parameters
  • filename (str) – the file to save

  • obj (anything) – the object to save; if not already in JSON format, conversion will be attempted

  • folder (str) – folder if not part of the filename

  • die (bool) – whether or not to raise an exception if saving an empty object

  • indent (int) – indentation to use for saved JSON

  • keepnone (bool) – allow sc.savejson(None) to return ‘null’ rather than raising an exception

  • kwargs (dict) – passed to json.dump()

Returns

None

Example:

json = {'foo':'bar', 'data':[1,2,3]}
sc.savejson('my-file.json', json)