Using a JSON file with the Dropdown widget on the Metadata Schema


Adobe
Have to use where you need to setup a metadata schema with a dropdown widget where the options needed to come from a JSON file? Keep on reading…
First, the JSON file.
The JSON file needs to follow the same structure as below.
{
“options”: [
{
“value”: “en-gb”,
“text”: “English-United Kingdom”
},
{
“value”: “en-us”,
“text”: “English-United States”
},
{
“value”: “fr-ca”,
“text”: “French-Canada”
},
{
“value”: “fr-fr”,
“text”: “French-France”
},
{
“value”: “de-de”,
“text”: “German-Germany”
},
{
“value”: “es-mx”,
“text”: “Spanish-Mexico”
},
{
“value”: “es-es”,
“text”: “Spanish-Spain”
}
]
}

There needs to be an “options” array and each element in the array needs to have a “value” and a “text”. The “text” value is what is displayed to the end user and the “value” value is what is saved in JCR.
Second, where to store the file.
You can upload this file to AEM as an Asset or upload it somewhere as a nt:file. Where its uploaded will define how the widget on the metadata schema needs to be configured.
Lastly, how to configure the widget.
The dropdown widget on the metadata schema lets you define a “JSON Path” property. This property needs to point to the nt:file node of the JSON file.
What does this mean?
If you have uploaded the JSON file as an Asset, this value needs to be set to the original rendition of the asset. For example /content/dam/myproject/myfile.json/jcr:content/renditions/original. If you have upload this file as an nt:file, the path would be something like /etc/myconfigurations/myfile.json.

At the time of writing this blog, there is a known issue where if the content of the JSON file changes, you need to open the schema again and hit save for the new changes to populate.