gpt4 book ai didi

json - jq 读取内联字符串,而不是从标准输入

转载 作者:行者123 更新时间:2023-12-02 02:44:38 25 4
gpt4 key购买 nike

这可以从文件中读取:

jq '.c | fromjson | .id' my_file.json

这从标准输入读取:
echo "$my_json" | jq -r '.field'

如果我只想从这样的字符串中读取怎么办:
jq '.field' "$my_json"

怎么做?

最佳答案

$ jq -n '$in.foo' --argjson in '{"foo":"bar"}'
"bar"
$ jq -n '$foo' --arg foo 'bar'
"bar"
  • -n使用 null作为输入(而不是标准输入),
  • --argjson用于传递 JSON 实体(对象、数组、数字、字符串、 bool 值或 null)
  • --arg用于传递(shell)字符串。
  • 关于json - jq 读取内联字符串,而不是从标准输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56202911/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com