matchms.importing.load_from_json module

matchms.importing.load_from_json.as_spectrum(dct: dict, metadata_harmonization: bool = True) dict | Spectrum | None[source]

A json.load() object_hook to convert dictionary shaped like spectrum into Spectrum object.


dct – Dictionary shaped like spectrum

Return type:

A Spectrum or None when no peaks where found.

matchms.importing.load_from_json.dict2spectrum(spectrum_dict: dict, metadata_harmonization: bool) Spectrum | None[source]

Convert dictionary to a Spectrum object.


spectrum_dict – Dictionary shaped like a single JSON object from the GNPS Spectra library

Return type:

A Spectrum or None when no peaks where found.

matchms.importing.load_from_json.load_from_json(filename: str, metadata_harmonization: bool = True) List[Spectrum][source]

Load spectrum(s) from json file.

JSON document formatted like the GNPS Spectra library. Spectrums with zero peaks will be skipped.


from matchms.importing import load_from_json

file_json = "gnps_testdata.json"
spectrums = load_from_json(file_json)
  • filename – Provide filename for json file containing spectrum(s).

  • metadata_harmonization (bool, optional) – Set to False if metadata harmonization to default keys is not desired. The default is True.


Object_hook function to convert JSON dictionary with Score object into a python dictionary.