我目前正在使用 Pentaho Kettle 进行一些 ETL 工作,并且我需要集成 JSON 提要,这意味着我需要使用 JSONPath 来获取数据。在大多数情况下,它运行良好,除了一些 JSON 数据是嵌套对象,在父项和子项中具有相同的字段名称。
示例 JSON:
[
{
"Key": "5e59d536-2e3c-487c-bff1-efd0a706532f",
"Product": {
"Name": "Some Product",
"LastUpdated": "2013-08-23T12:10:25.454",
},
"Reviewer": {
"Email": "blah@foo.com",
"LastUpdated": "2013-08-23T12:10:25.454",
},
"LastUpdated": "2013-08-23T12:10:25.407",
},
{
"Key": "f3ae6a4b-1a20-4a9a-9a8e-2de5949c4493",
"Product": {
"Name": "Some Product",
"LastUpdated": "2013-08-23T12:10:51.896",
},
"Reviewer": {
"Email": "blah@foo.com",
"LastUpdated": "2013-08-23T12:10:51.896",
},
"LastUpdated": "2013-08-23T12:10:51.896",
},
{
"Key": "de01c358-6c74-473c-8cd4-a44cf50132df",
"Product": {
"Name": "Some Product",
"LastUpdated": "2013-08-26T10:30:13.617",
},
"Reviewer": {
"Email": "blah@foo.com",
"LastUpdated": "2013-08-26T10:30:13.617",
},
"LastUpdated": "2013-08-26T10:30:13.601",
},
},
{
"Key": "af04e48a-3ce8-4227-a00a-14483ca75058",
"Product": {
"Name": "Some Product",
"LastUpdated": "2013-08-26T10:31:20.573",
},
"Reviewer": {
"Email": "blah@foo.com",
"LastUpdated": "2013-08-26T10:31:20.573",
},
"LastUpdated": "2013-08-26T10:31:20.573",
},
{
"Key": "d1a787bb-37d2-4ea9-84fd-5a3d454b9127",
"Product": {
"Name": "Some Product",
"LastUpdated": "2013-08-27T11:59:56.777",
},
"Reviewer": {
"Email": "blah@foo.com",
"LastUpdated": "2013-08-27T11:59:56.777",
},
"LastUpdated": "2013-08-27T11:59:56.73",
},
{
"Key": "d8646319-af27-464f-bd50-d61e035800c6",
"Product": {
"Name": "Some Product",
"LastUpdated": "2013-08-27T19:43:06.928",
},
"Reviewer": {
"Email": "blah@foo.com",
"LastUpdated": "2013-08-27T19:43:06.928",
},
"LastUpdated": "2013-08-27T19:43:06.866",
},
]
如您所见,父对象及其子对象“Product”和“Reviewer”都具有“LastUpdated”字段。我试图仅获取父对象的“LastUpdated”,但使用:
$..LastUpdated
按顺序返回父级 LastUpdated、Product LastUpdated,然后是 Reviewer LastUpdated。
结果:
[
"2013-08-23T12:10:25.407",
"2013-08-23T12:10:25.454",
"2013-08-23T12:10:25.454",
"2013-08-23T12:10:51.896",
"2013-08-23T12:10:51.896",
"2013-08-23T12:10:51.896",
"2013-08-26T10:30:13.601",
"2013-08-26T10:30:13.617",
"2013-08-26T10:30:13.617",
"2013-08-26T10:31:20.573",
"2013-08-26T10:31:20.573",
"2013-08-26T10:31:20.573",
"2013-08-27T11:59:56.73",
"2013-08-27T11:59:56.777",
"2013-08-27T11:59:56.777",
"2013-08-27T19:43:06.866",
"2013-08-27T19:43:06.928",
"2013-08-27T19:43:06.928"
]
预期成绩:
[
"2013-08-23T12:10:25.407",
"2013-08-23T12:10:51.896",
"2013-08-26T10:30:13.601",
"2013-08-26T10:31:20.573",
"2013-08-27T11:59:56.73",
"2013-08-27T19:43:06.866",
]
有没有我可以用来只获取父对象的 LastUpdated 字段的查询?