Skip to content

MAR-GUEZ/JSON-to-WXR-Converter--Migrate-Posts-from-Ghost-to-WordPress-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

JSON-to-WXR Converter

This script can receive a JSON file from the Ghost Blog service and convert it to a WordPress XML (WXR) file, ready for import into WordPress.

Overview

Ghost provides export files in JSON format, typically containing posts, authors, and other data. WordPress, on the other hand, imports data via WXR (WordPress eXtended RSS) files. This script bridges that gap, taking a Ghost JSON export (with minor structural adjustments as needed) and producing a WXR that WordPress can read via Tools → Import.

Requirements

Python 3.6+ (Confirmed to work with Python 3.9+) A JSON export file from Ghost or a similar structure that matches the script's expectations: Typically, your JSON might have an object with "db" (an array) → [ { "data": { "posts": [], "posts_authors": [] } } ].

Usage

  1. Place Your Files Put the Python script (e.g., json_wp.py) in a folder. In the same folder, place your Ghost JSON export file (commonly named lp-data.json or similar).
  2. Inspect / Adjust the Script If Needed Confirm the script points to the correct JSON structure. If your Ghost export has a slightly different layout, update where it reads db_obj.get('data', {}).get('posts', []) or posts_authors so it matches your file. If you don't see any authors or you have multiple authors per post, you can tweak how the script assigns dc:creator or wp:author.
  3. Install Any Dependencies (Optional)
  • If you're on a standard Python installation, this script should work with no extra libraries.
  • If using a virtual environment:
python3 -m venv venv
source venv/bin/activate
  1. Run the Script From your terminal (Mac/Linux) or command prompt (Windows), navigate to the folder with json_wp.py and run:
python3 json_wp.py
  • By default, it reads lp-data.json and outputs wp-export.xml. If you want different filenames, you can edit the last lines:
if __name__ == "__main__":
    input_json = "my-ghost.json"
    output_wxr = "my-wordpress.xml"
    generate_wordpress_wxr(input_json, output_wxr)
  1. Check the Output You should see a wp-export.xml (or your chosen output name) in the same folder. Open it in a text editor or browser to confirm and entries look right.
  2. Import into WordPress Go to WordPress Admin → Tools → Import. Install the WordPress importer if you haven't already. Choose the generated wp-export.xml. Follow the prompts to map or create new authors, then complete the import.

Troubleshooting

  1. No Posts Found Double-check your JSON structure. If the script prints No posts found, it means the path to "posts" is different than expected. Adjust the code where it does posts_data = db_obj.get('data', {}).get('posts', []) to match your JSON's path.
  2. Author Mapping Issues If your JSON doesn't have a posts_authors array, remove or adjust the section that expects authors. If you do have authors but they don't appear in the WordPress import tool, ensure wp:author entries are added to the and the dc:creator for each post references a valid author "login" (often the slug or username).
  3. HTML Content is Escaped If your post content is showing as < and > after import, remove extra wrapping in the script. Simply do:
content_el.text = post.get('html', '')

WordPress importer typically handles HTML correctly when placed directly as text within content:encoded.

Extending the Script

  • Categories/Tags: If you want categories or tags imported, add or lines inside each .
  • Dates: If your JSON has original publication dates, replace:
post_date_el.text = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

with the correct field from your JSON.

  • Images & Media: If you have images, you can create entries for attachments, though it requires a bit more advanced WXR format. License

Feel free to use, modify, or redistribute. This script is meant as a starter example for migrating Ghost JSON data to WordPress WXR—customization is often necessary to match exact fields and structures.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages