Import/Export CLI Utilities

This article explains a handful of export CLI utilities that can help you manage exported content.

This guide is intended for Unix-based OS. The scripts provided will not work on a Windows terminal.

Isolate JSON export files for a specific custom type

To isolate documents for a specific Custom Type, follow these steps:

Unzip the Export archive.

Create a folder inside of the unzipped export:

mkdir page

Run this command in the export folder:

mv `grep -lir '"type":"page"' ./*` ./page

In this example, all files containing the string "type": "page" will be moved to the /page folder.

Rename the JSON files in the Export archive

The Export tool generates a ZIP archive that contains a JSON file for each document published in Prismic. Some users would like to have a human-readable filename to ease their workflow. You can rename JSON files according to any data contained in the document (like its UID or its title).

For this script to work, you need to globally install the npm package json, a CLI tool to work with JSON:

npm install -g json

In this example, we will go through rename the JSON files with the value of the "uid" field.

Create a file called script_rename.sh in the folder where you want to rename JSON files and paste in this script:

#!/bin/bash
filetype=".json"
for filename in ./*.json; do
    newname=$(json -f $filename uid)
   mv "$filename" "$newname$filetype"
done

In your terminal, navigate to the folder. Run this code to allow execution of your new script

chmod +x script_rename.sh

Then run the script:

./script_rename.sh

You can replace uid with any field key you'd like to use to rename the file.

Isolate JSON export files for a specific locale

To isolate documents for a specific locale, follow these steps:

Unzip the Export archive.

Create a folder for a specific locale (i.e., en-us) inside of the unzipped export:

mkdir en-us

Run this command in the export folder:

mv `grep -lir '"lang":"en-us"' ./*` ./en-us

In this example, all documents in the en-us locale will be moved to the ./en-us directory