簡體   English   中英

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 key 下,這似乎是唯一的,作為按所需結果集的條件分組的唯一方法,例如作為

[
  {
    "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"
        }
      }
    }
  }
]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM