2017-01-16 51 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