Search code examples
jsonibm-watsonwatson-conversationwatson

Watson Conversation - Retrieving specific data from nested context


I'd like the interaction to look like this:

  • Bot: Name a country
  • User: Mexico
  • Bot: The population of Mexico is approximately 120M.

For now, I've got the populations hard-coded and looks like below:

{
  "context": {
    "inputcountry": "<?@Country?>",
    "populations": {
      "USA": "300M",
      "Mexico": "100M",
      "Japan": "127M"
    }
  },
  "output": {
    "text": {
      "append": true,
      "values": [
        "The population of $inputcountry is approximately $populations.$inputcountry"
      ]
    }
  }
}

What is the syntax to provide the specific population number using the user input as the identifier/lookup?

Using $populations.$inputcountry shown above returns

{"USA": "300M","Mexico": "100M","Japan": "120M"}.Mexico

Solution

  • Try <? $populations.get($inputcountry) ?> - that should do the trick.