then it would be best to use it in conjunction with the -n command-line option and the following jq filter:
$ echo '{ "format_id": "250" }{ "format_id": "18" }{ "format_id": "140" }{ "format_id": "18" }{ "format_id": "244" }' | jq .
{
"format_id": "250"
}
{
"format_id": "18"
}
{
"format_id": "140"
}
{
"format_id": "18"
}
{
"format_id": "244"
}
If your jq does not have format_id
... then you'd have to use the -s command-line option, e.g. with the following filter:
$ echo '{ "format_id": "250" }{ "format_id": "18" }{ "format_id": "140" }{ "format_id": "18" }{ "format_id": "244" }' | jq -r 'select(.format_id=="18")'
{
"format_id": "18"
}
{
"format_id": "18"
}
Here, using format_id
is preferable as it requires less RAM.
我有以下json。我设法提取了
$ echo '{ "format_id": "18" }{ "format_id": "18" }' | jq '[.[]|select(.format_id)][0]'
jq: error (at <stdin>:1): Cannot index string with string "format_id"
jq: error (at <stdin>:1): Cannot index string with string "format_id"
$ echo '{ "format_id": "18" }{ "format_id": "18" }' | jq '( map(select(.format_id)) | first )'
jq: error (at <stdin>:1): Cannot index string with string "format_id"
jq: error (at <stdin>:1): Cannot index string with string "format_id"
$ echo '{ "format_id": "18" }{ "format_id": "18" }' | jq '( first(.[] | select(.format_id)) )'
jq: error (at <stdin>:1): Cannot index string with string "format_id"
jq: error (at <stdin>:1): Cannot index string with string "format_id"
$ echo '{ "format_id": "18" }{ "format_id": "18" }' | jq 'map(select(.format_id))|.[0]'
jq: error (at <stdin>:1): Cannot index string with string "format_id"
jq: error (at <stdin>:1): Cannot index string with string "format_id"
的第1次出现,它等于 "18"。
我想从中提取第1次出现的此处inputs
但他们都没有工作,因为我想他们需要以某种方式适应我的输入数据。
first(inputs | select(.format_id =="18"))
inputs
first(.[] | select(.format_id =="18"))
inputs
我有以下json:$ echo '{ "format_id": "250" }{ "format_id": "18" }{ "format_id": "140" }{ "format_id": "18" }{ "format_id": "244" }'