如何使用jq搜索包含特定字符串的JSON键?
我有一个JSON数据:如何使用jq搜索包含特定字符串的JSON键?,json,regex,key,jq,Json,Regex,Key,Jq,我有一个JSON数据: { "orderTotal_1": { "fields": { "button": { "actionDialog": null, "actionUrl": null, "clicked": false, "enable": true, "text": "LANJUT
{
"orderTotal_1": {
"fields": {
"button": {
"actionDialog": null,
"actionUrl": null,
"clicked": false,
"enable": true,
"text": "LANJUTKAN KE PEMBAYARAN",
"textColor": null
},
"payment": {
"pay": "Rp1.953.800",
"taxTip": "Termasuk PPN, jika berlaku.",
"title": "Total"
},
"timestamp": 1522355946093
},
"id": "1",
"tag": "orderTotal",
"type": "biz"
},
"rightContainer_10010": {
"fields": {
"css": {
"backgroundColor": null,
"floatPosition": "right",
"marginTop": null,
"width": "388px"
}
},
"id": "10010",
"tag": "rightContainer",
"type": "container"
},
"toPayBtn_10021": {
"fields": {
"clicked": false,
"enable": true,
"text": "LANJUTKAN KE PEMBAYARAN"
},
"id": "10021",
"tag": "toPayBtn",
"type": "biz"
},
"voucherInput_1": {
"fields": {
"buttonText": "GUNAKAN",
"placeHolder": "Masukkan Kode Voucher",
"status": "default"
},
"id": "1",
"tag": "voucherInput",
"type": "biz"
}
}
我想获得toPayBtn_10021
,但编号10021
是动态的。因此它可以是toPayBtn_34
toPayBtn_21
等
这是我想要实现的输出:
"toPayBtn_10021": {
"fields": {
"clicked": false,
"enable": true,
"text": "LANJUTKAN KE PEMBAYARAN"
},
"id": "10021",
"tag": "toPayBtn",
"type": "biz"
}
这就是我尝试过的:
jq '.toPayBtn*'
但结果是:
jq: error: syntax error, unexpected $end (Unix shell quoting issues?) at <top-level>, line 1:
.toPayBtn*
jq: 1 compile error
exit status 3
jq:error:syntax error,第1行出现意外的$end(Unix shell引用问题?):
.toPayBtn*
jq:1编译错误
退出状态3
Regex似乎不适用于jq
如何修复它
with_entries( select(.key | test("^toPayBtn_")) )
生成所需的输出。您可能需要调整正则表达式。这是搜索框中的角度过滤器示例搜索文本,它将仅显示具有搜索键的对象。
应用程序
th{
显示:表格单元格;
垂直对齐:继承;
字体大小:粗体;
文本对齐:居中;
}
{{search}}
对象
{{displayById}
{{x}
var ngmodule=angular.module(“app”,[]);
ngmodule.controller(“ctrl”[“$scope”、“$log”、“$timeout”,
函数($scope、$log、$timeout){
$scope.init=函数(){
console.log(“$timeout”)
}
$timeout($scope.init);
$scope.jsonData=[{
“订单总数1”:{
“字段”:{
“按钮”:{
“actionDialog”:空,
“actionUrl”:空,
“单击”:false,
“启用”:正确,
“文本”:“LANJUTKAN KE PEMBAYARAN”,
“textColor”:空
},
“付款”:{
“支付”:“Rp1.953.800”,
“税务提示”:“Termasuk PPN,jika berlaku.”,
“标题”:“总计”
},
“时间戳”:1522355946093
},
“id”:“1”,
“标记”:“orderTotal”,
“类型”:“业务”
},
“rightContainer_10010”:{
“字段”:{
“css”:{
“背景颜色”:空,
“浮动位置”:“右侧”,
“marginTop”:空,
“宽度”:“388px”
}
},
“id”:“10010”,
“标记”:“rightContainer”,
“类型”:“容器”
},
“toPayBtn_10021”:{
“字段”:{
“单击”:false,
“启用”:正确,
“文本”:“LANJUTKAN KE PEMBAYARAN”
},
“id”:“10021”,
“标签”:“toPayBtn”,
“类型”:“业务”
},
“voucherInput_1”:{
“字段”:{
“buttonText”:“GUNAKAN”,
“占位符”:“Masukkan Kode凭证”,
“状态”:“默认”
},
“id”:“1”,
“标记”:“voucherInput”,
“类型”:“业务”
}
}];
}]);
谢谢,你能再帮我一次吗?