使用jolt变换并将平面json转换为复杂的嵌套json数组
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用jolt变换并将平面json转换为复杂的嵌套json数组相关的知识,希望对你有一定的参考价值。
我有一个关于使用jolt将flat json转换为嵌套json的问题。我很吵,这是我的意见
{
"id": "LIKKI MOSORU",
"aff_id": "WOOD",
"aff_name": "WOOD-LOVE",
"aff_desc": "WOOD INC.",
"aff_corrltn_name": "MARVEL MEMBERSHIP",
"aff_corrltn_id": "8999938",
"affil_trans_id": "222222",
"misc_aff_dtl_name": "MBR-FIRST-NAME",
"misc_aff_dtl_value" :"KKKKKLYYYY",
"oper_id": "AP",
"create_timestamp":"2018-10-16-04:00",
"update_timestamp": "2018-10-17-04:00",
"active_rcrd": "Y"
}
我写了jolt spec,但是我得不到想要的输出
[
{
"operation": "shift",
"spec": {
"misc_aff_dtl_*": "misc_aff_dtl.&(0,1)",
"aff_corrltn_*": "aff_corrltn.&(0,0)",
"aff_*": "aff.&(0,0)",
"rewards_id": "rewards_id",
"oper_id": "oper_id",
"create_timestamp": "create_timestamp",
"update_timestamp": "update_timestamp",
"active_rcrd": "active_rcrd"
}
}
]
我的预期输出是:
{
"rewards_id": "Jeannine Rosario",
"aff": [
{
"aff_id": "WOOD",
"aff_name": "WOOD-LOVE",
"aff_desc": "WOOD INC.",
"aff_corrltn": [
{
"aff_corrltn_name": "MARVEL MEMBERSHIP",
"aff_corrltn_id": "8999938",
"affil_trans_id": "222222",
"misc_aff_dtl": [
{
"name":"MBR-FIRST-NAME",
"value":"DANJALKSA"
}
]
}
],
"oper_id": "AP",
"create_timestamp":"2018-10-16-04:00",
"update_timestamp": "2018-10-17-04:00",
"active_rcrd": "Y"
}
]
}
任何一个摇摆专家都可以帮助我获得所需的输出。我是否应该在摇晃中使用多个变换,或者是否可以在一个变压器中获得所需的输出?
答案
使用[0]
添加数组将产生预期的效果:
[
{
"operation": "shift",
"spec": {
"rewards_id": "rewards_id",
"aff_*": "aff.[0].&(0,0)",
"misc_aff_dtl_*": "aff.[0].aff_corrltn.[0].misc_aff_dtl.[0].&(0,1)",
"aff_corrltn_*": "aff.[0].aff_corrltn.[0].&(0,0)",
"affil_trans_id": "aff.[0].aff_corrltn.[0].&",
"oper_id": "aff.[0].oper_id",
"create_timestamp": "aff.[0].create_timestamp",
"update_timestamp": "aff.[0].update_timestamp",
"active_rcrd": "aff.[0].active_rcrd"
}
}
]
以上是关于使用jolt变换并将平面json转换为复杂的嵌套json数组的主要内容,如果未能解决你的问题,请参考以下文章
使用 python 将嵌套 json 转换为平面 json 时遇到困难
如何将 JSON 对象的嵌套部分转换为点链式平面 JSON?
我如何将平面数据框转换为 spark(scala 或 java)中的嵌套 json