private void BuildDomFromSchema(JsonData data, string tableName, JsonSchema schema = null) { // first, create a new table instance for the data JsonSchemaTable table = new JsonSchemaTable(tableName, data, this, schema); TableList.Add(table); JsonData objectToParse; if (data != null && data.IsArray) { objectToParse = data.Count > 0 ? data[0] : null; } else { objectToParse = data; } //enumerate all schema foreach (var property in schema.Properties) { string propertyName = property.Key; JsonData objectData = null; if (objectToParse != null && objectToParse.ContainsKey(propertyName)) { objectData = objectToParse[propertyName]; } if (property.Value.Type == JsonObjectType.Object) { if (IsFlattableR(property.Value)) { continue; } else { string newTableName = GetUniqueTableName(propertyName); JsonTableRelation relation = new JsonTableRelation(GetUniqueRelationName(tableName, newTableName), tableName, newTableName); RelationList.Add(relation); BuildDomFromSchema(objectData, newTableName, schema.Properties[propertyName]); } } // schema.Properties[propertyName].Item may be null if schema has no other definitions for the array ("Item": { "type": "array" }) => we wont add this array since it will always be an empty array with no columns else if (property.Value.Type == JsonObjectType.Array && schema.Properties[propertyName].Item != null) { // need to add a table anyway, either for a true object or just a fake table using "ArrayValue" as field name string newTableName = GetUniqueTableName(propertyName); JsonTableRelation relation = new JsonTableRelation(GetUniqueRelationName(tableName, newTableName), tableName, newTableName); RelationList.Add(relation); // see if there is an object underneath BuildDomFromSchema(objectData, newTableName, schema.Properties[propertyName].Item); } } }
public JsonSchemaEnumerator(JsonData data, JsonSchema schemaData, JsonSchemaTable table, SchemaAwareJsonDataProvider provider) : base(data, table, provider) { _schemaData = schemaData; }