Jolt转换扩展点作为JSON对象

xyhw6mcr  于 2023-02-06  发布在  其他
关注(0)|答案(1)|浏览(121)

在Jolt中有没有一种方法可以在转换输入时将JSON值中的点操作符转换为嵌套的JSON对象?
例如,在下面的json中,我希望将id = 2的target_property转换为预期O/P中所示的json对象。如有任何帮助,敬请谅解

    • 输入:**
{
  "name": "Test",
  "email": "Test",
  "form_id": "123",
  "field_list": [
    {
      "id": 1,
      "value": "Test Subject",
      "is_custom_field": false,
      "target_property": "subject"
    },
    {
      "id": 2,
      "value": "Test Description",
      "is_custom_field": false,
      "target_property": "comment.body"
    }
  ]
}
    • 已尝试抖动变换**
[
  {
    "operation": "shift",
    "spec": {
      "form_id": "ticket.ticket_form_id",
      "name": "ticket.requester.name",
      "email": "ticket.requester.email",
      "field_list": {
        "*": {
          "is_custom_field": {
            "true": {
              "@(2,target_property)": "ticket.custom_fields[&3].id",
              "@(2,value)": "ticket.custom_fields[&3].value"
            },
            "*": {
              "@(2,value)": "ticket.@(3,target_property)"
            }
          }
        }
      }
    }
  }
]
    • 当前输出**
{
  "ticket" : {
    "ticket_form_id" : "123",
    "requester" : {
      "name" : "Test",
      "email" : "Test"
    },
    "subject" : "Test Subject",
    "comment.body" : "Test Description"
  }
}
    • 预期产出**
{
  "ticket": {
    "ticket_form_id": "123",
    "requester": {
      "name": "Test",
      "email": "Test"
    },
    "subject": "Test Subject",
    "comment": {
      "body": "Test Description"
    }
  }
}
9udxz4iz

9udxz4iz1#

您可以添加另一个shift转换规范,使

{
  "operation": "shift",
  "spec": {
    "*": {
      "*": "&1.&",
      "*.*": "&1.&(0,1).&(0,2)"
    }
  }
}

其中

  • "*.*"表示在其中有一个点的属性.在&(0,..)表达式中的零代表 * 当前级别 *
    12作为它们的第二参数分别表示分割密钥的第一和第二部分(在这种情况下为*comment.body**)。

相关问题