JSON Interface¶
-
muspy.
load_json
(path: Union[str, pathlib.Path, TextIO], compressed: bool = None) → muspy.music.Music[source] Load a JSON file into a Music object.
Parameters: Returns: Loaded Music object.
Return type: Notes
When a path is given, assume UTF-8 encoding and gzip compression if compressed=True.
-
muspy.
save_json
(path: Union[str, pathlib.Path, TextIO], music: Music, skip_missing: bool = True, ensure_ascii: bool = False, compressed: bool = None, **kwargs)[source] Save a Music object to a JSON file.
Parameters: - path (str, Path or TextIO) – Path or file to save the JSON data.
- music (
muspy.Music
) – Music object to save. - skip_missing (bool, default: True) – Whether to skip attributes with value None or those that are empty lists.
- ensure_ascii (bool, default: False) – Whether to escape non-ASCII characters. Will be passed to PyYAML’s yaml.dump.
- compressed (bool, optional) – Whether to save as a compressed JSON file (.json.gz). Has no effect when path is a file object. Defaults to infer from the extension (.gz).
- **kwargs – Keyword arguments to pass to
json.dumps()
.
Notes
When a path is given, use UTF-8 encoding and gzip compression if compressed=True.
Note
A JSON schema is available for validating a JSON fiule against MusPy’s format.