Skip to content

Instantly share code, notes, and snippets.

@Loupax
Last active March 29, 2021 08:04
Show Gist options
  • Save Loupax/4f3aeda1eb31187b446d4399941092d3 to your computer and use it in GitHub Desktop.
Save Loupax/4f3aeda1eb31187b446d4399941092d3 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Dependencies: xargs, jq
#
# Example usages:
# fsToJson file file2 file2
# fsToJson $(ls file*)
# will generate something like
# {
# "file": "file contents",
# "file2": "file2 contents",
# "file3": "file2 contents"
# }
function files_to_json(){
printf '%s\n' "$@" |
xargs -L 1 -I {} jq -sR --arg key {} '{ ($key): .}' {} | jq -s 'add'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment