The JSON Schema is here:
https://www.encodeproject.org/profiles/experiment#raw
I'm calling:
datamodel-codegen --input experiment.json --input-file-type jsonschema --output models/experiment.py --output-model-type pydantic_v2.BaseModel
The model is loaded perfectly by pydantic, but my specific data fails to validate:
$ python validate.py
Validation failed!
165 validation errors for Experiment
biosample_ontology
Input should be a valid string [type=string_type, input_value={'status': 'released', 's... 'K-562', 'K-562 cell']}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.4/v/string_type
analyses.0
Input should be a valid string [type=string_type, input_value={'documents': ['/document...'ENCODE4 v1.2.1 GRCh38'}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.4/v/string_type
analyses.1
Input should be a valid string [type=string_type, input_value={'documents': ['/document...ENCODE4 v1.15.0 GRCh38'}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.4/v/string_type
...
Here is the code of my simple validator script:
import json
from pydantic import ValidationError
from models.experiment import Experiment
def validate_json(json_data):
try:
Experiment(**json_data)
print("Validation successful!")
except ValidationError as e:
print("Validation failed!")
print(e)
if __name__ == "__main__":
# Load JSON data to be validated
with open('experiment-ENCSR545YBD.json', 'r') as f:
data_json = json.load(f)
# Validate
validate_json(data_json)
The experiment JSON can be downloaded here:
https://www.encodeproject.org/experiments/ENCSR545YBD/?format=json
I guess it's to do with the complex data types not being strings, and being represented as $refs, but I don't know what I@m doing π
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too