How can i patch nested json request

i need to patch config/ttsmessages/welcome/message from the following body , how can i do it ?

{
  "name": "service created",
  "mainCountryCode": "fr",
  "config": {
    "ttsMessages": {
      "welcome": {
        "speak": [
          {
            "message": "Welcome to Alias Revamp",
            "voice": 1,
            "gender": "FEMALE",
            "language": "en"
          }
        ]
      },
      "wait": {
        "speak": [
          {
            "message": "Dear customer please wait",
            "voice": 1,
            "gender": "FEMALE",
            "language": "en"
          }
        ]
      },
      "warning": {
        "speak": [
          {
            "message": "Oups, quelque chose n'a pas fonctionn dirait-on. Veuillez-nous en excuser, nous allons raccrocher. Au revoir!",
            "voice": 1,
            "gender": "MALE",
            "language": "fr"
          }
        ]
      },
      "inboundCall": {
        "speak": [
          {
            "message": "someone is calling your number",
            "voice": 1,
            "gender": "FEMALE",
            "language": "en"
          }
        ]
      },
      "outboundCall": {
        "speak": [
          {
            "message": "",
            "voice": "1",
            "gender": "FEMALE",
            "language": "en"
          }
        ]
      },
      "voicemail": {
        "speak": [
          {
            "message": "8ii",
            "voice": "1",
            "gender": "FEMALE",
            "language": "FR"
          }
        ]
      },
      "pincode": {
        "speak": [
          {
            "message": "hi%CODE%",
            "voice": 1,
            "gender": "FEMALE",
            "language": "fr"
          }
        ]
      },
      "clickToCallConfirmation": {
        "speak": [
          {
            "message": "hi",
            "voice": 1,
            "gender": "MALE",
            "language": "fr"
          }
        ]
      },
      "clickToCallFailure": {
        "speak": [
          {
            "message": "Bienvenue sur la messagerie.",
            "voice": 1,
            "gender": "MALE",
            "language": "fr"
          }
        ]
      }
    },
    "pickupInboundCall": false,
    "pickupOutboundCall": false,
    "inboundCallFlow": "TWO_STEPS",
    "ringingTimeout": {
      "inboundCall": 40,
      "outboundCall": 5
    },
    "pincodeValidationMaxTries": 3,
    "pincodeValidationMaxDelay": 30,
    "sip": {
      "inboundCallPresentedUri": {
        "type": "CALLER"
      },
      "addDiversionHeader": false
    }
  }
}

The first question would be:

Where do you have that json and in which format do you have it.

  1. you may have it as string in a Robot Framework variable
  2. you may have it in a file
  3. you may have it already as a dictionary
1 Like

The easiest way to do that is probably in a custom Python Library. In Python, loading a json object / string the (response.json()) results in a dict (in most case, it can also be a list). In case of a dict, you can simply do an .update() on the response dict to add / update the desired key values. Something like this:

response_json = response.json()
response_json.update({"mainCountryCode": "nl"})

If you have the entire patch as a dict, I’m not entirely sure response_json_update(**patch) will update recursively without overriding, but it may work out of the box. If not, there’s probably packages available to get that done.