# Copy/paste/create a separate person via JSON

**URL:** <https://gramps.discourse.group/t/copy-paste-create-a-separate-person-via-json/5995>\
**Category:** Ideas\
**Created:** [September 3, 2024, 6:32pm UTC](https://gramps.discourse.group/t/copy-paste-create-a-separate-person-via-json/5995 "2024-09-03T18:32:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Urchello](https://avatars.discourse-cdn.com/v4/letter/u/c4cdca/32.png) [@Urchello](https://gramps.discourse.group/u/Urchello)\
**Post date:** [September 3, 2024, 6:32pm UTC](https://gramps.discourse.group/t/copy-paste-create-a-separate-person-via-json/5995/1 "2024-09-03T18:32:57Z")

</div>

Maybe anybody is interesting to create such addon or core feature.

The feature allows copy and paste separate persons from one Gramps app (say on virtual machine) to another Gramps app (say on host machine). Or even do this inside one app.

I made a small test of the copy feature (the “Copy to Clipboard” button):

 ![Screenshot from 2024-09-03 21-20-27](https://global.discourse-cdn.com/free1/uploads/gramps/original/2X/4/4847d81cd2365ad15630bf72e83362224d4084d5.png)

It copies the next:

```python
{
    "gender": 1,
    "primary_name": {
        "given": "\u0421\u0435\u043c\u0435\u043d"
    },
    "alternative_names": {},
    "notes": {},
    "attributes": {},
    "events": {}
}

```

Then the clipboard text could be pasted into any input and save. And a new person with all necessary data will be created. Code fragment:

```python
   def _setup_fields(self):
        ...
        self.json_button = Gtk.Button(label="Copy to clipboard")
        self.top.get_object("vbox").pack_start(self.json_button, False, False, 0)
        self.json_button.connect("clicked", self._export_to_json)
    
   def _export_to_json(self, widget):
        # Gather person data
        primary_surname = self.pname.get_primary_surname()
        person_data = {
            "gender": self.obj.get_gender(),
            "primary_name": {
                "given": self.pname.get_first_name(),
            },
            "alternative_names": {},
            "notes": {},
            "attributes": {},
            "events": {},
        }

        # Convert to JSON
        json_data = json.dumps(person_data, indent=4)

        # Copy to clipboard
        clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
        clipboard.set_text(json_data, -1)
        clipboard.store()

        # Notify user
        dialog = Gtk.MessageDialog(
            transient_for=self.window,
            flags=0,
            message_type=Gtk.MessageType.INFO,
            buttons=Gtk.ButtonsType.OK,
            text="Person is copied",
        )
        dialog.format_secondary_text(
            "The current Person data has been copied to the clipboard."
        )
        dialog.run()
        dialog.destroy()

```

The code above demonstrates copying only, no paste.

```python
/usr/local/lib/python3.10/dist-packages/gramps/gui/editors$ sudo vi editperson.py

```

---

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [June 16, 2025, 9:25pm UTC](https://gramps.discourse.group/t/copy-paste-create-a-separate-person-via-json/5995/3 "2025-06-16T21:25:32Z")

</div>


