Skip to content

Instantly share code, notes, and snippets.

@rokibhasansagar
Forked from arlina-espinoza/split_json.sh
Created May 4, 2023 13:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rokibhasansagar/a8ec012edb306a3b3f441a0132c31412 to your computer and use it in GitHub Desktop.
Save rokibhasansagar/a8ec012edb306a3b3f441a0132c31412 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