Skip to content

Instantly share code, notes, and snippets.

@arlina-espinoza
Created May 24, 2017 21:29
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save arlina-espinoza/f691385d9ff0f2d17da6af33a6505b5d to your computer and use it in GitHub Desktop.
Save arlina-espinoza/f691385d9ff0f2d17da6af33a6505b5d to your computer and use it in GitHub Desktop.
Bash script to split a JSON into multiple files. Uses jq.
#!/bin/bash
# Split a JSON into multiple files. Uses jq.
# Usage
# ./split_json.sh /path/to/json/file
file="$1"
jq -cr 'keys[] as $k | "\($k)\t\(.[$k])"' "$file" | awk -F\\t '{ file=$1".json"; print $2 > file; close(file); }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment