嵌套JSON的颠簸转换

时间:2020-03-10 20:45:41

标签: java arrays json transformation jolt

我正在尝试为我的Input JSON编写规范,并期望使用jolt转换实现以下Output JSON。我面临为此输入JSON创建颠簸规范的困难。 我正在使用以下摇晃链接尝试此操作,但无法创建规范摇晃

https://jolt-demo.appspot.com/#inception

请帮我写出输入JSON的规范。

谢谢!

输入JSON

    {
  "apiVersion": "gateway.solo.io/v1",
  "kind": "RouteTable",
  "metadata": {
    "labels": {
      "proxy": "eag",
      "app": "TestCard",
      "centralId": "200005020"
    },
    "name": "test-rt"
  },
  "spec": {
    "routes": [
      {
        "matchers": [
          {
            "regex": "/acquisition/digital/test",
            "headers": [
              {
                "name": ":method",
                "value": "GET",
                "invertMatch": true
              }
            ]
          }
        ],
        "options": {
          "ratelimit": {
            "rateLimits": [
              {
                "actions": [
                  {
                    "genericKey": {
                      "descriptorValue": "5000pm"
                    }
                  }
                ]
              }
            ]
          }
        },
        "directResponseAction": {
          "status": 405,
          "body": "{\"Error\" : \"RaiseFault\", \"ErrorCode\" : \"405\", \"ErrorDesc\" : \"Method Not Allowed\" }"
        }
      },
      {
        "matchers": [
          {
            "methods": [
              "GET"
            ],
            "regex": "/acquisition/digital/test",
            "headers": [
              {
                "name": "Authorization",
                "invertMatch": true
              }
            ]
          }
        ],
        "options": {
          "ratelimit": {
            "rateLimits": [
              {
                "actions": [
                  {
                    "genericKey": {
                      "descriptorValue": "5000pm"
                    }
                  }
                ]
              }
            ]
          }
        },
        "directResponseAction": {
          "status": 400,
          "body": "{\"Error\" : \"RaiseFault\", \"ErrorCode\" : \"400\", \"ErrorDesc\" : \"Missing Authorization Header\"}"
        }
      },
      {
        "matchers": [
          {
            "methods": [
              "GET"
            ],
            "regex": "/acquisition/digital/test"
          }
        ],
        "options": {
          "extauth": {
            "configRef": {
              "name": "hmac-auth"
            }
          },
          "ratelimit": {
            "rateLimits": [
              {
                "actions": [
                  {
                    "genericKey": {
                      "descriptorValue": "5000pm"
                    }
                  }
                ]
              }
            ]
          }
        }
      }
    ]
  }
}

期望输出JSON

{
  "apigeeVSeag": "true",
  "proxyName": "TestCard",
  "env": "e1",
  "EndPoint": [
    {
      "path": "/acquisition/digital/test",
      "Policies": [
        {
          "PolicyName": "MatchingHeader",
          "Attributes": [
            {
              "CustomError": "{'Error' : 'RaiseFault', 'ErrorCode' : '405', 'ErrorDesc' : 'Method Not Allowed' }",
              "name": ":method",
              "invertmatch": "true",
              "value": "GET",
              "status": 405
            }
          ]
        },
        {
          "PolicyName": "Ratelimit",
          "Attributes": [
            {
              "value": "5000pm"
            }
          ]
        },
        {
          "PolicyName": "CheckMissingHeaders",
          "Attributes": [
            {
              "CustomError": "{'Error' : 'RaiseFault', 'ErrorCode' : '400', 'ErrorDesc' : 'Missing Authorization Header'}",
              "name": "Authorization",
              "invertmatch": "true",
              "status": 400
            }
          ]
        },
        {
          "PolicyName": "ExtAuth",
          "Attributes": [
            {
              "name": "hmac-auth"
            }
          ]
        }
      ]
    }
  ]
}

0 个答案:

没有答案