-
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_binary Here'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 |
Beta Was this translation helpful? Give feedback.
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_binary cat 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. |
Beta Was this translation helpful? Give feedback.
Sorry for the delayed response here.
I'm focusing on dasel v3 right now, and this is achievable with:
in.yaml
Output
V3 isn't officially released yet but you are able to install the development version.