I have the following json
{
"version" : "0.1.2",
"basePath" : "/"
}
and the desired output is
{
"version" : "0.1.2",
"basePath" : "beta1"
}
I have the following jq which is producing the error below:
.basePath = .version | split(".") as $version | if $version[0] == "0" then "beta"+ $version[1] else $version[0] end
jq: error (at :3): split input and separator must be strings exit status 5
Using .basePath = .version assigns the value successfully and .version | split(".") as $version | if $version[0] == "0" then "beta"+ $version[1] else $version[0] end on its own returns "beta1". Is there a way to assign the string to the basePath key?
Good news! Your proposed solution is just missing a pair of parentheses. Also, there is no need for $version. That is, this will do it:
.basePath = (.version | split(".")
| if .[0] == "0" then "beta"+ .[1] else .[0] end)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With