2017-01-16 44 views
0

我有以下的JSON數據使用JQ用支架取一個值

"cumulativeStatistics": [ 
     { 
     "Mean_Test_Time_(ms)": 481.6876712328767, 
     "Response_bytes_per_second": 10514.456156404525, 
     "Errors": 0.0, 
     "testNumber": 1.0, 
     "TPS": 2.141001049970378, 
     "testDescription": "Some status", 
     "Mean_time_to_first_byte": 481.1034246575342, 
     "Tests": 1460.0, 
     "Peak_TPS": 4.0 
     }, 
     { 
     "Mean_Test_Time_(ms)": 453.88211103495547, 
     "Response_bytes_per_second": 10507.254474105619, 
     "Errors": 0.0, 
     "testNumber": 2.0, 
     "TPS": 2.1395346108950557, 
     "testDescription": "Status Again", 
     "Mean_time_to_first_byte": 453.4825222755312, 
     "Tests": 1459.0, 
     "Peak_TPS": 4.0 
     } 

我用下面的JQ這是能夠走出除了Mean_Test_Time_(MS)所有其它參數,因爲括號

cat sample.data | jq '.perf.cumulativeStatistics[0].Response_bytes_per_second' 

這是解釋括號本身。因此,當我使用Mean_Test_time_(ms)與該命令時,出現以下錯誤

error: syntax error, unexpected '(', expecting $end 
.perf.cumulativeStatistics[0].Mean_Test_Time_(ms) 

如何避免這些錯誤?

謝謝!

回答

1

像在Javascript中,你可以用括號來訪問這些「問題」的屬性名稱,像這樣:

jq '.perf.cumulativeStatistics[0]["Mean_Test_Time_(ms)"]' sample.data