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

Parsing Json using Data contract classes in X++

(1) ShareShare
ReportReport
Posted on by 20
Hi ,
 
Could you please help me with parsing the below json structure using datacontract classes.
 
{
"InsertTable": [
        {
            "name": "ZCK_CDS_RATES",
            "data": [
                [
                    {
                       "name": "PARTNR",
                        "type": "VALUE",
                    },
                   {
                       "name": "PARTNR",
                        "type": "VALUE",
                     },
               ],
              [
                    {
                       "name": "PARTNR",
                        "type": "VALUE",
                    },
                   {
                       "name": "PARTNR",
                        "type": "VALUE",
                     },
               ]
            ]
       }
  ]
}
 
 
 
C# code 
public class Inserttable
{
public string name { get; set; }
public Datum[][] data { get; set; }
}
  • Martin Dráb Profile Picture
    241,656 Most Valuable Professional on at
    Which version of AX are you using?
     
    You showed a piece of C# code. Does it mean that you want to parse the data in C#?
     
    If your question is about F&O (and not AX), not that the system can do the parsing for you. You'll just need to create correct contract classes (with DataContract and DataMember attributes etc.).
  • Indra sena Profile Picture
    20 on at
     
    It's F&O, the C# code is provided only for reference(created through paste special ).
     
    Challenge i am facing is when creating a data contract classes in x++  for list inside another list.
    "data":[
                 [
                           {},
                           {},
                 ],
                  [
                           {},
                           {},
                 ]
    ]
     
  • Suggested answer
    Martin Dráb Profile Picture
    241,656 Most Valuable Professional on at
    Moved from Dynamics AX forum.
     
    As I said, you don't need to implement parsing (as the title suggest), you just need to define the contracts correctly. You'll need two contracts; the outer will hold a list of instances of the other contract. You'll use AifCollectionType attribute to define the type of data in the list.
     
    For example:
    [DataContract]
    class MainContract
    {
        str name;
        List items;
    
        [DataMember('name')]
        public str parmName(str _name = name)
        {
            ...
        }
        
        [
            DataMember('data'),
            AifCollectionType('_items', Types::Class, classStr(ItemsContract)),
            AifCollectionType('return', Types::Class, classStr(ItemsContract))
        ]
        public List parmItems(List _items = items)
        {
            ...
        }
    }
  • Indra sena Profile Picture
    20 on at
     
    Thanks for the reply , i've created below data contract classes but the function "parmListofInsertTableData" is returning null.
     
    Not sure what i am missing / doing wrong here.
     
    [DataContract]
    class ELTInsertTableDataContract
    {
        private str     name;
        private List    insertTableDataListDataContract;
        [DataMember("name")]
        public str parmName(str _name = Name)
        {
            name = _name;
            return name;
        }
        [DataMember("data"),
            AifCollectionType('_insertTableDataListDataContract',Types::Class,classStr(ELTInsertTableDataListDataContract)),
            AifCollectionType('return',Types::Class,classStr(ELTInsertTableDataListDataContract))]
        public list parmListofInsertTableData(list _insertTableDataListDataContract = insertTableDataListDataContract)
        {
            insertTableDataListDataContract = _insertTableDataListDataContract;
            return insertTableDataListDataContract;
        }
    }
    -----------------------------------------------------------------------------------------------------
    // for the fist array in data(key from json)
     
    [DataContract]
    class ELTInsertTableDataListDataContract
    {
        private List lisfOfInsertTableData;
        
        [DataMember,DataCollection(Types::Class,classStr(ELTInsertTableDataDataContract))]
        public list parmlistOfInsertTableData(list _lisfOfInsertTableData = lisfOfInsertTableData)
        {
            lisfOfInsertTableData = _lisfOfInsertTableData;
            return lisfOfInsertTableData;
        }
    }
    --------------------------------------------------------------------------------------------------
    [DataContract]
    class ELTInsertTableDataDataContract
    {
        private str name,type;
     
        [DataMember("name")]
        public str parmName(str _name = Name)
        {
            name = _name;
            return name;
        }
        [DataMember("type")]
        public str parmtype(str _type = type)
        {
            type     = _type;
            return type;
        }
    }
  • Suggested answer
    Martin Dráb Profile Picture
    241,656 Most Valuable Professional on at
    Aha, I didn't notice that you wanted an array of arrays. I don't think you can do that; the values in a list may be either primitive ones or data contracts.
     
    If you can't influence the format, you should transform it before calling the custom service.
     
    When you test your code (by populating the contract and returning it from a custom service), you'll see that it produces something like this:
    {
        "name": "abc",
        "data": [
            {
                "parmlistOfInsertTableData": {
                    "name": "xyz",
                    "type": "type1"
                }
            }
        ]
    }

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 239 Super User 2026 Season 2

#2
Aayush Tiwari Profile Picture

Aayush Tiwari 221

#3
Subra Profile Picture

Subra 166 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans