Amazon Connect – Access JSON Path Keys with Fullstops/Periods/Other Special Characters

Another small one, but potentially of use to others.

Whilst working with Lambda functions I am across a response that had a period in the JSON key, like key.subkey. This is not a nested JSON value, rather the key name, like follows.

{ 
   "body": { 
      "key.subkey": "value 
   }
}

It is worth mentioning at this point this is perfectly valid, as JSON has no real enforcement on which characters are and are not allowed in keys, but you could well replace this with any other special character.

Any regular Connect users will immediately spot the issue with this. If you try to index the JSON path in the standard way, with $.External.body.key.subkey you will always get a null value, as it is looking for an object like the following:

{ 
   "body": { 
      "key": {
            "subkey": "value 
      }
   }
}

The second thought might to simply enclose the name in quotation marks (single or double, take your pick). Unfortunately, this causes Connect to just render the value of . then the item in the quotation marks, so you’d end up with .'key.subkey' as an output, which obviously isn’t helpful.

Long story short, you need to actually look into the JSON Path to find out to resolve this. This means using a string like the following:
$['External']['body']['key.subkey']
Note that its important that you use single quotes here, and not double, otherwise you’ll end up with similar issues of printing out substrings.

To make access attributes easier (such as for “Check Contact Attributes”) it may be desirable to set the needed value into a Flow Attribute, this will assist with accessing the value (of course, it is worth remembering that means the value will only be flow level scoped).