# Turtl to MD directory \[python\]

**URL:** <https://discourse.joplinapp.org/t/turtl-to-md-directory-python/29010>\
**Category:** Apps\
**Created:** [7 January 2023 21:12 UTC](https://discourse.joplinapp.org/t/turtl-to-md-directory-python/29010 "2023-01-07T21:12:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![krystalwolf](https://avatars.discourse-cdn.com/v4/letter/k/43a26b/32.png) [@krystalwolf](https://discourse.joplinapp.org/u/krystalwolf)\
**Post date:** [7 January 2023 21:12 UTC](https://discourse.joplinapp.org/t/turtl-to-md-directory-python/29010/1 "2023-01-07T21:12:43Z")

</div>

Turtl's output JSON is a bit annoying, so here's a basic script to transfer **text** and **password** notes (only) to a markdown directory.  
It's very limited in features since I only built it for personal use.  
Place your output JSON (called `turtl-backup.json`) in the same folder, and create a folder called `turtl`.

NB: it ignores boards, users, and creation dates, and only copies notes that are in text or password form

I would upload the python file but discourse doesn't seem to like me doing that, so here's the source code in plain text. Yes it's not as efficient as it can be but it only has to work once.

```auto
import json, os
OUTPUT = "turtl/"

if OUTPUT != "" and OUTPUT[-1] != "/":
    OUTPUT += "/"

def createUnnamedFile(board="", num=0):
    try:
        f = open(OUTPUT + board + f"Untitled-{num}.md", "x")
        f.close()
        return "Untitled-%i" % num
    except FileExistsError:
        return createUnnamedFile(board, num + 1)

with open("turtl-backup.json") as f:
    data = json.load(f)

boards = {}
for b in data["boards"]:
    boards[b["id"]] = str(b["title"])
    try:
        os.mkdir(OUTPUT + b["title"])
    except FileExistsError:
        print("board directory already exists")

for n in data["notes"]:
    outdir = ""
    if n["board_id"] != None:
        try:
            outdir = boards[n["board_id"]] + "/"
        except KeyError:
            print("board not found")
            print("board id:", n["board_id"])
    
    if n["title"] == "":
        name = createUnnamedFile(outdir) + ".md"
    else:
        name = n["title"].strip() + ".md"
    
    outData = []
    if n["type"] == "text":
        outData = [n["text"]]
    elif n["type"] == "password":
        outData = [n["password"]]
    #print(len(outData))
    with open(f"{OUTPUT}{outdir}{name}", "w") as f:
        f.writelines(outData)

```

---

<div class="post-metadata">

**Author:** ![krystalwolf](https://avatars.discourse-cdn.com/v4/letter/k/43a26b/32.png) [@krystalwolf](https://discourse.joplinapp.org/u/krystalwolf)\
**Post date:** [7 January 2023 21:18 UTC](https://discourse.joplinapp.org/t/turtl-to-md-directory-python/29010/2 "2023-01-07T21:18:23Z")

</div>

I doubt many people will have a use for this as a lot of users moved away from Turtl after it kinda stopped being maintained in 2019, but if any future people have a need for this I hope it is helpful. I know someone else on here gave a PHP version, but not a lot of people can easily run PHP so I figured this was still worth posting.  
If this has errors or bugs, that's tough luck because I forgot to save the password when I made this account 😛

---

<div class="post-metadata">

**Author:** ![Daeraxa](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/daeraxa/32/6172_2.png) [@Daeraxa](https://discourse.joplinapp.org/u/Daeraxa)\
**Post date:** [8 January 2023 00:16 UTC](https://discourse.joplinapp.org/t/turtl-to-md-directory-python/29010/3 "2023-01-08T00:16:05Z")

</div>

Thanks for posting it, I've added it to [Importing notes from other notebook applications](https://discourse.joplinapp.org/t/importing-notes-from-other-notebook-applications/22425)
