CRITICAL-JSON-STRUCTURE-FIX.md•3.24 kB
# CRITICAL: Fix Composition JSON Structure
**Task ID**: CRITICAL-JSON-STRUCTURE-FIX-001
**Status**: URGENT EXECUTION REQUIRED
**Priority**: CRITICAL
**Owner**: Claude Code
**Created**: 2025-07-03 20:40 EST
**Dependencies**: Manual composition JSON structure identified
---
## 🎯 **ROOT CAUSE CONFIRMED**
**Manual composition JSON structure** vs **Our automation structure**:
### **✅ CORRECT (Manual)**
```json
{
"version": "1.1",
"metadata": {
"title": "Actual Title Here",
"description": "",
"thumb": null,
"tags": []
},
"interface": {
"content_language": "pt_br",
"index_option": "buttons",
"font_family": "Lato",
"show_summary": "disabled",
"finish_btn": "disabled"
},
"structure": [
{
"id": "6fe34380-57fe-11f0-9c4d-4300d65c62e7",
"type": "head-1",
// ... element properties
}
],
"assets": []
}
```
### **❌ WRONG (Our Automation)**
```json
{
"composition": {
"id": "composition-123",
"title": "Title",
"elements": [
{
"id": "head-1",
"type": "head-1"
}
]
}
}
```
## 🛠️ **REQUIRED CHANGES**
### **1. Fix Root Structure**
```javascript
// CHANGE FROM:
const compositionData = {
composition: { ... }
};
// CHANGE TO:
const compositionData = {
version: "1.1",
metadata: {
title: extractedTitle, // THIS FIXES "Sem título"
description: "",
thumb: null,
tags: []
},
interface: {
content_language: "pt_br",
index_option: "buttons",
font_family: "Lato",
show_summary: "disabled",
finish_btn: "disabled"
},
structure: elementsArray, // RENAME FROM "elements"
assets: []
};
```
### **2. Fix Element IDs**
```javascript
// CHANGE FROM:
{
"id": "head-1",
"type": "head-1"
}
// CHANGE TO:
{
"id": generateUUID(), // e.g. "6fe34380-57fe-11f0-9c4d-4300d65c62e7"
"type": "head-1"
}
// Add UUID generation function:
function generateUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
const r = Math.random() * 16 | 0;
const v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
```
### **3. Fix Element Properties**
Based on manual composition, ensure elements have:
- ✅ **Proper UUID IDs**
- ✅ **All required properties** (padding_top, padding_bottom, etc.)
- ✅ **Correct property names** (no extra nesting)
### **4. Update Function Name**
```javascript
// IN generateEnhancedComposition():
return {
version: "1.1",
metadata: {
title: title, // CRITICAL: This will fix "Sem título"
// ...
},
// ... rest of structure
};
```
## ✅ **SUCCESS CRITERIA**
1. **Compositions save with correct titles** (not "Sem título")
2. **Elements render visibly** in Composer interface
3. **Interactive elements work** (flashcards, quiz, etc.)
4. **No API interception needed** (normal Composer flow works)
## 🚀 **EXPECTED OUTCOME**
Once JSON structure is corrected:
- ✅ Compositions will have proper titles
- ✅ Content will render immediately
- ✅ All elements will be interactive
- ✅ Manual navigation will work
- ✅ No visualization issues
---
**This is the actual fix needed - correct the JSON structure to match Composer's format!**