Skip to main content

Notifications

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

Remove invalid character \" from API JSON

Posted on by 129
Hello experts,

I have created custom API and I am expecting following JSON format but I have received different format :
Looking your help to get the expected JSON (Extra  character added in JSON, how to remove  from the JSON to match the expected JSON)

Actual JSON format: Extra invalid character added in JSON



Expected JSON format:
 
Code:
 
        salesOrderList                            =  _request.ParmSalesOrder();
        ListEnumerator  ListLineEnumerator       =  salesOrderList.getEnumerator();
        while(ListLineEnumerator.moveNext())

      {
           salesOrderListContract = ListLineEnumerator.current();
            
            salesOrderLineResonse = new XXX_SalesOrderLineResonse();
            salesOrderLineResonse.parmOrderNum(salesOrderListContract.ParmSalesOrderList());
            orderList.addEnd(salesOrderLineResonse);
        }
        salesOrderResponse = new XXX_salesOrderResponse();
        salesOrderResponse.parmLine(orderList);
        
        str jsonSerializedContractResponse = FormJsonSerializer::serializeClass(salesOrderResponse); // convert the object to JSON response
   
       
        jsonSerializedContractResponse = strReplace(jsonSerializedContractResponse,/////, //);   //To remove backward slash and / from the output
       
        return jsonSerializedContractResponse;
 
Output: 
  • Verified answer
    Layan Jwei Profile Picture
    Layan Jwei 7,339 Super User 2024 Season 2 on at
    Remove invalid character \" from API JSON
    Hi KomalG,
     
    When you say custom API, do you mean custom service?
     
    If yes, then as Martain said, are you looking at debugger? Cause the result might be correct. Try to call the custom service vis postman for example and check if the result returned is correct or not (without the need to remove "\"
     
    Thanks,
    Layan Jweihan
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,064 Most Valuable Professional on at
    Remove invalid character \" from API JSON
    How are you checking the result? If you're looking at a variable in debugger, the whole problem may be in how the data is shown there. Try saving it to a file, for example.
     
    By the way, why are you trying to serialize the contract object by yourself? You should return the contract object from your custom service; F&O will do the serialization for you.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,232 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,064 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans