当前位置: 首页 > 知识库问答 >
问题:

JSON到JSON jolt转换

洪浩
2023-03-14

我想转换我的嵌套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"
  }
]

我尝试了很多选择,但国籍不是我预期的输出。请在这里帮助颠簸转换

共有1个答案

林鸿飞
2023-03-14

提示:使用“*”:“&”查看结果数组的外部部分,同时查看结果数组的内部部分,并将它们组合在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"
        }
      }
    }
  }
]
 类似资料:
  • 问题内容: 我有一个场景。 必需的输入和输出是JSON。 我需要一些转换代码或最好是xslt类型的语言才能将json从一种格式转换为另一种格式。该变压器也需要快速运行,因为转换将即时进行。 编辑 我没有收到INPUT对象的定义,它可能会在运行时更改。但是如果需要,我可以将类用于OUTPUT对象。我尝试以 json- > xml-> xslt-> xml-> json的方式进行此操作 ,但 此刻 每

  • 所以目前我看到的是这样的: 这是我目前编写的Jolt规范(编辑): 以及转换后的输出: 任何帮助都是非常感谢的。

  • `我有以下输入json格式,需要转换以下json文件。我正在使用jolt转换,但无法使用https://jolt-demo.appspot.com/#inception网站正确格式化输出 `需要以下使用JOLT Iam的输出json格式,尝试使用JOLT转换进行转换

  • 问题内容: 我正在从String变量的Restful api获取数据,现在我想转换为JSON对象,但是在转换时会引发异常,这是我的问题。这是我的代码: 我的字符串包含 这是我想要在json中使用的字符串,但它向我显示了线程“ main”中的异常 问题答案: 的是本内的。您需要按层次分析JSON,以便能够正确获取数据。 注意:本示例使用类而不是。 正如“ Matthew”在他正在使用的注释中提到的那

  • 问题内容: 是否有在Ruby中将XML转换为JSON的库? 问题答案: 一个简单的把戏: 首先,您需要,然后在使用Rails时可以执行以下操作: 如果您不使用Rails,则可以要求它,并且事情应该顺利进行。 例:

  • 我试图将一个JSON请求传递给我的服务器,在那里控制器在将JSON转换为POJO时遇到一个错误。 我不确定代码出了什么问题。我对Spring还是个新手,所以我很感激你的帮助。