JSON 到 JSOn 颠簸转变

JSON to JSOn jolt transformation

我想转换我的嵌套 json 消息并使用 Jolt 规范只获取必需的文件-

我的输入JSON:

{
  "results": [
    {
      "user": {
        "gender": "male",
        "name": {
          "title": "mr",
          "first": "moritz",
          "last": "zimmer"
        },
        "location": {
          "street": "3667 breslauer straße",
          "city": "gera",
          "state": "mecklenburg-vorpommern",
          "zip": 35662
        },
        "email": "moritz.zimmer@example.com",
        "username": "purplegorilla905",
        "password": "kkkkk",
        "salt": "O5KFiJMB",
        "md5": "d5659f39f9102452dca5e9afbfe06f07",
        "sha1": "bb8790f5e22a8a4c33f12d623cd7f5c45adba275",
        "sha256": "5fc5dd30d75c323404474e2c5bec2372a145f363742162b36a6414aa10e2b5e6",
        "registered": 968202500,
        "dob": 68248460,
        "phone": "0450-7475136",
        "cell": "0179-3008357",
        "picture": {
          "large": "https://randomuser.me/api/portraits/men/15.jpg",
          "medium": "https://randomuser.me/api/portraits/med/men/15.jpg",
          "thumbnail": "https://randomuser.me/api/portraits/thumb/men/15.jpg"
        }
      }
    },
    {
      "user": {
        "gender": "female",
        "name": {
          "title": "ms",
          "first": "julia",
          "last": "bayer"
        },
        "location": {
          "street": "5913 burgstraße",
          "city": "mühldorf a. inn",
          "state": "bremen",
          "zip": 17247
        },
        "email": "julia.bayer@example.com",
        "username": "bluedog987",
        "password": "sheba1",
        "salt": "qJ3KuIu7",
        "md5": "c29e59c439ebc41b6772344b53863a17",
        "sha1": "7fdb58f22eb85cb89ffb0c2cbb13bbf3bbb37238",
        "sha256": "d6114912b8476e1c825a3487feb1cc7319c0c26f29f583ccd6864fa4f11214db",
        "registered": 1224249359,
        "dob": 1307176045,
        "phone": "0846-0635929",
        "cell": "0172-0881456",
        "picture": {
          "large": "https://randomuser.me/api/portraits/women/15.jpg",
          "medium": "https://randomuser.me/api/portraits/med/women/15.jpg",
          "thumbnail": "https://randomuser.me/api/portraits/thumb/women/15.jpg"
        }
      }
    },
    {
      "user": {
        "gender": "male",
        "name": {
          "title": "mr",
          "first": "sascha",
          "last": "vogel"
        },
        "location": {
          "street": "8276 lerchenweg",
          "city": "straubing",
          "state": "niedersachsen",
          "zip": 73954
        },
        "email": "sascha.vogel@example.com",
        "username": "purplefrog135",
        "password": "picard",
        "salt": "kBv4gmHR",
        "md5": "79a388de1832ab7f14f4e5ddf0d88012",
        "sha1": "8fc12f95217bf04eaf7e950154485dd35b84c65e",
        "sha256": "a5df2bfd3ee84a869c43f92fe28ce5f56f7700bc75ce2e12bbee7cad2524af82",
        "registered": 950549849,
        "dob": 310749405,
        "phone": "0098-5667969",
        "cell": "0179-8473990",
        "picture": {
          "large": "https://randomuser.me/api/portraits/men/83.jpg",
          "medium": "https://randomuser.me/api/portraits/med/men/83.jpg",
          "thumbnail": "https://randomuser.me/api/portraits/thumb/men/83.jpg"
        }
      }
    },
    {
      "user": {
        "gender": "female",
        "name": {
          "title": "mrs",
          "first": "luisa",
          "last": "döring"
        },
        "location": {
          "street": "9027 am bahnhof",
          "city": "salzgitter",
          "state": "bayern",
          "zip": 12419
        },
        "email": "luisa.döring@example.com",
        "username": "purpleelephant855",
        "password": "californ",
        "salt": "gsnCNl8c",
        "md5": "905d16801137f3368277889a783c02f3",
        "sha1": "a5027752e9228bbc1e99fa56a6f2d09a1901e7e2",
        "sha256": "51b7e09a415fef7e71eb3aec2721e91d0b51c2e264a7cdd41f3a692777771de3",
        "registered": 1068886905,
        "dob": 733574914,
        "phone": "0648-0740938",
        "cell": "0172-1199322",
        "picture": {
          "large": "https://randomuser.me/api/portraits/women/65.jpg",
          "medium": "https://randomuser.me/api/portraits/med/women/65.jpg",
          "thumbnail": "https://randomuser.me/api/portraits/thumb/women/65.jpg"
        }
      }
    }
  ],
  "nationality": "DE",
  "seed": "23e269027e0ea51404",
  "version": "0.8"
}

预期输出:

[
  {
    "Gender": "male",
    "FirstName": "moritz",
    "LastName": "zimmer",
    "City": "gera",
    "State": "mecklenburg-vorpommern",
    "Email": "moritz.zimmer@example.com",
    "DateOfBirth": 68248460,
    "MobileNo": "0179-3008357",
    "Nationality": "DE"
  },
  {
    "Gender": "female",
    "FirstName": "julia",
    "LastName": "bayer",
    "City": "mühldorf a. inn",
    "State": "bremen",
    "Email": "julia.bayer@example.com",
    "DateOfBirth": 1307176045,
    "MobileNo": "0172-0881456",
    "Nationality": "DE"
  },
  {
    "Gender": "male",
    "FirstName": "sascha",
    "LastName": "vogel",
    "City": "straubing",
    "State": "niedersachsen",
    "Email": "sascha.vogel@example.com",
    "DateOfBirth": 310749405,
    "MobileNo": "0179-8473990",
    "Nationality": "DE"
  },
  {
    "Gender": "female",
    "FirstName": "luisa",
    "LastName": "döring",
    "City": "salzgitter",
    "State": "bayern",
    "Email": "luisa.döring@example.com",
    "DateOfBirth": 733574914,
    "MobileNo": "0172-1199322",
    "Nationality": "DE"
  }
]

我使用的是低于规格的产品,但输出未达到预期 -

我的规格:

[
  {
    "operation": "shift",
    "spec": {
      "results": {
        "*": {
          "user": {
            "gender": "[&2].Gender",
            "name": {
              "first": "[&3].FirstName",
              "last": "[&3].LastName"
            },
            "location": {
              "city": "[&3].City",
              "state": "[&3].State"
            },
            "email": "[&2].Email",
            "dob": "[&2].DateOfBirth",
            "cell": "[&2].MobileNo"
          }
        }
      }
    }
  }
]

低于预期的规格输出 -

[
  {
    "Gender": "male",
    "FirstName": "moritz",
    "LastName": "zimmer",
    "City": "gera",
    "State": "mecklenburg-vorpommern",
    "Email": "moritz.zimmer@example.com",
    "DateOfBirth": 68248460,
    "MobileNo": "0179-3008357"
  },
  {
    "Gender": "female",
    "FirstName": "julia",
    "LastName": "bayer",
    "City": "mühldorf a. inn",
    "State": "bremen",
    "Email": "julia.bayer@example.com",
    "DateOfBirth": 1307176045,
    "MobileNo": "0172-0881456"
  },
  {
    "Gender": "male",
    "FirstName": "sascha",
    "LastName": "vogel",
    "City": "straubing",
    "State": "niedersachsen",
    "Email": "sascha.vogel@example.com",
    "DateOfBirth": 310749405,
    "MobileNo": "0179-8473990"
  },
  {
    "Gender": "female",
    "FirstName": "luisa",
    "LastName": "döring",
    "City": "salzgitter",
    "State": "bayern",
    "Email": "luisa.döring@example.com",
    "DateOfBirth": 733574914,
    "MobileNo": "0172-1199322"
  }
]

我尝试了很多选项,但国籍并没有像我预期的那样出现。 请在这里帮助 Jolt 转型

提示: 使用 "*": "&" 查看结果数组的外部,同时查看结果数组的内部,并将它们组合在 下name 键,作为所需结果集的标准分组似乎是唯一的,例如

[
  {
    "operation": "shift",
    "spec": {
      "results": {
        "*": {
          "user": {
            "*": "&"
          }
        }
      },
      "*": "&"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "name": {
        "*": {
          "@(2,gender[&])": "[&].Gender",
          "@(0,first)": "[&1].First&2",
          "@(0,last)": "[&1].Last&2",
          "@(2,location[&].city)": "[&].City",
          "@(2,location[&].state)": "[&].State",
          "@(2,email[&])": "[&].Email",
          "@(2,dob[&])": "[&].DateOfBirth",
          "@(2,phone[&])": "[&].MobileNo",
          "@(2,nationality)": "[&].Nationality"
        }
      }
    }
  }
]