DEV Community

oded
oded

Posted on

how do I turn a JASON schema to a javascript object?

I need to work with a "complex" object that contains an array of objects that contains an array of objects.
I have a JASON schema that describes this object.
I need to create a javascript object according the this schema.
I do NOT need need to validate data according to this JASON schema. The javascript code populates the array's items and properties by means of direct assignment, such as:
mainObj.series[1].instance[2].mode = "Mode 2";
Following is the JSON schema of the object:
{ "$schema": "http://json-schema.org/draft-07/schema#",
"title": "My-Special-Schema-Or-Data-Structure-Title",
"description": "Whatever I have to say about my described structure",
"type": "object",
"properties": {
"version": {
"description": " ... ",
"type": "string"
},
"series": {
"description": " ... ",
"type": "array",
"minItems": 1,
"items": {
"description": " ... ",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"possModes": {
"description": " ... ",
"type": "array"
},
"instance": {
"description": " ... ",
"type": "array",
"minItems": 1,
"items": {
"description": " ... ",
"type": "object",
"properties": {
"date": {
"type": "string"
},
"mode": {
"type": "string"
}
},
"required": [
"date",
"mode"
]
}
}
},
"required": [
"name",
"possModes",
"instance"
]
}
}
},
"required": [
"version",
"series"
]
}

Top comments (0)