我应该使用哪个JSONPath表达式来拆分我的JSON字符串?
我想以下面的JSON文件拆分成2个FlowFiles申请SplitJson
(根据hits
):我应该使用哪个JSONPath表达式来拆分我的JSON字符串?
{"took":0,"timed_out":false,"_shards":
{"total":5,"successful":5,"failed":0},
"hits":{"total":2,"max_score":0.0,
"hits":
[
{"_index":"my_index","_type":"my_entry","_id":"111","_score":0.0,"_source":{"ZoneId":"1","OriginId":"1"},
"fields":{"ttime":[11000]}},
{"_index":"my_index","_type":"my_entry","_id":"222","_score":0.0,"_source":{"ZoneId":"1","OriginId":"2"},
"fields":{"ttime":[5000]}}
]
}
}
我应该使用哪种JsonPath Expression
?我试过$.hits[*]
,但它会根据第一级hits
分割内容。在我的情况下,我有hits[hits[...]]
,但我应该如何在表达式中指定它?
UPDATE:
我希望得到两个FlowFiles:
FlowFile#1:{"_index":"my_index","_type":"my_entry","_id":"111","_score":0.0,"_source":{"ZoneId":"1","OriginId":"1"},"fields":{"ttime":[11000]}}
FlowFile#2: {"_index":"my_index","_type":"my_entry","_id":"222","_score":0.0,"_source":{"ZoneId":"1","OriginId":"2"},"fields":{"ttime":[5000]}}
var arr = $.hits.hits;
会给你你想要的2个对象的数组。
var o1 = arr[0];
var o2 = arr[1];
会给你你想要的2个物体。
var json1 = JSON.stringify(arr[0]);
var json2 = JSON.stringify(arr[1]);
会根据您的要求提供2个JSON文件。 这是你需要的吗?
您可以使用此website测试JSONPath索引你的情况。 正确的答案是$.hits.hits[*]
。
正如丹特史密斯提到的,你可以简单地使用$.hits.hits
在你的情况。这取决于后期处理。这两种方法都很好。
不,它会生成两个具有相同内容的JSON文件。它不适合我。 – Dinosaurius
我想得到两个FlowFile:第一个包含“{”_index“:”my_index“,”_ type“:”my_entry“,”_ id“:”111“,”_ score“:0.0,”_ source“:{第二个包含“{”_index“:”my_index“,”_ type“”OriginId“:”1“},”fields“:{”ttime“:[11000]}} : “my_entry”, “_ ID”: “222”, “_分数”:0.0, “_源”:{ “了zoneid”: “1”, “OriginId”: “2”}, “字段”:{ “TTIME”: [5000]}}'。 – Dinosaurius
是的,它工作正常。为什么'$ .hits.hits [*]'不起作用? – Dinosaurius
它应该如果你修改后的方法。看看结果在http://jsonpath.com/中的细微差别? – DanteTheSmith