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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Json deserialize in D365FO

(0) ShareShare
ReportReport
Posted on by

Hi Folks,

Trying to deserialize JSON in D365FO, which has multiple tags.

Created data contract class to deserialize each tags, But still PackstructureEntity & PalletEntity so on can't deserialize with all values.

Sample Json:

{

              "HEADERENTITY": {

                             "ID": "000001947",

                             "BLNUMBER": "tret",

                             "BOOOKINGNUMBER": 546575tststt7,

                             "LINEENTITY": [

                                           {

                                                          "ID": "000001947",

                                                          "LINENUM": 1,

                                                          "ORDERLINEITEMID": "8M0073789"

                                           },

                                           {

                                                          "ID": "000001947",

                                                          "LINENUM": 2,

                                                          "ORDERLINEITEMID": "8M0064457"

                                           }

                             ],

                             "PACKSTRUCTUREENTITY": [

                                           {

                                                          "PACKIID": "000001948",

                                                          "ID": "000001947",

                                                          "PALLETENTITY": [

                                                                        {

                                                                                      "PACKIID": "000001948",

                                                                                      "PALLETID": "CARTOON 1",

                                                                                      "ID": "0139-000001947",

                                                                                      "PALLETLINEENTITY": {

                                                                                                     "PACKIID": "000001948",

                                                                                                     "PALLETID": "CARTOON 1",

                                                                                                     "LINENUM": 1,

                                                                                                     "ITEMID": "8M0073789",

                                                                                                     "QUANTITY": 2,

                                                                                                     "ID": "0139-000001947"

                                                                                      }

                                                                        },

                                                                        {

                                                                                      "PACKIID": "000001948",

                                                                                      "PALLETID": "CARTOON 2",

                                                                                      "ID": "000001947",

                                                                                      "PALLETLINEENTITY": {

                                                                                                     "PACKIID": "000001948",

                                                                                                     "PALLETID": "CARTOON 2",

                                                                                                     "LINENUM": 1,

                                                                                                     "ITEMID": "8M0064457",

                                                                                                     "QUANTITY": 16,

                                                                                                     "ID": "000001947"

                                                                                      }

                                                                        }

                                                          ]

                                           }

                             ],

                             "INVOICEHEADERENTITY": [

                                           {

                                                          "ID": "000001947",

                                                          "INVOICENUMBER": "CINV000001947

                                                          "INVOICEHEADERCHARGESENTITY": [

                                                                        {

                                                                                      "ID": "000001947",

                                                                                      "INVOICENUMBER": "CINV000001947",

                                                                                      "CHARGEID": "Air Freight"

                                                                        },

                                                                        {

                                                                                      "ID": "000001947",

                                                                                      "LINENUM": 2,

                                                                                      "INVOICENUMBER": "CINV000001947",

                                                                                      "CHARGEID": "Insurance and Handling"

                                                                        }

                                                          ],

                                                          "INVOICELINESENTITY": [

                                                                        {

                                                                                      "ID": "000001947",

                                                                                      "INVOICENUMBER": "CINV000001947",

                                                                                      "INVENTTRANSID": "INLI00037689"

                                                                        },

                                                                        {

                                                                                      "ID": "000001947",

                                                                                      "INVOICENUMBER": "CINV000001947",

                                                                                      "INVENTTRANSID": "INLI00037691"

                                                                        }

                                                          ]

                                           }

                             ]

              }

}

I have the same question (0)
  • Suggested answer
    ergun sahin Profile Picture
    8,826 Moderator on at

    There are two errors in the example you gave. When you fix them, you should get something like below (from https://json2csharp.com)
    You can compare it with your own class or you can open a .Net project directly and do the deserialization there.

    // Root myDeserializedClass = JsonConvert.DeserializeObject(myJsonResponse); 
        public class LINEENTITY
        {
            public string ID { get; set; }
            public int LINENUM { get; set; }
            public string ORDERLINEITEMID { get; set; }
        }
    
        public class PALLETLINEENTITY
        {
            public string PACKIID { get; set; }
            public string PALLETID { get; set; }
            public int LINENUM { get; set; }
            public string ITEMID { get; set; }
            public int QUANTITY { get; set; }
            public string ID { get; set; }
        }
    
        public class PALLETENTITY
        {
            public string PACKIID { get; set; }
            public string PALLETID { get; set; }
            public string ID { get; set; }
            public PALLETLINEENTITY PALLETLINEENTITY { get; set; }
        }
    
        public class PACKSTRUCTUREENTITY
        {
            public string PACKIID { get; set; }
            public string ID { get; set; }
            public List PALLETENTITY { get; set; }
        }
    
        public class INVOICEHEADERCHARGESENTITY
        {
            public string ID { get; set; }
            public string INVOICENUMBER { get; set; }
            public string CHARGEID { get; set; }
            public int? LINENUM { get; set; }
        }
    
        public class INVOICELINESENTITY
        {
            public string ID { get; set; }
            public string INVOICENUMBER { get; set; }
            public string INVENTTRANSID { get; set; }
        }
    
        public class INVOICEHEADERENTITY
        {
            public string ID { get; set; }
            public string INVOICENUMBER { get; set; }
            public List INVOICEHEADERCHARGESENTITY { get; set; }
            public List INVOICELINESENTITY { get; set; }
        }
    
        public class HEADERENTITY
        {
            public string ID { get; set; }
            public string BLNUMBER { get; set; }
            public string BOOOKINGNUMBER { get; set; }
            public List LINEENTITY { get; set; }
            public List PACKSTRUCTUREENTITY { get; set; }
            public List INVOICEHEADERENTITY { get; set; }
        }
    
        public class Root
        {
            public HEADERENTITY HEADERENTITY { get; set; }
        }

  • Community Member Profile Picture
    on at

    HI Ergün Şahin,

    Thanks for your prompt response,

    could you tell us, where is exact error?.  I did compare with my data contract, its look same.

    Thanks,

    Sangeeth

  • Suggested answer
    ergun sahin Profile Picture
    8,826 Moderator on at

    Probably, just copy + paste errors

    pastedimage1631108163759v1.png

    pastedimage1631108282206v2.png

     String values so need (" ") and after invoiceNumber (,)

  • Suggested answer
    Sheikh Sohail Profile Picture
    6,125 on at

    HI

    You can validate your JSON online, using the link https://jsonlint.com/

    During the validation of your JSON, I found the below error message.

    Error: Parse error on line 9:
    ...KINGNUMBER": 546575 tststt7,		"LINEENT
    -----------------------^
    Expecting 'EOF', '}', ',', ']', got 'undefined'
  • Community Member Profile Picture
    on at

    Thanks Sohail & Ergün for your reply.

    Yes Copy and paste mistake. Since this json converter using XML only.

    Still facing issue while deserialize,

    Code:

    FormJsonSerializer::deserializeObject(classNum(<RootContact>),jsonResponseStr);

    D365FO, system not deserializing for inner json which has list and other types.

    Thanks,

    Sangeeth

  • Verified answer
    Sheikh Sohail Profile Picture
    6,125 on at

    Hi

    I would recommend you, create the C# class library project, write logic to deserialize your JSON, and return the class object.

    the same C# class object you can use in D365FO as well.

  • Community Member Profile Picture
    on at

    Thanks Sohail.

    Let me try it out.

  • Suggested answer
    Sheikh Sohail Profile Picture
    6,125 on at

    Hi

    You can also use the online portal to understand what class structure you need to resolve your JSON.

    https://json2csharp.com/

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 559 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 464 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans