Skip to content

Instantly share code, notes, and snippets.

@sethc23
Created October 17, 2015 04:43
Show Gist options
  • Save sethc23/65ba1631484ec99ffa71 to your computer and use it in GitHub Desktop.
Save sethc23/65ba1631484ec99ffa71 to your computer and use it in GitHub Desktop.
jq example of one-liner for generating JSON
#!/bin/bash
printf 'With Color:\n\n'
echo \
'Producer: FOP 0.20.5
Tagged: no
UserProperties: no
Suspects: no
Form: none
JavaScript: no
Pages: 2
Encrypted: no
Page size: 648 x 857 pts
Page rot: 0
File size: 9894 bytes
Optimized: no
PDF version: 1.3' | \
jq -sRc 'splits("\n")? | split(":") as $i | { ($i[0]?) : ( $i[1] | sub("^(\\s)+"; ""; "x") ) }'
printf '\n\n\nWithout Color:\n\n'
echo \
'Producer: FOP 0.20.5
Tagged: no
UserProperties: no
Suspects: no
Form: none
JavaScript: no
Pages: 2
Encrypted: no
Page size: 648 x 857 pts
Page rot: 0
File size: 9894 bytes
Optimized: no
PDF version: 1.3' | \
jq -sRcM 'splits("\n")? | split(":") as $i | { ($i[0]?) : ( $i[1] | sub("^(\\s)+"; ""; "x") ) }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment