2017-10-30 16 views
1

警告:jq:エラー:文字列を反復処理できません。

入力ファイルがある:

{ 
"env": "DC", 
"hosts" : 
[ 
{ 
    "apt_update_last_success": "1495991703", 
    "architecture": "amd64", 
    "hostname": "h1" 
}, 
{ 
    "apt_update_last_success": "1495991703", 
    "architecture": "amd64", 
    "hostname": "h2" 
}, 
{ 
    "apt_update_last_success": "1496045706", 
    "architecture": "amd64", 
    "hostname": "h3" 
}, 
{ 
    "apt_update_last_success": "1496045705", 
    "architecture": "amd64", 
    "hostname": "h4" 
}, 
{ 
    "apt_update_last_success": "1496049305", 
    "architecture": "amd64", 
    "hostname": "h5" 
}, 
{ 
    "apt_update_last_success": "1496049307", 
    "architecture": "amd64", 
    "hostname": "h6" 
} 
] 
} 

JQコマンドが期待したものを返すだけでなく、私はなぜ知らない警告を表示:

$ jq -r '.[][] | select(.hostname=="h6")' ddd.json 
jq: error: Cannot iterate over string 
{ 
    "apt_update_last_success": "1496049307", 
    "architecture": "amd64", 
    "hostname": "h6" 
} 

この取り除く方法を教えてください。

ありがとうございました。

答えて

0

問題はあなたの表記である.[][]です。あなたの入力はオブジェクトですが、 "容器"の "容器"として提示しようとしています.[][]

正しい方法は次のとおりです。ほかに

jq '.hosts[] | select(.hostname=="h6")' ddd.json 
{ 
    "apt_update_last_success": "1496049307", 
    "architecture": "amd64", 
    "hostname": "h6" 
} 

JQ1.5このjq -r '.[][] | select(.hostname=="h6")' ddd.jsonに慎重に「、期待されるオブジェクトを返すだけ jq: error (at jq1:36): Cannot iterate over string ("DC")

+0

@peakを印刷していません"この例では"頑強 "という意味ではありません – RomanPerekhrest

+0

@peak、あなたは私の更新があります – RomanPerekhrest

関連する問題