将Jolt中的JSON数组转换为新的JSON对象,并保持对象的分离

ss2ws0br  于 2023-01-10  发布在  其他
关注(0)|答案(1)|浏览(176)

我有一个JSON对象数组,需要将其转换为与我的方案一致的新JSON对象数组。我不熟悉Jolt,但我的输出不是我所需要的。我尝试在其中使用[&1]和@运算符,但尚未获得所需的输出。
我的意见:

{
  "totalCount": 2,
  "entities": {
    "people": [
      {
        "uniqueIdentifier": "0105",
        "common": {
          "firstName": "Bob",
          "lastName": "Smith",
          "geoLocation": {
            "geometry": {
              "point": {
                "coordinates": [
                  39.93479016,
                  47.21850072
                ]
              }
            }
          },
          "timeOfReporting": "2019-11-18T18:36:10Z"
        },
        "type": "PERSON",
        "parent": {
          "firstName": "Jane",
          "lastName": "Smith"
        }
      },
      {
        "uniqueIdentifier": "0106",
        "common": {
          "firstName": "Joe",
          "lastName": "Green",
          "geoLocation": {
            "geometry": {
              "point": {
                "coordinates": [
                  39.93479016,
                  47.21850072
                ]
              }
            }
          },
          "timeOfReporting": "2019-11-18T18:36:10Z"
        },
        "Type": "PERSON",
        "parent": {
          "firstName": "John",
          "lastName": "Green"
        }
      }
    ]
  }
}

我的震动规格:

[
  {
    "operation": "shift",
    "spec": {
      "entities": {
        "people": {
          "*": {
            "uniqueIdentifier": "Person.Id",
            "type": "Person.Type",
            "parent": {
              "firstName": "Person.Parent.FirstName",
              "lastName": "Person.Parent.LastName"
            },
            "common": {
              "firstName": "Person.FirstName",
              "lastName": "Person.LastName",
              "timeOfReporting": "Person.DateCreated",
              "geoLocation": {
                "geometry": {
                  "point": {
                    "coordinates": {
                      "0": "Person.Locations.Location.Longitude",
                      "1": "Person.Locations.Location.Latitude"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "default",
    "spec": {
      "Person": {
        "Processed": "false"
      }
    }
  }
  ]

电流输出:

{
  "Person" : {
    "DateCreated" : [ "2019-11-18T18:36:10Z", "2019-11-18T18:36:10Z" ],
    "FirstName" : [ "Bob", "Joe" ],
    "Id" : [ "0105", "0106" ],
    "LastName" : [ "Smith", "Green" ],
    "Locations" : {
      "Location" : {
        "Latitude" : [ 47.21850072, 47.21850072 ],
        "Longitude" : [ 39.93479016, 39.93479016 ]
      }
    },
    "Parent" : {
      "FirstName" : [ "Jane", "John" ],
      "LastName" : [ "Smith", "Green" ]
    },
    "Processed" : "false",
    "Type" : "PERSON"
  }
}

预期输出:

{
    "Person":{
        "DateCreated": "2019-11-18T18:36:10Z",
        "FirstName": "Bob",
        "LastName" "Smith"
        "Id": "0105",
        "Locations": {
            "Location": {
                "Latitude": 47.2184,
                "Longitude": 39.7854
            }
        },
        "Parent": {
            "FirstName": "Jane",
            "LastName": "Smith"
        },
        "Processed": "false",
        "Type": "PERSON"
    },
    "Person": {
        "DateCreated": "2019-11-18T18:36:10Z",
        "FirstName": "Joe",
        "LastName": "Green"
        "Id": "0106",
        "Locations": {
            "Location": {
                "Latitude": 42.2184,
                "Longitude": 31.7854
            }
        },
        "Parent": {
            "FirstName": "John",
            "LastName": "Green"
        },
        "Processed": "false",
        "Type": "PERSON"
    },
}
5lhxktic

5lhxktic1#

不能在所需的输出中有两个人键。但是,您可以根据您所需的输出使用以下震动规格之一:

1.将所有person对象保存在数组中

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "people": {
          "*": {
            "uniqueIdentifier": "Person[&1].Id",
            "type": "Person[&1].Type",
            "parent": {
              "firstName": "Person[&2].Parent.FirstName",
              "lastName": "Person[&2].Parent.LastName"
            },
            "common": {
              "firstName": "Person[&2].FirstName",
              "lastName": "Person[&2].LastName",
              "timeOfReporting": "Person[&2].DateCreated",
              "geoLocation": {
                "geometry": {
                  "point": {
                    "coordinates": {
                      "0": "Person[&6].Locations.Location.Longitude",
                      "1": "Person[&6].Locations.Location.Latitude"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "modify-default-beta",
    "spec": {
      "*": {
        "*": {
          "Processed": "false"
        }
      }
    }
  }
]

2.将每个人的对象保存在新对象中:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "people": {
          "*": {
            "uniqueIdentifier": "Person.&1.Id",
            "type": "Person.&1.Type",
            "parent": {
              "firstName": "Person.&2.Parent.FirstName",
              "lastName": "Person.&2.Parent.LastName"
            },
            "common": {
              "firstName": "Person.&2.FirstName",
              "lastName": "Person.&2.LastName",
              "timeOfReporting": "Person.&2.DateCreated",
              "geoLocation": {
                "geometry": {
                  "point": {
                    "coordinates": {
                      "0": "Person.&6.Locations.Location.Longitude",
                      "1": "Person.&6.Locations.Location.Latitude"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "modify-default-beta",
    "spec": {
      "*": {
        "*": {
          "Processed": "false"
        }
      }
    }
  }
]

相关问题