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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Convert Json to X++ and How to deserialize it?

(2) ShareShare
ReportReport
Posted on by 89

Hello 

Can you please help me understand, how I can write code in F&O (X++) to convert below C# code (JSON) to X++ and deserialize it. Also how I can loop through all the multiple records in Json to assign/populate value from json record to AX table field.?

I know we can write a contract class, but Im confused whether to write multiple contract class (as we wrote in C# ?)

public class Project
{
public int id { get; set; }
public string name { get; set; }
}
public class Entry
{
public double hours { get; set; }
public string notes { get; set; }
public Project project { get; set; }
public object invoice { get; set; }
}

public class Root
{
public List<Entry> entries { get; set; }
}

I have the same question (0)
  • Verified answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi RahulD365,

    You can take a look at method FormJsonSerializer::deserializeCollection and use cross-references to check how it's used for list object deserialization.

    Steps for conversions

    1. Create data contract classes in x++ for Project and Entity (docs.microsoft.com/.../walkthrough-exposing-an-x-class-as-a-data-contract )

    2. Use FormJsonSerializer::deserializeCollection to deserialize json to list of Entry objects

    The only field which can cause issues is Entry.invoice because of object type. Do you know what is stored in that field?

  • Suggested answer
    Martin Dráb Profile Picture
    238,599 Most Valuable Professional on at

    Another approach is not converting it to X++   at all - you can call C# libraries from X++, therefore your C# code could deserialize the file and simple return a Root object with the data, which you'll use in X++ for whatever you need.

    By the way, please use Insert > Insert Code (in the rich formatting view) to paste source code. Look at the difference:

    public class Project
    {
        public int id { get; set; }
        public string name { get; set; }
    }
    
    public class Entry
    {
        public double hours { get; set; }
        public string notes { get; set; }
        public Project project { get; set; }
        public object invoice { get; set; }
    }
    
    public class Root
    {
        public List entries { get; set; }
    }

     

  • RahulD365 Profile Picture
    89 on at

    Thanks Martin, Can you please help me with any sample code? Like I want to learn, how we can convert it in C# and loop/iterate to get the data?

  • RahulD365 Profile Picture
    89 on at

    Thanks Sergei! Appreciate it!

  • Martin Dráb Profile Picture
    238,599 Most Valuable Professional on at

    I'm a bit confused. What do you mean by "to convert it in C#"? You used "to convert" when talking about rewriting C# to X++, but "converting it in C#" doesn't make sense in such a context. Do you mean how to deserialize JSON files in C#?

  • RahulD365 Profile Picture
    89 on at

    I meant to say - How I can retrieve the values of the fields when we deserialize the string(response) and how can I loop through each elements in the Json?

  • Verified answer
    Martin Dráb Profile Picture
    238,599 Most Valuable Professional on at

    When you deserialize the string, you'll get objects. You won't look through anything in the JSON string; you'll loop through elements of the List object.

    For example:

     

    MyLibrary.Root root = MyLibrary.MyClass::GetData();
    System.IEnumerator entryEnumerator = root.entries.GetEnumerator();
    while (entryEnumerator.MoveNext)
    {
        MyLibrary.Entry entry = entryEnumerator.Current;
    }

     

    By the way, your code doesn't respect C# naming conventions. Property names (such as entries) should start with a capital letter.

    Note that I thought you already have C# and you know how to use, that's why I suggested you could use it directly instead of rewriting it to X++. If it's not the case, using X++ will probably be better for you.

  • harshilsavaj Profile Picture
    4 on at
     
    I have created a tool which will reduce the labour work of creating contract classes from a raw JSON. 
     
    search : dynamicspilot.online 
     
    Attached is the image for reference.
     
    This tool will convert most of the raw json to X++ contract classes. If you find this tool helpful kindly share it with others. Thank you all. 
     
    JSON String to X++ Contract Classes  Free Online Tool.png

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

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
André Arnaud de Calavon Profile Picture

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

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 289 Super User 2026 Season 1

#3
Martin Dráb Profile Picture

Martin Dráb 232 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans