Groovy скрипт слияния json строка в json файл - PullRequest
0 голосов
/ 15 февраля 2020

Мы хотим написать groovy скрипт, который может анализировать JsonfileA, извлекать данные и объединяться в JsonfileB. У нас есть следующий JsonfileA. нам нужно вытащить данные из узла «пути». Мы используем JsonSlurper для синтаксического анализа файла и чтения данных из узла «пути»

JsonfileA
==========
{
  "swagger": "2.0",
  "basePath": "/abc",
  "paths": {
    "/api/abcBusiness/cussShipTos": {
      "post": {
        "tags": [
          "abcBusiness"
        ],
        "operationId": "cussShipTos",
        "produces": [
          "application/json"
        ]
      }
    }
  },
  "definitions": {
    "cussShipTosInput": {
      "type": "object",
      "properties": {
        "geo": {
          "type": "string"
        }
      }
    }
  }
}

Мы имеем JsonfileB, мы хотим добавить данные узла «пути» из JsonfileA в узел «пути» JsonfileB, и мы хотим сохранить JsonfileB

JsonfileB
===========
{
  "x-generator": "NSwag v13.0.5.0 (NJsonSchema v10.0.22.0 (Newtonsoft.Json v11.0.0.0))",
  "swagger": "2.0",
  "paths": {
    "/api/Bancco/JobSpec": {
      "post": {
        "tags": [
          "Bancco"
        ],
        "operationId": "JobSpec"
      }
    }
  },
  "definitions": {
    "cusatestResponse": {
      "type": "object",
      "description": "Model class object with the values that would be sent as response from the Service",
      "properties": {
        "TransactionDetail": {
          "$ref": "#/definitions/cusatestTransactionDetail"
        }
      }
    }
  }
}

После добавления JosonfileA в JsonfileB под узлом "paths" результат должен выглядеть следующим образом. Ожидаемый результат

  "x-generator": "NSwag v13.0.5.0 (NJsonSchema v10.0.22.0 (Newtonsoft.Json v11.0.0.0))",
  "swagger": "2.0",
  "paths": {
    "/api/Bancco/JobSpec": {
      "post": {
        "tags": [
          "Bancco"
        ],
        "operationId": "JobSpec"
      }
    },
    "/api/abcBusiness/cussShipTos": {
      "post": {
        "tags": [
          "abcBusiness"
        ],
        "operationId": "cussShipTos",
        "produces": [
          "application/json"
        ]
      }
    }
  },
  "definitions": {
    "cusatestResponse": {
      "type": "object",
      "description": "Model class object with the values that would be sent as response from the Service",
      "properties": {
        "TransactionDetail": {
          "$ref": "#/definitions/cusatestTransactionDetail"
        }
      }
    }
  }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...