# Validation of mzQC documents

#### Chris Bielow chris.bielow@fu-berlin.de

#### 2025-07-15

# How to syntactically validate an mzQC file

The mzQC file format is based upon JSON. When writing a JSON file, certain substructures are required by the mzQC specification document, other items are optional. The syntax validator build into `rmzqc` allows you to check if all mandatory items are present, or if something was erroneously omitted in the mzQC file.

There are three validation functions validateFromFile(), validateFromString() and validateFromObj(), depending on the data you have at hand. Their result is always a bool (TRUE/FALSE) which has some attributes (usually ‘errors’) attached. Simply print the bool or call ‘attributes()’ on the result (in case of failure) to inspect details.

To validate a file simply:

    library(rmzqc)
    mzQC_filename = system.file("testdata/test.mzQC", package="rmzqc")
    #mzQC_filename = "C:\\dev\\rmzqc\\inst\\testdata\\test.mzQC"
    res = validateFromFile(mzQC_filename)
    res

If you have the file already as a JSON string in R (i.e. no need to load the data from a file), then simply use ‘validateFromString()’

    library(rmzqc)
    mzQC_strings = readLines(system.file("testdata/test.mzQC", package="rmzqc"))
    res = validateFromString(mzQC_strings)
    res

Finally, if you have an mzQC root object in hand, then call ‘validateFromObj()’

    library(rmzqc)
    mzQC_root = rmzqc::readMZQC(system.file("testdata/test.mzQC", package="rmzqc"))
    res = validateFromObj(mzQC_root)
    res