Skip to content

Instantly share code, notes, and snippets.

@evansd
Created June 24, 2019 15:41
Show Gist options
  • Select an option

  • Save evansd/55ad36f35c13fccfcd2e506e0c123730 to your computer and use it in GitHub Desktop.

Select an option

Save evansd/55ad36f35c13fccfcd2e506e0c123730 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Converts JSON into a flat, line-by-line format
# Equivalent to https://github.com/soheilpro/catj
# Borrowed from this HN comment: https://news.ycombinator.com/item?id=20246957
exec jq -r '
tostream
| select(length > 1)
| (
.[0] | map(
if type == "number"
then "[" + tostring + "]"
else "." + .
end
) | join("")
) + " = " + (.[1] | @json)
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment