How to convert nested dynamic objects into readable data when building email custom tokens without using strongly type models?

Here's my data:

  "Fruits":[{"Number":"111", "Name":"Apple"}, {"Number":"112", 

and I'm using DeserializeObject

dynamic data = JsonConvert.DeserializeObject<ExpandoObject>(result);

then pass it to the method below:

    protected virtual Dictionary<string, object> BuildCustomTokens(dynamic data)
        var customTokens = new Dictionary<string, object>();
        if(data != null)
            foreach (var dataField in data)
              customTokens.Add($"form_{dataField.Key}", dataField.Value);      

        return customTokens;

It is working, but for array of objects like "Fruits", it is formatted as objects. Sample Email: enter image description here

  • I'd argue this isn't directly an EXM or Sitecore question and more of a general .NET question on how to use dynamic objects. Jul 14 '19 at 13:26
  • @PeteNavarra this one is solved. And you're right, this is a .NET Question. What would i do to this question?
    – ZQuiray
    Jul 15 '19 at 9:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.