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

Line Break when sending data through JSON

(8) ShareShare
ReportReport
Posted on by 45
Hello,
 
i am using Microsoft Dynamics NAV 2017 version.
 
I am sending data through JSON.
 
Variable: JsonTextWriter 
Datatype: DotNet
Subtype: Newtonsoft.Json.JsonTextWriter.'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
 
JsonTextWriter.WriteValue(TextField1 + '\n' + TextField2 + '\n'+ TextField3);
 
The output comes in one single line, but i want it to be break and go on another line after each TextField
 
TextField1
TextField2
TextField3
 
any suggestions?
 
 
I have the same question (0)
  • Sohail Ahmed Profile Picture
    11,136 Super User 2025 Season 2 on at

    I believe you've posted this question twice if so, you can remove the duplicate to avoid confusion and keep the thread clean.

     

    https://community.dynamics.com/forums/thread/details/?threadid=abb47e5e-5d64-f011-bec2-7c1e521b4ace

     

    ✅ Mark this answer as verified if it helps you.

  • Suggested answer
    DAnny3211 Profile Picture
    11,397 on at

    Hi,

    When using JsonTextWriter.WriteValue() from Newtonsoft.Json in Dynamics NAV 2017, the method escapes newline characters (\n) and writes the entire value as a single JSON string. This is expected behavior, as JSON strings do not interpret \n as actual line breaks when rendered—they remain as literal escape sequences.

    To achieve line breaks in the output, you have a couple of options:

    1. Use WriteRaw() Instead of WriteValue()
      If you're constructing a JSON object manually and want to insert raw line breaks, you can use:

    JsonTextWriter.WriteRaw('"' + TextField1 + '\n' + TextField2 + '\n' + TextField3 + '"');

    1. This writes the string exactly as you format it, including the escape sequences.

    2. Use Environment.NewLine (if supported)
      If you're writing to a file or stream and want actual line breaks (not escaped \n), you can build the string using

     

    CombinedText := TextField1 + Environment.NewLine + TextField2 + Environment.NewLine + TextField3;

    JsonTextWriter.WriteValue(CombinedText);

     
    1. However, this still results in a single JSON string with escaped newlines unless the consumer of the JSON interprets them.

    2. Post-process the output
      If the JSON is being consumed by a system that renders text (e.g., a UI or report), ensure that the consumer interprets \n as line breaks. If not, you may need to split the values into an array:

     

    JsonTextWriter.WriteStartArray();

    JsonTextWriter.WriteValue(TextField1);

    JsonTextWriter.WriteValue(TextField2);

    JsonTextWriter.WriteValue(TextField3);J

    sonTextWriter.WriteEndArray();

    1. This way, each value is a separate element, and the consumer can render them on separate lines.

    Please verify if this response was helpful.

    Best regards,
    Daniele

     

     

     

     

     

  • CU28070813-0 Profile Picture
    4 on at

    To ensure that each TextField appears on a new line in your JSON output, you can use the escape sequence for a newline character (\r\n or \n). Modify your code as follows: [url=https://headbasketball.io][color=#FFFFFF]head basketball game[/color][/url]

     
    Copy
    JsonTextWriter.WriteValue(TextField1 + '\r\n' + TextField2 + '\r\n' + TextField3);

    This will create the desired line breaks in the output.

  • Jackson Eagle Profile Picture
    20 on at

    If you’re using JsonTextWriter.WriteValue() with something like TextField1 + '\n' + TextField2, those \n get escaped in JSON and show up as \\n — that’s actually correct per the JSON spec.

    If you just want to see the actual line breaks, you’ll need to unescape the JSON string after serialization. I often use a Unescape JSON tool. Paste your JSON there, and it instantly converts \n into real newlines.

    And if you need the reverse — taking text and escaping it for JSON — another Escape JSON tool helps too. Both run fully in-browser and are great for quick debugging.

     
  • Suggested answer
    YUN ZHU Profile Picture
    95,331 Super User 2025 Season 2 on at
    Hi, Just to add some information, if it is in Business Central 2025 wave 1 (BC26), you can directly use the following method to write it.
     
    Thanks.
    ZHU
     
  • Suggested answer
    Nimsara Jayathilaka. Profile Picture
    4,836 on at
  • Gerardo Rentería García Profile Picture
    25,157 Most Valuable Professional on at

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 > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,143

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,694 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,067 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans