Skip to content

[Content request]: Add FAQ: How do I prevent empty Adaptive Cards when an array property is empty? #64

@ChetanSharma-msft

Description

@ChetanSharma-msft

Issue type

Update to existing content

Details

FAQ: How do I prevent empty Adaptive Cards when an array property is empty?
Problem
Adaptive Cards render blank when the array (e.g., recommendations) in the API response is empty.
Example API Response

JSON{  "llmAnswer": "",  "recommendations": [],  "llmFollowUpMessage": ""}Show more lines
Cause

recommendations array has no items.
Template lacks conditional logic for empty arrays.

Solution

Bind to the correct array property:
JSON"data_path": "$.recommendations"Show more lines

Iterate over objects only when data exists:
JSON{ "type": "ColumnSet", "$data": "${$root}", "$when": "${title != null && title != ''}"}

Add fallback text for empty arrays:
JSON{ "type": "TextBlock", "text": "No recommendations available", "$when": "${$root.length == 0}"}

Best Practice
Always validate data_path and include $when conditions for empty arrays to avoid blank cards.

Doc can be updated:
https://learn.microsoft.com/en-us/microsoft-365-copilot/extensibility/api-plugin-adaptive-cards

Subject matter expert

Laura Graham

Priority

P3 - The request is medium priority and is not blocking.

Target publish date

No response

Approximate size of the work item

Small - The request will take one day to complete.

Additional details

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions