Lava Filters - AsDictionary
Category:Arrays
Description:Takes an object and creates a new dictionary that contains the same keys and values. If the input is already a dictionary, then the input is returned without change.
Input:
Lava: {% sql %}
SELECT [Id], [Name] FROM [Campus]
{% endsql %}
{% assign items = null %}
{% for result in results %}
{% assign item = result | AsDictionary %}
{% assign idKey = item.Id | ToIdHash %}
{% assign item = item | AddToDictionary:'IdKey',idKey | RemoveFromDictionary:'Id' %}
{% assign items = items | AddToArray:item %}
{% endfor %}
{{ items | ToJSON }}
Output: [
{
"Name": "Main Campus",
"IdKey": "QN8mrQBVyn"
},
{
"Name": "South-Inactive",
"IdKey": "OX9mQWPQo8"
}
]