Skip to content

Instantly share code, notes, and snippets.

@Aerex
Last active September 29, 2025 15:33
Show Gist options
  • Save Aerex/01499c66f6b36a5d997f97ca1b0ab5b1 to your computer and use it in GitHub Desktop.
Save Aerex/01499c66f6b36a5d997f97ca1b0ab5b1 to your computer and use it in GitHub Desktop.
Import wallabag json file into a shiori instance.
#!/bin/bash
help() {
cat <<HELP
wallbag2shiori [options] <JSON_FILE>
Import wallabag json file into shiori instance.
-h Print the help menu
-v Enable verbose mode
HELP
exit;
}
while getopts :hv arg; do
case "$arg" in
h)
help
;;
v)
set -x
;;
?)
echo "ERROR: Unknown option $OPTARG"
exit 2
;;
esac
done
# Get file path from arg
shift $((OPTIND - 1))
FILE=$1
if [ -z $FILE ]; then
help
fi
if [ ! -f $FILE ]; then
echo "ERROR: Cannot find $FILE to import"
exit 2
fi
if [[ $FILE != *.json* ]]; then
echo "ERROR: $FILE must be a json file"
exit 2
fi
while IFS= read -r wall; do
title=$(echo $wall | jq -r '.title')
url=$(echo $wall | jq -r '.url')
num_tags=$(echo $wall | jq '.tags | length')
if [[ $num_tags != 0 ]]; then
tags=$(echo $wall | jq -r '.tags | tostring' | tr -d '\[\]' | tr -d '"')
shiori add "$url" -i "$title" -t $tags
else
shiori add "$url" -i "$title"
fi
done < <(jq -c '. | reverse | .[]' < $FILE)
@appel
Copy link

appel commented Sep 29, 2025

Hey there, thanks for posting this! One thing I've noticed it that it by starting at the top it imports recent bookmarks first. This means that your oldest bookmarks will be shown first. You can fix this by reversing the order of the json file (last line):

done < <(jq -c '. | reverse | .[]' < $FILE)

@Aerex
Copy link
Author

Aerex commented Sep 29, 2025

@appel Thanks for the tip. Updated.

@appel
Copy link

appel commented Sep 29, 2025

Sure thing, thanks again for publishing this gist, I appreciate it.

@Aerex
Copy link
Author

Aerex commented Sep 29, 2025

No problem and thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment