|
Hi! I am trying to exclusively use dasel to read a yaml file but I sadly had to convert the yaml to json and process it with jq as I haven't found a way to do it in dasel V2. Here's part of a bigger yaml, with only the relevant part: installation:
methods:
- method: gitea_deb_package
os: [debian, ubuntu]
- method: gitea_arch_package
os: [arch]
- method: gitea_release_binaryHere's the command I'm using to read the installation methods list: metadata_yml=$(cat << 'EOF'
installation:
methods:
- method: gitea_deb_package
os: [debian, ubuntu]
- method: gitea_arch_package
os: [arch]
- method: gitea_release_binary
EOF
)
os_id="ubuntu"
compatible_methods_json=$(echo "$metadata_yml" | dasel -r yaml -w json '.installation.methods' | jq -c --arg os "$os_id" '[.[] | select( (.os // ["any"]) | any(. == $os or . == "any") )]')
echo "$compatible_methods_json"Result of [
{
"method": "gitea_deb_package",
"os": [
"debian",
"ubuntu"
]
},
{
"method": "gitea_arch_package",
"os": [
"arch"
]
},
{
"method": "gitea_release_binary"
}
]Output/content of compatible_methods_json (formatted for easy read): [
{
"method":"gitea_deb_package",
"os":[
"debian",
"ubuntu"
]
},
{
"method":"gitea_release_binary"
}
]Is it possible to do it all in a |
Answered by
TomWright
Aug 26, 2025
Replies: 1 comment
|
Sorry for the delayed response here. in.yaml installation:
methods:
- method: gitea_deb_package
os: [debian, ubuntu]
- method: gitea_arch_package
os: [arch]
- method: gitea_release_binarycat in.yaml |
OSID=ubuntu dasel -i yaml -o json 'installation.methods.filter($this.os.contains($OSID) ?? true)'Output [
{
"method": "gitea_deb_package",
"os": [
"debian",
"ubuntu"
]
},
{
"method": "gitea_release_binary"
}
]V3 isn't officially released yet but you are able to install the development version. |
0 replies
Answer selected by
stecydube
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry for the delayed response here.
I'm focusing on dasel v3 right now, and this is achievable with:
in.yaml
Output
[ { "method": "gitea_deb_package", "os": [ "debian", "ubuntu" ] }, { "method": "gitea_release_binary" } ]V3 isn't officially released yet but you are able to install the development version.