savejson#

savejson(filename=None, obj=None, folder=None, die=True, indent=2, keepnone=False, sanitizepath=True, **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

  • sanitizepath (bool) – whether to sanitize the path prior to saving

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

Returns:

The filename saved to

Example:

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

See also sc.jsonify().