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 serialization x++ d365 fo

(2) ShareShare
ReportReport
Posted on by 28

Hi All,

I faced the issue about json serialization, i used this below code

str jsRead;

List resultSet = new List(Types::Class);

ResponseContract responseContract = new ResponseContract();
responseContract.parmRetTicketId("Test");
responseContract.parmRetStatus("Success");
responseContract.parmRetMessage("Test");
resultSet.addEnd(responseContract);

jsRead = FormJsonSerializer::serializeClass(resultSet);
return jsRead;

and i got the return like this

[{\"RetMessage\":\"Test\",\"RetStatus\":\"Success\",\"RetTicketId\":\"Test\"}]
How could it show this \ in the json string?
Regards,
Masha
I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    I suspect you're talking about the visualization in Visual Studio debugger and not the actual content of jsRead variable.

    The backslashes escape quotation marks, so you can copy the string and place it inside other quotations marks (as a string literal).

  • Verified answer
    mhdshb1 Profile Picture
    1,250 on at

    Hi Masha,

    As Martin said, the backslashes are shown in the debugger watches and it is only for escaping the qutations.

    For example: 

    This is the printed json string 

    pastedimage1595330997151v1.png

    But in the debugger it looks like this

    pastedimage1595331037379v2.png

    "{\"_worker\":\"090344\",\"_dayDateFrom\":\"2020-06-07T00:00:00\",\"_dayDateTo\":\"2020-06-13T00:00:00\"}"

    Regards,

    M

  • Verified answer
    Blue Wang Profile Picture
    on at

    HI Masha,

    Combine the points mentioned above.

    If you want to write your own Json string manually (it is better to use JSON serializer instead of manual), then you need to add a backslash to the string.

    For example, use jsonStr = "{\"name1\":\"%1\",\"name2\":\"%2\"}"; instead of jsonStr ={"name1":"%1"," name2":"%2"};

  • Suggested answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    It's true only in one case, not generally. Try using single quotation marks around the string literal, instead of double quotation marks - it doesn't require escaping and therefore it's easier to read:

    jsonStr = '{"name1":"%1"," name2":"%2"}';

  • Jackson Eagle Profile Picture
    20 on at
    Working with JSON in Dynamics can get tricky, especially when special characters aren’t properly escaped. In cases like this, I usually rely on online utilities to speed things up. This Escape JSON tool can quickly convert problematic characters into escaped JSON format, and the matching Unescape JSON tool makes it easy to revert them back for readability and debugging. Using these kinds of tools has saved me time when troubleshooting integrations and data transformations.

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 503 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans