json¶
Functions for interacting with json objects
- pretty(path: str = '.', indent: int = 4, sort_keys: bool = True, overwrite: bool = True) int[source]
takes one or more .json files and makes them human-readable
will only work on files ending with .json, all other files are skipped
appends ‘_pretty’ to the end of the base filename, i.e. ‘data.json’ becomes ‘data_pretty.json’
skips files already ending with ‘_pretty.json’ - we assume those are already done
- Parameters:
path (str) –
path to file or folder to work on
if a file, will only do that file
- if a folder, will do every file in that folder
does not search subfolders
default: current working directory
indent (int) –
number of spaces to indent by
default: 4
sort_keys (bool) –
whether to sort keys
default: True
overwrite (bool) –
whether to overwrite a ‘_pretty.json’ file if it already exists
default: True
- Returns:
number of files that were formatted
- Return type:
int