Skip to content

Instantly share code, notes, and snippets.

@orangecms
Created July 15, 2017 08:03
Show Gist options
  • Save orangecms/0708dab280245bd4473500ca0c2c0914 to your computer and use it in GitHub Desktop.
Save orangecms/0708dab280245bd4473500ca0c2c0914 to your computer and use it in GitHub Desktop.
Convert xlsx spreadsheets to JSON :)
#!/bin/bash
# Preconditions:
# Before using this script, you need to have additional tools. Preferably, use
# your system package manager to install `csv2json`, `jsonlint` and `xslx2csv`.
# Alternatively, if you have `node`, `npm`, `python` and `pip`, run
# `npm i -g csv2json jsonlint && pip install xlsx2csv` for the unclean way.
# WARNING: You may have to adjust your `$PATH` then and you will need to track
# updates yourself. Do this at your own risk only.
# Usage:
# Simply make this script executable (`chmod +x ./xlsx2json.sh`) and run it
# with an xlsx file as an argument. You probably want to redirect the output to
# a new file or pipe it into a pager of your choice. Examples:
# ./xlsx2json.sh foo.xlsx > foo.json
# ./xlsx2json.sh foo.xlsx | less
if [ $# -eq 0 ]
then
echo "Missing filename"
exit 1
fi
if [ ! -f "$1" ]
then
echo "File does not exist"
exit 1
fi
xlsx2csv "$1" | csv2json | jsonlint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment