Accessing object keys with spaces in OpenAF templates (Handlebars)
If you ever came across a similar JSON map to this:
{
"Update" : "2019-08-24T12:34:56.789Z",
"Stats" : {
"Memory stats": {
"Free memory" : 1234,
"Total memory": 5678
}
}
}
You know that to access JSON map keys with space in javascript you need to do something like this:
print("Update: " + myMap.Update);
print("Free mem: " + myMap.Stats["Memory stats"]["Free memory"] + "MB");
To replicate in a HandleBars template you would write for the first line:
Update: {{Update}}
But, how to access the keys with space in HandleBars?
Update: {{Update}}
Free mem: {{Stats.[Memory stats].[Free memory]}}MB
So the final code would be, for example:
tprint("Update: {{Update}}", myMap);
tprint("Free mem: {{Stats.[Memory stats].[Free memory]}}MB", myMap);