我应该使用哪个 JSONPath 表达式来拆分我的 JSON 字符串?

Which JSONPath expression should I use to split my JSON string?

我想应用 SplitJson 以便将以下 JSON 文件拆分为 2 个 FlowFiles(根据 hits):

    {"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[...]],但我应该如何在表达式中指定它?

更新:

我想得到两个流文件:

流文件#1:{"_index":"my_index","_type":"my_entry","_id":"111","_score":0.0,"_source":{"ZoneId":"1","OriginId":"1"},"fields":{"ttime":[11000]}}

流文件#2: {"_index":"my_index","_type":"my_entry","_id":"222","_score":0.0,"_source":{"ZoneId":"1","OriginId":"2"},"fields":{"ttime":[5000]}}

您可以使用此 website 为您的案例测试 JSONPath 索引。 正确答案是 $.hits.hits[*].

如 DanteTheSmith 所述,您可以在您的情况下简单地使用 $.hits.hits。这取决于 post- 处理。两种方法都很好。

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 个文件。 这是您需要的吗?