Is there a way to create a dictionary with dynamic keys?

I’m trying to create a dictionary with dynamic keys.

{% do locationDetails.update({ "{{childTableMarketKey}}": childTableDetails[0] }) %}

doesn’t seem to work. What I’m trying to achieve is the same as doing this in javascript

object[key] = value;

Is there a way to achieve this in Hubspot?

Remember Hubl (Jinjava) is just a wraper around java. HubSpot might not expose it or tell you that you can… But, you can. And if you can’t… take the nuclear option :wink:

{% do mydictionary.put(key, value) %}
{# If you want to put all keys from another dict.... #}
{# You've already seen update.... #}
{% do mydictionary.putAll(otherDictionary) %}
{# If you want to iterate updating or override keys #}
{% for ... in ... %}
 {% do mydictionary.put(key, transmorgifiedValue) %}
{% endfor %}
{# If you want to remove a key... #}
{% do mydictionary.remove(key) %}

Have fun: ForwardingMap (Guava: Google Core Libraries for Java 19.0 API)

This works for basically any more complex op you need dealing with any native object type… But, if you need more complex functions like trigonometric functions etc you’re SOL unless you want to do taylor series approximations in HubL… I use that as ana example becuase I’ve done it and it’s not fun! If you play around with this I’ll save you a headache.
You can’t do proxy dicts such as:

{% set proxyDict = {
 "key": nameOfMacroFucntion
%}

For… reasons. Puzzle for you to solve.

I’m assuming to get the value using a dynamic key I need to do something like this right?

{% do mydictionary.get(key) %}

However you want. By key name, brackets, or methods.
It’s only mutating state that requires trickery. Once it’s in there… Just grab it.