2015-11-24 111 views
4

我有短JQ過濾器下面這完美的作品:JQ不能索引字符串字符串「值」

cat data.tmp2 | ./jq-linux64-1.5 -r '.issues[].fields.customfield_10025 | if .value != null then (.value + "," + .child.value) else "" end' 

它產生正是我所需要的,如果該字段爲空,則返回「」如果該字段是不是空的,它使用字段的值並連接逗號和子值。 然而,當我將我的過濾器在下面看到一個更大的過濾器,我得到一個錯誤:無法索引字符串字符串「值」

這是較長的過濾器失敗:

cat data.tmp2 | ./jq-linux64-1.5 -r '.issues | map([.key,.fields.project.name,.fields.parent.key,.fields.issuetype.name,.fields.status.name,.fields.priority.name,.fields.resolution.name,.fields.assignee.name,.fields.reporter.name,.fields.created,.fields.updated,.fields.resolutiondate,.fields.summary,(.fields.components | (map(.name?) | join (","))),(.fields.fixVersions | (map(.name?) | join (","))),.fields.customfield_10025 | if .value != null then (.value + "," + .child.value) else "" end,.fields.customfield_10201] | join ("---")) 

回答

2

嘗試把周圍的括號表達式:

.fields.customfield_10025 | if .value != null then (.value + "," + .child.value) else "" end 

即,[1,2 | type]被解析爲[(1,2) | type],不[1, (2|type)]

+1

謝謝!就是這樣。在我發佈這個問題之前,我嘗試過在管道後面使用parantheses,但是沒有工作......但是這樣做的確有用。 –