I’m not entirely clear on what you’re trying to do, but I think there are two things at play
-
%asset_data_metadata%
contains a lot more than just key:value
- since you’re using
%asset_children
whatever you do to transform the metadata bit will need to be done per-child
To reformat the asset_data_metadata
object to something simpler I’d use Object.entries
to change it from {key:value}
to [[key,value]]
, then run .map
over it to reduce the value down to just the bit I want, then Object.fromEntries
to change it back to an object
Here’s an example that uses the same keyword as yours, prints out the original and then the cut-down version that I think you’re after.
<pre><script runat="server">
var list = %globals_asset_children:4033^as_asset:asset_name,asset_assetid,asset_url,asset_published_short,asset_data_metadata%;
print('---Original---\n\n')
print(JSON.stringify(list,null,2));
print('\n\n---Cut down---\n\n')
list.forEach(child => {
child.asset_data_metadata = Object.fromEntries(Object.entries(child.asset_data_metadata).map(k => [k[0],k[1].value]));
})
print(JSON.stringify(list,null,2));
</script></pre>
which spits out
---Original---
[
{
"asset_name": "Test",
"asset_assetid": "4029",
"asset_url": "http://matrix.local/forum13132/listfolder/test",
"asset_published_short": "1970-01-01",
"asset_data_metadata": {
"Related": {
"value": "4022",
"fieldid": "4024",
"type": "metadata_field_related_asset",
"is_contextable": true,
"default_value": false,
"use_default": true
},
"Select": {
"value": "a",
"fieldid": "4025",
"type": "metadata_field_select",
"is_contextable": true,
"default_value": false,
"use_default": true
}
}
},
{
"asset_name": "OtherChild",
"asset_assetid": "4034",
"asset_url": "http://matrix.local/forum13132/listfolder/otherchild",
"asset_published_short": "1970-01-01",
"asset_data_metadata": {
"Related": {
"value": "4021",
"fieldid": "4024",
"type": "metadata_field_related_asset",
"is_contextable": true,
"default_value": false,
"use_default": true
},
"Select": {
"value": "b",
"fieldid": "4025",
"type": "metadata_field_select",
"is_contextable": true,
"default_value": false,
"use_default": true
}
}
}
]
---Cut down---
[
{
"asset_name": "Test",
"asset_assetid": "4029",
"asset_url": "http://matrix.local/forum13132/listfolder/test",
"asset_published_short": "1970-01-01",
"asset_data_metadata": {
"Related": "4022",
"Select": "a"
}
},
{
"asset_name": "OtherChild",
"asset_assetid": "4034",
"asset_url": "http://matrix.local/forum13132/listfolder/otherchild",
"asset_published_short": "1970-01-01",
"asset_data_metadata": {
"Related": "4021",
"Select": "b"
}
}
]