# Gramps XML to JSONL file format

**URL:** <https://gramps.discourse.group/t/gramps-xml-to-jsonl-file-format/7349>\
**Category:** Beta Testing\
**Tags:** third-party-addon\
**Created:** [March 29, 2025, 11:20am UTC](https://gramps.discourse.group/t/gramps-xml-to-jsonl-file-format/7349 "2025-03-29T11:20:00Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![romjerome](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/romjerome/32/1489_2.png) [@romjerome](https://gramps.discourse.group/u/romjerome)\
**Post date:** [March 29, 2025, 11:40am UTC](https://gramps.discourse.group/t/gramps-xml-to-jsonl-file-format/7349/3 "2025-03-29T11:40:13Z")

</div>

… this proposal (AI script) needs some ‘human local’ adjustements (fix)… 😉

```python
import xml.etree.ElementTree as ET
import json

# Charger le fichier XML
with open('input.xml', 'r', encoding='utf-8') as file:
    xml_data = file.read()

# Analyser les données XML
root = ET.fromstring(xml_data)

# Extraire les événements et convertir en JSONL
jsonl_lines = []
for event in root.findall('.//{http://gramps-project.org/xml/1.7.2/}event'):
    type_elem = event.find('{http://gramps-project.org/xml/1.7.2/}type')
    dateval_elem = event.find('{http://gramps-project.org/xml/1.7.2/}dateval')
    place_elem = event.find('{http://gramps-project.org/xml/1.7.2/}place')
    description_elem = event.find('{http://gramps-project.org/xml/1.7.2/}description')

    event_data = {
        "handle": event.get('handle'),
        "change": event.get('change'),
        "id": event.get('id'),
        "type": type_elem.text if type_elem is not None else None,
        "dateval": dateval_elem.get('val') if dateval_elem is not None else None,
        "place": place_elem.get('hlink') if place_elem is not None else None,
        "description": description_elem.text if description_elem is not None else None
    }
    jsonl_lines.append(json.dumps(event_data))

# Joindre tous les objets JSON en une seule chaîne avec des séparateurs de nouvelle ligne
jsonl_output = "\n".join(jsonl_lines)

# Sauvegarder le résultat dans un fichier JSONL
with open('output.jsonl', 'w', encoding='utf-8') as file:
    file.write(jsonl_output)

print("Conversion terminée. Le fichier JSONL a été enregistré sous 'output.jsonl'.")

```

to be continued…

`1 validation error for FinetuningMessages messages Input should be a valid list [type=list_type, input_value={'handle': '_a5af0eb66701... Warner, Sarah Suzanne'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.9/v/list_type (line 1)`

this can take a while since… I find the [expected file format](https://docs.mistral.ai/capabilities/finetuning/#dataset-format)! Anyway, it is still unclear for me (see also [dataset](https://github.com/mistralai/mistral-finetune/tree/main?tab=readme-ov-file#prepare-dataset)).

* * *

> [@The Road Ahead for database representations](https://gramps.discourse.group/t/the-road-ahead-for-database-representations/6363/20):
>
> I would think so. This will be a simple dump to disk. On that topic, I would recommend that we use [JSONLines](https://jsonlines.org/) format (one JSON object per line)

Is there any “limit” for the number of characters before the “end of line” ( **CPL** ) on JSONL file format? 112 characters per line?

I am not certain of the “right” JSONL file format! So, I made some experimentations with a basic `custom XML file format`, after parsing the content of a `Gramps XML` file (`example.gramps`).

> <https://github.com/gramps-project/addons-source/pull/692>

 ![GUI_lxml_dialog](https://global.discourse-cdn.com/free1/uploads/gramps/original/2X/f/fef51ab10e0b668f572f07495bbe41e3caa4afc3.png)

> <https://github.com/romjeromealt/addons-source/pull/3>

The `custom XML file` is for the POC. Few lines for a very basic transformer/exporter (_new JSONL file generation and print into GtkTextBuffer on gramplet_). Anyway, I suppose that I should be able to generate more templates with this “old” method, but still active with few ressources and time process.

---

_[View the full topic](https://gramps.discourse.group/t/gramps-xml-to-jsonl-file-format/7349)._
