web
You’re offline. This is a read only version of the page.
close
Skip to main content
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 140
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 
I have the same question (0)
  • Martin Dráb Profile Picture
    236,172 Most Valuable Professional on at
    deserialize JSON without []
    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.
  • Layan Jwei Profile Picture
    8,034 Super User 2025 Season 2 on at
    deserialize JSON without []
    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
     
  • D356FO_Dev Profile Picture
    140 on at
    deserialize JSON without []
    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?

     
  • Martin Dráb Profile Picture
    236,172 Most Valuable Professional on at
    deserialize JSON without []
    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.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,352

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 634 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans