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, ...
Unanswered

deserialize JSON without []

(0) ShareShare
ReportReport
Posted on by 162
Hi, I have the following JSON string from rest API and I have to read /rates/ values in a List and the problem is JSON string does not have rectangular brackets in rates object.


Please help to fix this problem.

Thanks 
  • Martin Dráb Profile Picture
    240,852 Most Valuable Professional on at
    It's not a list / array. It's on object.
     
    I assume you're talking about passing this JSON to an F&O custom service. Your service operation will have five arguments, such as success, timestamp and rates, where the type of rates would be a data contract class. This other contract will have data members AUD, CAD etc.

     If the number of properties (currencies) is variable, it's not a good a candidate for an object passed to a custom service. Consider transforming the message in Azure API management, for example.
  • D356FO_Dev Profile Picture
    162 on at
    Thanks for your response. 
    We are using an external REST API to grab the exchange rates and store them in D365FO. Can you please share a sample code to read JSON object 'rates' in my case?

     
  • Layan Jwei Profile Picture
    8,329 Super User 2026 Season 2 on at
    Hi D365FO_Dev,

    can you please show us the code you have?

    In general, If u want to use custom service, then you need to create two contract classes. Here's an example:
    [DataContractAttribute]
    class ReqContract1
    {
        boolean   success;
        //add the rest
    
        RatesReqContract ratesContract;
    
        [DataMemberAttribute]
        public boolean parmSuccess(boolean _success = success)
        {
           success = _success;
           return success;
        }
        
        [DataMemberAttribute]
        public RatesReqContract parmRatesContract(Contract2 _contract2 = ratesContract)
        {
           ratesContract = _ratesContract;
           return ratesContract;
        }
        
        // add the rest
    }
    
    [DataContractAttribute]
    class RatesReqContract
    {
        str aud;
        str cad;
        // add the rest
    
        [DataMemberAttribute]
        public str parmAUD(boolean _aud = aud)
        {
          aud= _aud;
          return aud;
        }
    
        [DataMemberAttribute]
        public str parmCAD(str _cad = cad)
        {
          cad = _cad;
          return cad;
        }
        
        //add the rest
    }
    

    Thanks,
    Layan Jweihan
     
  • Martin Dráb Profile Picture
    240,852 Most Valuable Professional on at
    Please tell us what you're doing. Are you passing this object to an F&O custom service? Or is it a response you got by making a request directly from X++?
     
    If it's about a custom service and you agree you can use a data contract object, then you won't write any code to parse JSON. It's done automatically by F&O kernel.
     
    If you have this JSON string in X++, you can utilize FormJsonSerializer::deserializeObject(), for example.

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

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

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

#1
Martin Dráb Profile Picture

Martin Dráb 523 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
CU10121822-0 Profile Picture

CU10121822-0 354

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans