Jolt 将嵌套对象转换为数组

问题描述 投票:0回答:1

给定以下 Json 输入,如何编写 Jolt 规范以将输入转换为下面所需的输出。我不确定如何处理在数组中转动嵌套对象并在使用“*”运算符时排除字段“AllOff”。但是我已经尝试了不同的规格https://jolt-demo.appspot.com/#inception我似乎无法获得想要的转变。

输入

{
    "data": {
        "properties": {
            "info": { 
                "type": "object",
                "$comment": "Evaluation Information",
                "required": [
                "evalDate",
                "evalType",
                "evalWeather"
                ],
                "properties": {
                  "evalDate": {
                      "type": "string",
                      "format": "date"
                  },
                  "evalType": {
                      "type": "string",
                      "enum": [
                      "1st Party",
                      "2nd Party",
                      "3rd Party"
                      ],
                      "default": "2nd Party"
                  },
                  "evalWeather": {
                      "type": "string"
                  }
                }
            },
            "evaluator": {
                "type": "object",
                "required": [
                  "id",
                  "name"
                ],
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "name": {
                    "type": "string"
                  },
                  "phone": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "email": {
                    "anyOf": [
                      {
                        "type": "string",
                        "format": "email"
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                }
              },
            "AllOf": []
        }
    }
}

期望的输出

{
    "FormModel": {
        "Categories": [
            {
                "Title": "info",
                "fields": [
                    {
                        "Title": "evalDate",
                        "DataType": "string"
                    },
                    {
                        "Title": "evalType",
                        "DataType": "string"
                    },
                    {
                        "Title": "evalWeather",
                        "DataType": "string"
                    }
                ]
            },
            {
                "Title": "evaluator",
                "fields": [
                    {
                        "Title": "id",
                        "DataType": "string"
                    },
                    {
                        "Title": "name",
                        "DataType": "string"
                    },
                    {
                        "Title": "phone",
                        "DataType": ["string"]
                    },
                    {
                        "Title": "email",
                        "DataType": ["string", "null"]
                    }
                ]
            }

        ]
    }
}
json jolt
1个回答
0
投票

似乎预计会循环查找叶节点

type
,然后使用
Title
通配符(例如
)轻松确定相应的
$

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": {
            "properties": {
              "*": {
                "type": "&3.&1.Data&",
                "*": {
                  "*": {
                    "type": "&5.&3.Data&"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "$": "FormModel.Categories[0].&1.Title",
        "*": {
          "$": "FormModel.Categories[0].&2.fields[#2].Title",
          "*": "FormModel.Categories[0].&2.fields[#2].&"
        }
      }
    }
  }
]
© www.soinside.com 2019 - 2024. All rights reserved.