Skip to main content

Hello,

I have just attended the Dev meet up group and one of their suggestions for JSON files was to use it as a config file.

My bot is creating zendesk tickets and the dev environment has different custom field values than the prod environment. So the JSON config would be a great way of storing this data.

I’m currently doing this with XML, reading it every single time and setting all variables (its a lot of them).

My though was that the new JSON package could safe some time since it allows the JSON to dictionary action. I would only reference the dictionary with the key when needed and not having to create and fill a bunch of variables prior.

So here is the JSON sample:

{
"Environment": "Dev",
"Zendesk":
{
"URL-Prod": "Prod Environment",
"URL-Dev": "Dev Environment",
"custom_fields":
{
"market-Prod": "5678",
"market-Dev": "1234"
}
}
}

 In AA I start a JSON session to the control room file. I then convert the JSON to dictionary and select multiple variables. One will be a string called environment and one will be a dictionary call zendesk.

If I now create a message box and display $Environment$ I will receive ‘Dev’. I can also get the items from the dictionary $Zendesk{“URL-Dev”}$

My Problem:

How do I get the dictionary to be dynamic based on the environment variable?

Something like this  $Zendesk{“URL-”$Environment$}$

This would allow me to only switch the Environment in the file and I would not have to declare all variables since I would use a dictionary.

 

Try this package, it will convert your json string to dictionary recursively: https://botstore.automationanywhere.com/bot/json-parser-package

You can structure your JSON better, then you do not need to pass environment variable string for every key:

{
"Prod": {
"Zendesk": {
"URL": "Prod Environment",
"custom_fields": {
"market": "5678"
}
}
},
"Dev": {
"Zendesk": {
"URL": "Dev Environment",
"custom_fields": {
"market": "1234"
}
}
}
}

This package has useful actions related to reading config from different sources: XML, JSON, CSV, Excel
https://botstore.automationanywhere.com/bot/bot-framework-package

you can decide which node to parse(dev/prod) at runtime depending upon environment and keys can remain same in the later code.


Hi Bot Dev,

I’m using the json-parser-package to convert my JSON to dictionary.

If I’m restructuring the JSON like you have it (I thought about that as well) wouldn't I still have two different dictionaries that I need to reference or would you read both and then use an if statement to determine which environment I’m in and set the correct dictionary as the one to use?

I’m still a little unclear on your approach.

Thanks for the bot-framework-package. Looks interesting. I will take a look at this as well.


 


Reply