diff --git a/packages/frontend-core/src/fetch/DataFetch.js b/packages/frontend-core/src/fetch/DataFetch.js index 9d583f161c..ecd5313af5 100644 --- a/packages/frontend-core/src/fetch/DataFetch.js +++ b/packages/frontend-core/src/fetch/DataFetch.js @@ -259,6 +259,24 @@ export default class DataFetch { return null } + // Check for any JSON fields so we can add any top level properties + let jsonAdditions = {} + Object.keys(schema).forEach(fieldKey => { + const fieldSchema = schema[fieldKey] + if (fieldSchema?.type === "json") { + const jsonSchema = convertJSONSchemaToTableSchema(fieldSchema, { + squashObjects: true, + }) + Object.keys(jsonSchema).forEach(jsonKey => { + jsonAdditions[`${fieldKey}.${jsonKey}`] = { + type: jsonSchema[jsonKey].type, + nestedJSON: true, + } + }) + } + }) + schema = { ...schema, ...jsonAdditions } + // Ensure schema is in the correct structure let enrichedSchema = {} Object.entries(schema).forEach(([fieldName, fieldSchema]) => { @@ -275,24 +293,6 @@ export default class DataFetch { } }) - // Check for any JSON fields so we can add any top level properties - let jsonAdditions = {} - Object.keys(enrichedSchema).forEach(fieldKey => { - const fieldSchema = enrichedSchema[fieldKey] - if (fieldSchema?.type === "json") { - const jsonSchema = convertJSONSchemaToTableSchema(fieldSchema, { - squashObjects: true, - }) - Object.keys(jsonSchema).forEach(jsonKey => { - jsonAdditions[`${fieldKey}.${jsonKey}`] = { - type: jsonSchema[jsonKey].type, - nestedJSON: true, - } - }) - } - }) - enrichedSchema = { ...enrichedSchema, ...jsonAdditions } - return enrichedSchema }