Hi - I apologize if I'm barking up the wrong tree here, but I seem to be missing something:
I have defined a schema doc, snippet below, allowing for a null plateId in the json doc:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"PlateTracking": {
"type": "object",
"properties": {
"accessionNumber": {
"type": "string"
},
"barcode": {
"type": "string"
},
},
},
...
"Plate": {
"title": "Plate",
"type": "object",
"properties": {
"plateId": {
"oneOf": [
{
"type": "null"
},
{
"$ref": "#/definitions/PlateTracking"
}
]
},
"name": {
"type": "string"
},
...
Example of my valid json is with a null plateId object:
{
"plate": {
"plateId": null,
"name": "foobar",
...
I have a function that successfully validates the json data doc against the jsonschema doc:
def validate_json(schema_file_name, data_file_name, read_write_mode = 'r'):
# load the schema file as read-only
with open(schema_file_name, 'r') as f:
schema_data = f.read()
schema = json.loads(schema_data)
# load the data file
with open(data_file_name, read_write_mode) as f:
data = f.read()
json_data = json.loads(data)
# validate
try:
jsonschema.validate(json_data, schema)
return json_data
except jsonschema.ValidationError as e:
print(e.message)
raise e
except jsonschema.SchemaError as e:
print(e)
raise e
return None
My issue is this: given the schema object, how do I create a PlateTracking object and attach it to plate.plateId?
I am not looking to create a json string, but am interested in dealing with Python classes/objects. Is this possible?
Again, apologies, if missing something very basic here. Hoping so.
Best,
E