我的json内容存储在一个文件中:
{
"vms": [
{
"component": "pgdb",
"count": "1",
"endpoints": "80:8080,5432:5432"
},
{
"component": "mq",
"count": "1",
"endpoints": "80:8080,5672:5672,15672:15672"
},
{
"component": "ucms",
"count": "1",
"endpoints": "80:80,8080:8080"
},
{
"component": "wsgw",
"count": "1",
"endpoints": "8080:8080,9093:9093"
}
]
}
in irb :
require 'json'
require 'Siren'
json = File.read('c:\stack1.json')
irb(main):022:0> Siren.query "$.vms..[? @.component == ucms ]", json
=> []
我正在尝试起草一个查询,该查询将搜索组件名称并返回端点的值。任何帮助/指示将不胜感激。
感谢
对于字符串匹配,您需要使用=
运算符,而不是==
。此外,在查询之前需要解析文件读取:
json = Siren.parse File.read('c:\stack1.json')
Siren.query "$.vms..[? @.component = ucms ]", json