The Importer

Ghost imports from existing blogs via a custom JSON data format, which is described below. The import and export tools can be found on the 'labs' page in Ghost settings. The importer will accept a JSON file, markdown file, an image, or a zip file containing a combination of either JSON or markdown files along with accompanying images.

Existing Plugins

Official

Non-official

  • WordPress users can also use the wp2ghost command-line tool to convert their WordPress export files to Ghost-compatible JSON.
  • Jekyll users can use the Jekyll to Ghost Plugin
  • Blogger users can try blogger2ghost. Also available as a web service.
  • Open-source geeks may consider importing READMEs from all of their Github repositories as regular posts using gh2ost tool.
  • Tumblr users can use Tumblr to Ghost

Importing the JSON

Once you've generated the JSON go to the Labs Menu (/ghost/settings/labs/) on your blog to access the import form.

Rolling your own

If no export tools exist for your current blogging system you'll need to create one that generates a JSON file as described here. There is a full example at the end of this file. Please note that your final JSON file should have no comments in the final format. Those are only included here for readability and explanatory purposes.

JSON file structure

First and foremost, your JSON file must contain valid JSON. You can test your file is valid using the JSONLint online tool.

The file structure can optionally be wrapped in:

{
  "db": [...contents here...]
}

Both with and without are valid Ghost JSON files. But you must include a meta and a data object.

IDs inside the file are usually relative to the file only, so if you have a post with id: 1 and a posts_tags object which references post_id: 1, then those two things will be linked, but they do not relate to the post with id: 1 in your database.

The meta object

"meta": {
    "exported_on":1408552443891,
    "version":"003"
}

The meta block expects two keys, exported_on and version. exported_on should be an epoch timestamp in milliseconds, version should be the data version the import is valid for. Currently Ghost is on data version 003, see version info for more details.

The data block

"data": { 
  "posts": [{...}, ...], 
  "tags": [], 
  "posts_tags": [], 
  "users": [], 
  "roles_users": []
}

The data block contains all of the posts, tags, and users that you want to import into your blog, as well as relationships between posts and tags and users and roles. Each item that you include should be an array of objects.

Users

With 0.5 comes the ability to import multiple users into your blog. Any user in the file who has an email address which matches the email address of a user already in your database will be ignored. Any user with a new email address will be imported and their account set to locked so that they must reset their password to login.

Linking objects to users

If you want to link your posts, tags, etc to the user they were authored/created/published by you can do so by specifying a user id relative to a user's id in the import file. So, if you have a user with id: 2 in your file, and a post with author_id: 2 that post will be set to be authored by that user.

All new users (i.e. users with email addresses that aren't yet present in the db) are imported first. Then the importer matches the ids from created_by, author_id etc with users in the users: [] object, and finally maps them to the right user in the database via their email address. Therefore if you want to link objects to a user that is already in the database you can specify the bare minimum information for that user so that it can be mapped correctly:

"users": [{
   id: 3,
   name: "A User",
   email: "user@example.com"
}]

Note: there is a special case for user ids. Any reference to a user with id: 1, i.e. created_by: 1 or author_id: 1 where there is no user with that id in the import file, will be assumed to refer to the user who has the owner role.

User Roles

All users are given the role of author by default. If you want to specify different roles, you can do so by providing a roles_users object, much like the posts_tags object. Please note that Ghost doesn't yet support importing roles, so in this case the role_id is always relative to the id in the database, rather than in the file. This will change to match the other objects in the near future.

{
    "meta":{
        // epoch time in milliseconds
        "exported_on":  1388805572000,
        // Data version, current is 003
        "version":      "003"

    },
    "data":{
        "posts": [
            {
                "id":5,
                "title":        "my blog post title",
                "slug":         "my-blog-post-title",
                "markdown":     "the *markdown* formatted post body",
                "html":         "the <i>html</i> formatted post body",
                "image":        null,
                "featured":     0, // boolean indicating featured status
                "page":         0, // boolean indicating if this is a page or post
                "status":       "published", // or draft
                "language":     "en_US",
                "meta_title":   null,
                "meta_description":null,
                "author_id":    1, // the first user created has an id of 1
                "created_at":   1283780649000, // epoch time in millis
                "created_by":   1, // the first user created has an id of 1
                "updated_at":   1286958624000, // epoch time in millis
                "updated_by":   1, // the first user created has an id of 1
                "published_at": 1283780649000, // epoch time in millis
                "published_by": 1 // the first user created has an id of 1
            }
        ],
        "tags": [
            {
                "id":           3,
                "name":         "Colorado Ho!",
                "slug":         "colorado-ho",
                "description":  ""
            },
            {
                "id":           4,
                "name":         "blue",
                "slug":         "blue",
                "description":  ""
            }
        ],
        "posts_tags": [
            {"tag_id":3, "post_id":5},
            {"tag_id":3, "post_id":2},
            {"tag_id":4, "post_id":24}
        ],
        "users": [
            {
                "id":           2,
                "name":         "user's name",
                "slug":         "users-name",
                "email":        "user@example.com",
                "image":        null,
                "cover":        null,
                "bio":          null,
                "website":      null,
                "location":     null,
                "accessibility": null,
                "status":       "active",
                "language":     "en_US",
                "meta_title":   null,
                "meta_description": null,
                "last_login":   null,
                "created_at":   1283780649000, // epoch time in millis
                "created_by":   1, // the first user created has an id of 1
                "updated_at":   1286958624000, // epoch time in millis
                "updated_by":   1 // the first user created has an id of 1
            }
        ],
        "roles_users": [
            {
                "user_id": 2,
                "role_id": 3   
            }
        ]
    }
}

Importing Images

Ghost can import images which match any of the formats accepted by the API. Multiple images can be imported with a zip file.
When uploading a zip which includes both images and a JSON or markdown file, the relative path to the images from the JSON should match any relative path used inside the JSON/markdown data. Ghost will then attempt to update the image paths in the content of the JSON/markdown such that they will continue to work after importing.

E.g. If your JSON or markdown contains an image path like /images/my-image.jpg then ensure there is a directory called images inside the zip file, next to the JSON/markdown files, which contains your my-image.jpg file, and the import should keep images in tact.

Importing Markdown

Ghost can import markdown files and convert them into posts. Ghost expects the markdown files to have a name like:

status-year-month-day-slug.markdown

E.g.

published-2015-04-01-april-fools.markdown

If the post is published, the date provided will be used as the publish date. The slug will be used as the URL for the post.

The content of the file will be used as the content of the post, with the following special rules:

  • If the first thing in the post is markdown for an image (e.g. ![](my/image/url.jpg), this will be used as the posts cover image.
  • If the first thing in the post, or the second thing after an image, is a level 1 heading (e.g. # My heading) this will be used as the posts title (falls back to the slug).

Images can be imported with markdown files by including them together inside a zip file and ensuring the relative paths matched, as explained above.

You can import multiple markdown files inside a single zip.

Troubleshooting Ghost Imports

The Ghost importer takes a JSON file to import data. It has been improved to make it far more robust and provide greater information about the status of your import.

There are a number of ways in which an import file may trigger an Error or a Warning particularly if the the JSON file was not created by Ghost but by a third-party tool.

Error

When Ghost detects an error, the import will be cancelled, no information is imported and there should be a suitable error message to help you debug the problem. This also means there may be multiple errors in your import file but you will only see a single error during the import process.

An Error or warning should contain a relevant message on why the import was not successful along with a the relevant JSON entry that caused the issue where applicable.

An example of an error would be a JSON file that contains a null email field.

Example:

Import Error

Import Error

Warning

Your blog may contain multiple warnings. These are issues that may want to know about but are not significant enough to prevent the data being imported. Examples of this include a duplicate user (either duplicated in your JSON file or matching an existing user) or a post linked to an unknown user.

Example:

Import Warning

Import Warning

The Importer