matchms.exporting.save_as_json module
- matchms.exporting.save_as_json.create_spectrum_json_encoder(export_style)[source]
Creates a custom JSON encoder for matchms.Spectrum.Spectrum objects.
- matchms.exporting.save_as_json.save_as_json(spectra: list[Spectrum], filename: str, export_style: str = 'matchms') None[source]
Save spectrum(s) as json file.
Example:
import numpy as np from matchms import Spectrum from matchms.exporting import save_as_json # Create dummy spectrum spectrum = Spectrum( mz=np.array([100, 200, 300], dtype="float"), intensities=np.array([10, 10, 500], dtype="float"), metadata={"charge": -1, "inchi": '"InChI=1S/C6H12"', "precursor_mz": 222.2}, ) # Write spectrum to test file save_as_json(spectrum, "test.json")
- Parameters:
spectra – Expected input is a list of
Spectrumobjects.filename – Provide filename to save spectrum(s).
export_style – Converts the keys to the required export style. One of [“matchms”, “massbank”, “nist”, “riken”, “gnps”]. Default is “matchms”