Honestly I don’t know if anyone needs this, as most stuff can be done with simple processing of standard text anyway. I had a bit fun finding out how to convert the output format. If there is an easier way to do this, so be it. At least this was an exercise for me. So here it is.
#!/usr/bin/env bash
# Flatpak list output as JSON format
# Examples with jq:
# flatpak-list-json | jq -r '.[].name'
# flatpak-list-json | jq -r '.[0:2].[].application'
# flatpak-list-json | jq '.[0:2]'
# flatpak-list-json | jq '.[] | select(.description | contains("video"))'
columns='name,description,application,version,branch,branch,arch,runtime,origin,installation,ref,active,latest,size,options'
# Default show all flatpaks, use flatpak --app or --runtime option to limit type of package.
flatpak list --app --columns "${columns}" |
column \
--json \
--table-name 'flatpak' \
--table-columns "${columns}" \
--separator $'\t' \
--keep-empty-lines |
jq '.flatpak[0:]'
It simply outputs the flatpak list as a JSON data. This can be used with other software that processes JSON. A few examples are given using the standalone jq app. The script itself uses following commands: flatpak column jq.
You must log in or register to comment.


