Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Unanswered

deserialize JSON without []

(0) ShareShare
ReportReport
Posted on by 100
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
    Martin Dráb 230,934 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
    Layan Jwei 7,677 Super User 2025 Season 1 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
    D356FO_Dev 100 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
    Martin Dráb 230,934 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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,111 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,934 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans