当多个对象在输入中时,Jolt 转换将多个值组合在对象数组中

Jolt transformation combining multiple values in an array of objects when multiple objects are in input

我有一个 JSON 输入:

{
  "Name": "travel.0.0",
  "Documents": [
    {
      "Id": 6732210,
      "Name": "Passport",
      "Fields": [
        {
          "Name": "First Name",
          "Type": "text"
        }
      ],
      "Variants": [
        {
          "Name": "diplomatic_passport",
          "TrainingSamples": [
            {
              "Name": "First Name",
              "Value": "VGhlIFBPU1QsIFBVVCBhbmQgUEFUQ0ggcmVxdWVzdHMgY2FuIGhhdmUgdGhlIHJlcXVlc3QgYm9keSAocGF5bG9hZCksIHN1Y2ggYXMgSlNPTiBvciBYTUwgZGF0YS4gSW4gU3dhZ2dlciB0ZXJtcywgdGhlIHJlcXVlc3QgYm9keSBpcyBjYWxsZWQgYSBib2R5IHBhcmFtZXRlci4gVGhlcmUgY2FuIGJlIG9ubHkgb25lIGJvZHkgcGFyYW1ldGVyLCBhbHRob3VnaCB0aGUgb3BlcmF0aW9uIG1heSBoYXZlIG90aGVyIHBhcmFtZXRlcnMgKHBhdGgsIHF1ZXJ5LCBoZWFkZXIpLg==",
              "BoundingBoxes": [
                {
                  "Name": "string",
                  "Dimensions": [
                    {
                      "PageIndex": 0,
                      "Left": 0,
                      "Top": 0,
                      "Right": 0,
                      "Bottom": 0
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

我的 JOLT 规格是:

[
  {
    "operation": "shift",
    "spec": {
      "Name": "ProjectName",
      "Documents": {
        "*": {
          "Name": {
            "@": ["DocumentDefinitions[#].Name", "DocumentDefinitions[#].SectionDefinitions[#].Name"]
          },
          "Variants": {
            "*": {
              "Name": "DocumentDefinitions[#].SectionDefinitions[#].VarientNames[&1]",
              "TrainingSamples": {
                "0": {
                  "Name": "DocumentDefinitions[#].SectionDefinitions[#].ImageSources[#].ImageName.",
                  "Value": "DocumentDefinitions[#].SectionDefinitions[#].ImageSources[#].ImageValue."
                }
              }
            }
          },
          "Fields": {
            "*": {
              "Name": "DocumentDefinitions[#].SectionDefinitions[#].Fields[&1].Name.",
              "Type": "DocumentDefinitions[#].SectionDefinitions[#].Fields[&1].Type."
            }
          }
        }
      }
    }
  }
]

我的输出是:

{
  "ProjectName" : "travel.0.0",
  "DocumentDefinitions" : [ {
    "Name" : "Passport",
    "SectionDefinitions" : [ {
      "Name" : "Passport",
      "VarientNames" : [ "diplomatic_passport" ],
      "ImageSources" : [ {
        "ImageName" : "First Name",
        "ImageValue" : "VGhlIFBPU1QsIFBVVCBhbmQgUEFUQ0ggcmVxdWVzdHMgY2FuIGhhdmUgdGhlIHJlcXVlc3QgYm9keSAocGF5bG9hZCksIHN1Y2ggYXMgSlNPTiBvciBYTUwgZGF0YS4gSW4gU3dhZ2dlciB0ZXJtcywgdGhlIHJlcXVlc3QgYm9keSBpcyBjYWxsZWQgYSBib2R5IHBhcmFtZXRlci4gVGhlcmUgY2FuIGJlIG9ubHkgb25lIGJvZHkgcGFyYW1ldGVyLCBhbHRob3VnaCB0aGUgb3BlcmF0aW9uIG1heSBoYXZlIG90aGVyIHBhcmFtZXRlcnMgKHBhdGgsIHF1ZXJ5LCBoZWFkZXIpLg=="
      } ],
      "Fields" : [ {
        "Name" : "First Name",
        "Type" : "text"
      } ]
    } ]
  } ]
}

此输出看起来不错,直到我的输入文档数组中只有一个 JSON 对象。然而,当我放置另一个物体时,它看起来有点像这样,这是不希望的。它将两个对象的所有值组合在一起,如下所示:

{
  "ProjectName" : "travel.0.0",
  "DocumentDefinitions" : [ {
    "Name" : [ "Passport", "Passport" ],
    "SectionDefinitions" : [ {
      "Name" : [ "Passport", "Passport" ],
      "VarientNames" : [ [ "diplomatic_passport", "diplomatic_passport" ] ],
      "ImageSources" : [ {
        "ImageName" : [ "First Name", "First Name" ],
        "ImageValue" : [ "VGhlIFBPU1QsIFBVVCBhbmQgUEFUQ0ggcmVxdWVzdHMgY2FuIGhhdmUgdGhlIHJlcXVlc3QgYm9keSAocGF5bG9hZCksIHN1Y2ggYXMgSlNPTiBvciBYTUwgZGF0YS4gSW4gU3dhZ2dlciB0ZXJtcywgdGhlIHJlcXVlc3QgYm9keSBpcyBjYWxsZWQgYSBib2R5IHBhcmFtZXRlci4gVGhlcmUgY2FuIGJlIG9ubHkgb25lIGJvZHkgcGFyYW1ldGVyLCBhbHRob3VnaCB0aGUgb3BlcmF0aW9uIG1heSBoYXZlIG90aGVyIHBhcmFtZXRlcnMgKHBhdGgsIHF1ZXJ5LCBoZWFkZXIpLg==", "VGhlIFBPU1QsIFBVVCBhbmQgUEFUQ0ggcmVxdWVzdHMgY2FuIGhhdmUgdGhlIHJlcXVlc3QgYm9keSAocGF5bG9hZCksIHN1Y2ggYXMgSlNPTiBvciBYTUwgZGF0YS4gSW4gU3dhZ2dlciB0ZXJtcywgdGhlIHJlcXVlc3QgYm9keSBpcyBjYWxsZWQgYSBib2R5IHBhcmFtZXRlci4gVGhlcmUgY2FuIGJlIG9ubHkgb25lIGJvZHkgcGFyYW1ldGVyLCBhbHRob3VnaCB0aGUgb3BlcmF0aW9uIG1heSBoYXZlIG90aGVyIHBhcmFtZXRlcnMgKHBhdGgsIHF1ZXJ5LCBoZWFkZXIpLg==" ]
      } ],
      "Fields" : [ {
        "Name" : [ "First Name", "First Name" ],
        "Type" : [ "text", "text" ]
      } ]
    } ]
  } ]
}

请建议我应该在我的 JOLT 规范中做哪些更改,以便数组中的每个转换对象都被列为单独的对象,而不是被打乱。

检查此规范,

[
  {
    "operation": "shift",
    "spec": {
      "Name": "ProjectName",
      "Documents": {
        "*": {
          "Name": "DocumentDefinitions[&1].Name",
          "Variants": {
            "*": {
              "Name": "DocumentDefinitions[&3].SectionDefinitions[&1].VarientNames[]",
              "TrainingSamples": {
                "*": {
                  "Name": "DocumentDefinitions[&5].SectionDefinitions[&1].ImageSources[&1].ImageName",
                  "Value": "DocumentDefinitions[&5].SectionDefinitions[&1].ImageSources[&1].ImageValue"
                }
              }
            }
          },
          "Fields": {
            "*": {
              "Name": "DocumentDefinitions[&3].SectionDefinitions[&3].Fields[&1].Name",
              "Type": "DocumentDefinitions[&3].SectionDefinitions[&3].Fields[&1].Type"
            }
          }
        }
      }
    }
  }
]