jq Invalid numeric literal at EOF updating json value to 0.0.x

huangapple go评论57阅读模式
英文:

jq Invalid numeric literal at EOF updating json value to 0.0.x

问题

我试图按照以下方式更新我的 JSON 文件:

jq  .attributes.DeployVersion.default=0.0.1 block.json > t.tmp && mv t.tmp block.json

这会引发错误:

jq: error: Invalid numeric literal at EOF at line 1, column 5 (while parsing '0.0.0') at <top-level>, line 1:
.attributes.DeployVersion.default=0.0.1

而这个命令:

jq  .attributes.DeployVersion.default=0.1  block.json > t.tmp && mv t.tmp block.json

却可以正常工作(唯一的区别是我使用了 0.1 而不是 0.0.1)。尝试使用引号没有起作用。

英文:

i am trying to update my json file as following

jq  .attributes.DeployVersion.default=0.0.1 block.json &gt; t.tmp &amp;&amp; mv t.tmp block.json

which throws an error

jq: error: Invalid numeric literal at EOF at line 1, column 5 (while parsing &#39;0.0.0&#39;) at &lt;top-level&gt;, line 1:
.attributes.DeployVersion.default=0.0.1

while this:

jq  .attributes.DeployVersion.default=0.1  block.json &gt; t.tmp &amp;&amp; mv t.tmp block.json

works perfectly (the only difference is instead of 0.0.1 I use 0.1)

tried quotes, didnt work.

答案1

得分: 2

Quotes around both the version string and the whole expression:

jq -r '.attributes.DeployVersion.default="0.0.2"'

Or escape the quotes around the version string:

jq -r .attributes.deployVersion.default=\"0.0.2\"

You could also use tostring in a pipe, but it would be unnecessary.

英文:

Quotes around both the version string and the whole expression:

jq -r &#39;.attributes.DeployVersion.default=&quot;0.0.2&quot;&#39;

Or escape the quotes around the version string:

jq -r .attributes.deployVersion.default=\&quot;0.0.2\&quot;

You could also use tostring in a pipe, but it would be unnecessary.

huangapple
  • 本文由 发表于 2023年5月14日 22:55:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76248117.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定