How to set JSON as a data source to a Combo Box in Power Apps
I was creating a form mockup in Power Apps. Since it was a mockup, I didn't want to connect to any data source. One of the fields in the form was Combo Box. When you add this control, by default the Items property is set to ComboBoxSample. When you run the app, the combo box shows values such as Item 1, Item 2,... Item 15. For the purpose of the mockup, I wanted to put some other values to this control. However, creating a table and connecting to that data source is over engineering for a mockup. Hence, I wanted to create a sample JSON object and assign that to Items property.
This is where things got little tricky. I tried forming JSON text something like below (the same example given in Microsoft website).
[
{ "id": 1, "name": "Option 1"},
{ "id": 2, "name": "Option 2"},
{ "id": 3, "name": "Option 3"}
]
When I put this in Items property, it showed errors like below for the string part "id":
Unexpected characters. The formula contains 'id' where 'Ident' is expected.
Unexpected characters. The formula contains 'id' where 'Colon' is expected.
Expected colon. We expect a colon (:) at this point in the formula.
I tried using ParseJSON function but that didn't solve the issue. There are many examples in the net where JSON object is assigned to a variable in Power Automate flow and then it is set to a control. All I wanted was a direct connection to a JSON object and that serves my purpose.
In fact, I spent quite a time in figuring out what was missing. After trial and error, I found this simple solution to address this problem. I had to remove double quotes in the JSON string as shown below.
[
{ id: 1, name: "Option 1" },
{ id: 2, name: "Option 2" },
{ id: 3, name: "Option 3" }
]
Do note I have removed double quotes for id and name. This solved the issue! I could directly put this string in Items property and it worked! Even after putting this formula, if the combo box is not showing values, do make sure to click Edit Fields for the control and select "name" for "Primary text" property.
Comments