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 :
Small and medium business | Business Central, N...
Suggested answer

How to create json with special characters

(4) ShareShare
ReportReport
Posted on by 425

Hello Team,

How to create json with special characters.

I have the same question (0)
  • Suggested answer
    Sohail Ahmed Profile Picture
    11,013 Super User 2025 Season 2 on at
    How to create json with special characters

    Hope this might be helpful:

    In AL for Business Central, when creating JSON, special characters are generally handled automatically by the JsonToken and JsonBuilder (or JsonObject) data types, as they perform proper escaping according to JSON standards.

    You don't typically need to manually escape characters like double quotes ("), backslashes (\), newlines (\n), tabs (\t), or control characters. The WriteValue methods of JsonBuilder or assigning values to JsonObject members will take care of this for you.

    local procedure CreateJsonWithSpecialChars()
    var
        JsonBuilder: JsonBuilder;
        JsonText: Text;
    begin
        JsonBuilder.WriteStartObject(); // {
    
        // String with double quotes, newlines, tabs, and backslashes
        JsonBuilder.WriteName('Description');
        JsonBuilder.WriteValue('This is a "test" string with\nnewlines and\ttabs and a \\ backslash.');
    
        // String with characters that might seem special but are fine directly
        JsonBuilder.WriteName('ProductCode');
        JsonBuilder.WriteValue('PROD-BC/123-ÄÖÜ');
    
        // Unicode characters are also handled
        JsonBuilder.WriteName('UnicodeExample');
        JsonBuilder.WriteValue('你好世界 – नमस्ते दुनिया');
    
        JsonBuilder.WriteEndObject(); // }
    
        JsonBuilder.WriteTo(JsonText);
        Message('%1', JsonText);
        // Expected output will have special characters escaped:
        // {"Description":"This is a \"test\" string with\nnewlines and\ttabs and a \\\\ backslash.","ProductCode":"PROD-BC\/123-ÄÖÜ","UnicodeExample":"你好世界 – नमस्ते दुनिया"}
    end;
     
    Example using JsonObject (for more structured data or if you have existing objects):
     
    local procedure CreateJsonWithSpecialCharsUsingObject()
    var
        JsonObject: JsonObject;
        JsonToken: JsonToken;
        JsonText: Text;
    begin
        JsonObject.Add('Description', 'This is another "test" with\nnewlines and\ttabs.');
        JsonObject.Add('ItemName', 'Item with & symbols and < > brackets.'); // & is not special in JSON string values
        JsonObject.Add('Path', 'C:\\Program Files\\App'); // Backslashes will be escaped
    
        JsonObject.WriteTo(JsonText);
        Message('%1', JsonText);
        // Expected output:
        // {"Description":"This is another \"test\" with\nnewlines and\ttabs.","ItemName":"Item with & symbols and < > brackets.","Path":"C:\\\\Program Files\\\\App"}
    end;
     
     
    When using Business Central's built-in JsonToken, JsonBuilder, or JsonObject types to construct JSON in AL, you generally do not need to manually escape special characters within string values. The AL runtime and JSON serialization logic handle the necessary escaping automatically to produce valid JSON.
     
    ✅ Mark this answer as verified if it helps you.
  • Gerardo Rentería García Profile Picture
    23,454 Most Valuable Professional on at
    How to create json with special characters
  • Jackson Eagle Profile Picture
    18 on at
    How to create json with special characters

    In Business Central AL, you don’t need to manually escape special characters when building JSON — the built-in JsonObject and JsonValue types handle that automatically.

    Example:

     
    MyJson.Add('description', '10" Wrench\nSpecial');
     

    This will correctly escape to:

     
    { "description": "10\" Wrench\\nSpecial" }
     

    If you want to preview or debug how text is escaped or unescaped, these tools might help:

  • Dan Kinsella Profile Picture
    468 on at
    RE: How to create json with special characters

    You could convert the item description to a base 64 string, then have the webservice convert it back again. 

  • Yuhi Profile Picture
    on at
    RE: How to create json with special characters

    Hi Manish,

    It can be difficult if you don't want to change item description with escaping characters.

  • Manish Ratan Profile Picture
    425 on at
    RE: How to create json with special characters

    Hi Yuhi,

    Item description includes special character.And i need to flow it to it to website through json

  • Yuhi Profile Picture
    on at
    RE: How to create json with special characters

    Hi Manish

    Please let me know in what situation on Business Central you want to include special character in json?

    (where and when do you wanna do that?)

    Best regards,

    Yuhi

  • Manish Ratan Profile Picture
    425 on at
    RE: How to create json with special characters

    Thanks Yuhi for the reply.

    Yes this is related to Business central. My requirement is how to include special character in json.

  • Suggested answer
    Yuhi Profile Picture
    on at
    RE: How to create json with special characters

    Hi Manish

    I don't know if your question is related to Business Central.

    However, according to here (https://www.freeformatter.com/json-escape.html), please take a look at the list below:

         The following characters are reserved in JSON and must be properly escaped to be used in strings:

    • Backspace is replaced with \b
    • Form feed is replaced with \f
    • Newline is replaced with \n
    • Carriage return is replaced with \r
    • Tab is replaced with \t
    • Double quote is replaced with \"
    • Backslash is replaced with \\

    Also you can check how to escape special character in json here:

    https://stackoverflow.com/questions/19176024/how-to-escape-special-characters-in-building-a-json-string

    Best regards,

    Yuhi

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 3,406

#2
Sumit Singh Profile Picture

Sumit Singh 2,852

#3
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 2,217

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans