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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

JSON deserialization to .net class

(3) ShareShare
ReportReport
Posted on by 21
Hello, everyone!
 
I'm creating an integretion between vacancy publishi service(VPS) and D365 recruitment  module. VPS has API and it uses json for communication/data transfer.
 
I wanted to try to use paste special  option for generating clases from json.
 
Basically what I have is json array likes this (just an example)

[
{
“Date”: “2020-06-04T13:15:24”,
“applicationId”: 3231,
“email”: “dwight.k.schrute@dundermifflin.com”,
“employerId”: 213,
“files”: [
{
“fileId”: “c82e2b20-2c96-4dd2-96bf-b67d99c58340”,
“fileUrl”: “https://cv.lv/api/v1/applications-service/application/3231/file/c82e2b20-2c96-4dd2-96bf-b67d99c58340”
}
],
“firstName”: “Dwight K.”,
“lastName”: “Schrute”,
“answers”: [
{
“fileUrl”: “string”,
“externalQuestionId”: “Some random text”
}
]
}
]
Then I created .net class method from this json using paste special
 
public class Rootobject
{
public List Applications { get; set; }
}

public class Applicants
{
public DateTime Date { get; set; }
public int applicationId { get; set; }

public string email { get; set; }
public int employerId { get; set; }
public List files { get; set; }
public string firstName { get; set; }
public string lastName { get; set; }
public List answers { get; set; }
}

public class File
{
public string fileId { get; set; }
public string fileUrl { get; set; }
}

public class Answer
{
public string fileUrl { get; set; }
public string externalQuestionId { get; set; }
}

I’m having trouble deserializing it in D365.
Found 'Adria Ariste Santacreu' blog (deserialize xml) doing the same using xml, but I not able replicate it using json.
 
Maybe someone has done it before and can help with it.
 
Maybe deserialization needs to be done in .net class and then just return the instance of that class?
 
Any help appreciated.
 
I have the same question (0)
  • Martin Dráb Profile Picture
    239,029 Most Valuable Professional on at
    Which D365 application is it about? D365 HR?
     
    Talking just about D365 isn't sufficient, because it's a brand used for several product. Because they use different architecture, programming languages etc., the solution for different D365 may be very different.
     
    If you've created a C# class library that you'll call from X++, you can use Json.NET to do the parsing. It's very simple:
    JsonConvert.DeserializeObject<Rootobject>(json);
    It's easier to do in your C# project than in X++, because you can utilize the generic method.
  • Maris Sausins Profile Picture
    21 on at
    Thank you Martin, for fast reply!
     
    I'ts for D365 FO and D365 HR.
     
    Previously I tried using System.Text.Json.JsonSerializer::Deserialize, but without luck.
     
    If I understand it correctly I should do something like this in X++: 
    DllLibraryJsonParser.RootObject  rootObject = new DllLibraryJsonParser.RootObject();
    List  applicationsListCSharp = new List(Types::Class);
    
    rootObject  = Newtonsoft.Json.JsonConvert::DeserializeObject(jsonStr);
    applicationsListCSharp = rootObject.get_Applications();
     
    And if doing the deserialization in .net
    public static List<Applicants> DeserializeApplicants(string json)
    {
        return JsonConvert.DeserializeObject<List<Applicants>>(json);
    }
    
    and then in X++
    
    List  applicationsListCSharp = new List(Types::Class);
    
    applicationsListCSharp = DllLibraryJsonParser::DeserializeApplicants(jsonStr);
     
    Does it look correct?
     
    Haven't tried yet, but when I will, I'm going to post here the result.
     
    What would You reccomend? Perform deserialization in X++ or .Net class.
     
    If this works, it's going to be much faster than creating data contract classes in X++ :)
     
  • Suggested answer
    Martin Dráb Profile Picture
    239,029 Most Valuable Professional on at
    I would use what I suggested:
    JsonConvert.DeserializeObject<Rootobject>(json);
    But if wish, you can deserialize it as the list of application objects as well. The problem is that X++ (almost) doesn't support generics, therefore exposing the generic list rather than Rootobject will make your life a bit more complicated.
     
    This code is completely wrong:
    List  applicationsListCSharp = new List(Types::Class);
    applicationsListCSharp = DllLibraryJsonParser::DeserializeApplicants(jsonStr);
    The main problem is that the type of the variable doesn't match the return value of the method. The method returns and instance of System.Collection.Generic.List<T> class, while your variable is the X++ List (Dynamics.AX.Application.List or something like that).
     
    If you return Rootobject, declare the variable as Rootobject plus the namespace, e.g. MyLibrary.Rootobject. You can avoid specifying the namespace by utilizing the using statement on the top of the class (using MyLibrary;). If you keep returning the generic list, you can try the same syntax as in C# (it's possible, but not perfect), use var instead of the type or declare it as System.Collections.IEnumerable, which still allows you to iterate the list. Each has its pros and cons (and yet other options exist).
     
    Also, there is no point assigning the value of applicationsListCSharp on the first line if you immediately overwrite it on the next line.
     
    I prefer doing it the same way - utilizing JsonConvert in a C# library.
     
    Moved from Integration, Dataverse, and general topics forum to Finance | Project Operations, Human Resources, AX, GP, SL forum.
     

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!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 617

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 461 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 298 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans