Load GEDCOM Data in Family Tree JS 2
Code example: Load GEDCOM Data in Family Tree JS 2
Family Tree JS 2 supports importing GEDCOM files directly into your family tree using the FamilyTree2.convertGedcomToFamilyMembers() method.
javascript
FamilyTree2.convertGedcomToFamilyMembers(text, fieldBinding)Parameters:
text: The raw GEDCOM file content as a string.fieldBinding: Maps GEDCOM tag names to your family tree node property names.
Example mapping:
javascript
{
NAME: 'name', // GEDCOM "NAME" -> node.name
BIRT_DATE: 'dateOfBirth' // GEDCOM "1 BIRT 2 DATE" -> node.dateOfBirth
}Workflow
- Open a GEDCOM file: Use the File System Access API with
showOpenFilePicker()to let the user choose a.gedfile, then read its content as text. - Convert to Family Members: Pass the GEDCOM text and your field mapping into
convertGedcomToFamilyMembers(). - Display in Family Tree: Use
addFamilyMembers()anddraw()to render the tree.