'Adaptive Card: What is the best way to display an arbitrary JSON object?

  • I'd like to generate an adaptive card that contains an arbitrary JSON object inside.
  • I anticipate that the JSON object will be shallow.
    • Maybe it will contain just a list of key-value pairs.
  • But I won't know the structure of that JSON object until runtime.
    • For this reason, I can't templatize this portion of the adaptive card.

  • It would be ideal if I could embed the JSON inside of a codeblock, but I don't know if that's supported.
  • Alternatively, I'd be willing to embed the JSON inside of a monotype textbox.

Any help would be greatly appreciated.



Solution 1:[1]

  1. Embedding JSON inside of a codeblock isn't yet supported, although that would indeed be a great way to solve this use case.
  2. A template isn't necessarily static or fixed. If you're planning to "expand" your template with the AdaptiveCards.Templating NuGet package for instance, you'll have the occasion to load the template into memory. At this time, you can mutate the template according to the incoming JSON at runtime. This isn't an ideal solution, but it is a way to accommodate a truly arbitrary JSON object.
  3. If, on the other hand, if you anticipate that the JSON object will merely be a list of key-value pairs, you can use data binding.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1