【发布时间】:2020-03-03 08:58:19
【问题描述】:
我有一个 JSON 输入数据,其中 author 和 publisher 标签只有 ID,它们的完整信息在 relationships 标签下给出。我需要将这些 ID 替换为输出 JSON 中的实际数据。
通过 JOLT 转换是否可行?
我尝试了很多组合并阅读了他们的 Javadoc,但到目前为止还没有运气。我可以在 Java 代码和 jolt 转换中稍作调整,但只想通过 JOLT 转换来实现,这样就不需要创建新的 jar 文件。
我有一个示例输入 JSON,如下所示
"meta": {
"total": 3
},
"data": [
{
"id": "1112245810",
"title": "Introduction to JavaScript Object Notation",
"author": "54256",
"publisher": "57756",
"edition": "first",
"published": "2012"
},
{
"id": "1156464683",
"title": "JSON at Work",
"author": "15467",
"publisher": "57756",
"edition": "second",
"published": "2014"
},
{
"id": "1004467968",
"title": "A Tiny Bit Mortal",
"author": "54256",
"publisher": "56465",
"edition": "first",
"published": "2018"
}
],
"relationships": [
{
"id": "54256",
"type": "author",
"attributes": {
"first-name": "Lindsay",
"last-name": "Bassett",
"city": "Michigan"
}
},
{
"id": "15467",
"type": "author",
"attributes": {
"first-name": "Tom",
"last-name": "Marrs",
"city": "Cologne"
}
},
{
"id": "57756",
"type": "publisher",
"attributes": {
"name": "O'REILLY",
"established": "1984"
}
},
{
"id": "56465",
"type": "publisher",
"attributes": {
"name": "APRESS",
"established": "1979"
}
}
]
}
以及所需的输出 JSON
{
"meta": {
"total": 3
},
"data": [
{
"id": "1112245810",
"title": "Introduction to JavaScript Object Notation",
"author": {
"first-name": "Lindsay",
"last-name": "Bassett",
"city": "Michigan"
},
"publisher": {
"name": "O'REILLY",
"established": "1984"
},
"edition": "first",
"published": "2012"
},
{
"id": "1156464683",
"title": "JSON at Work",
"author": {
"first-name": "Tom",
"last-name": "Marrs",
"city": "Cologne"
},
"publisher": {
"name": "O'REILLY",
"established": "1984"
},
"edition": "second",
"published": "2014"
},
{
"id": "1004467968",
"title": "A Tiny Bit Mortal",
"author": {
"first-name": "Lindsay",
"last-name": "Bassett",
"city": "Michigan"
},
"publisher": {
"name": "APRESS",
"established": "1979"
},
"edition": "first",
"published": "2018"
}
],
}
【问题讨论】:
标签: json transformation jolt