How to increase number when converting json

I am trying to increase the version field. entrance

{"version":1}

      

The way out should be

{"v":2}

      

When i do

echo '{"version":1}'|jq '{"v":.version+1}'

      

I get

error: syntax error, unexpected '+', expecting '}'

      

When added to string interpolation works

echo '{"version":1}'|jq '{"v":"\(.version+1)"}'

      

gives

{
  "v":"2"
}

      

I need v to be of type number.

+3


source to share


2 answers


Try

echo '{"version":1}' | jq '{"v":(.version+1)}'

      



This works in the jq playground .

+3


source


I think you need to escape with "+" (plus) with "\ +" and see. How:



echo '{"version":1}'|jq '{"v":.version\+1}'

      

0


source







All Articles