web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Parsing Dynamic JSON without External Assemblies

(0) ShareShare
ReportReport
Posted on by

Hi I am trying to parse a JSON response that contains dynamic keys and values. Below is an example of the JSON I am parsing:

 {
  "data": [
    {
      "Id": "XXXXXXXXXXXXXXXXXXXXXXXX",
      "IsActive": true,
      "DateCreated": "2017-11-09T00:01:49.827Z",
      "DateModified": "2017-11-09T00:01:49.827Z",
      "IsDeleted": false,
      "Uid": "XXXXXXXXXXXXXXXXXXXXXXXX",
      "CustomObject": {
        "customdata1": " Store my customdata1 value",
        "customdata2": " Store my customdata2 value"
      }
    }
  ],
  "Count": 1
}

Where CustomObject is the dynamic object that I am trying to parse. Another option for me is to simply convert the value of CustomObject into a string, but I am also unable to find a method for that.

*This post is locked for comments

I have the same question (0)
  • PhuocLV Profile Picture
    347 on at

    I use this [View:https://github.com/facebook-csharp-sdk/simple-json.git]

  • Suggested answer
    Temmy Wahyu Raharjo Profile Picture
    2,916 on at

    Hi,

    For this requirement usually I will use this helper:

    /// <summary>

           /// Deserialize json string to an instance of type T using DataContractJsonSerializer.

           /// </summary>

           public static string ToJson<T>(this T obj)

           {

               using (var stream = new MemoryStream())

               {

                   var serializer = new DataContractJsonSerializer(typeof(T));

                   serializer.WriteObject(stream, obj);

                   return Encoding.UTF8.GetString(stream.ToArray());

               }

           }

           /// <summary>

           /// Serialize from an instance of type T to json string using DataContractJsonSerializer.

           /// </summary>

           public static T FromJson<T>(this string json)

           {

               using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(json)))

               {

                   var serializer = new DataContractJsonSerializer(typeof(T));

                   return (T) serializer.ReadObject(stream);

               }

           }

    This helper will help you to change your object from list data/object to json string (ToJson) and FromJson will help you to parse from string into object.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans