JOLT JSON转换无法按预期进行

时间:2018-09-19 12:32:52

标签: java arrays json transformation jolt

我试图使用JOLT将json从一种JSON格式转换为另一种JSON格式,但是我无法获得预期的输出。我将我的工作包括在下面。任何帮助将不胜感激。谢谢。

我的input.json

{
    "Result": {
    },
    "Content": [
        {
            "MovieDetails": [
                {
                    "Key": "TicketNumber",
                    "Value": "DF-0001"
                },
                {
                    "Key": "MovieName",
                    "Value": "Test"
                }
            ]
        },
        {
            "MovieDetails": [
                {
                    "Key": "TicketNumber",
                    "Value": "DF-0002"
                },
                {
                    "Key": "MovieName",
                    "Value": "Test2"
                }
            ]
        },
        {
            "MovieDetails": [
                {
                    "Key": "TicketNumber",
                    "Value": "DF-0003"
                },
                {
                    "Key": "MovieName",
                    "Value": "Test3"
                }
            ]
        }
    ]
}

我的预期Output.json

{
"Result": {

},
"Content": [
    {
        "MovieDetails": {
            "TicketNumber": "DF-0001",
            "MovieName": "Test1"
        },
        "MovieDetails": {
            "TicketNumber": "DF-0002",
            "MovieName": "Test2"
        }.
        "MovieDetails": {
            "TicketNumber": "DF-0003",
            "MovieName": "Test3"
        }
    }
]
} 

我的实际Output.json

{
"Result": {

},
"Content": [
    {
        "MovieDetails": {
            "TicketNumber": ["DF-0001","DF-0002","DF-0003"],
            "MovieName": ["Test1","Test2","Test3"]
        }
    }
]
} 

我的Spec.json

[
    {
        "operation": "shift",
        "spec": {
            "Result": {
                "*": "Result.&"
            },
            "Content": {
                "*": {
                    "MovieDetails": {
                        "*": {
                            "Value": "Content.MovieDetails.@(1,Key)"
                        }
                    }
                }
            }
        }
    }
]

1 个答案:

答案 0 :(得分:0)

最终使用以下规格...

[
  {
    "operation": "shift",
    "spec": {
      "Result": "Result",
      "Content": {
        "*": {
          "MovieDetails": {
            "*": {
              "Value": "Content[&3].MovieDetails.@(1,Key)"
            }
          }
        }
      }
    }
  }
]