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...
Answered

Line Break when sending data through JSON

(4) 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
    procedure ReadAsTextWithSeparator(InStream: InStream; LineSeparator: Text) Content: Text
        var
            Tb: TextBuilder;
            ContentLine: Text;
        begin
            InStream.ReadText(ContentLine);
            Tb.Append(ContentLine);
            while not InStream.EOS do begin
                InStream.ReadText(ContentLine);
                Tb.Append(LineSeparator);
                Tb.Append(ContentLine);
            end;
    
            exit(Tb.ToText());
        end;
     
     
     
     
     
    procedure LFSeparator(): Text[1]
        var
            LF: Text[1];
        begin
            LF[1] := 10; // Line feed, '\n'
            exit(LF);
        end;
     
     
    ✅ Mark this answer as verified if it helps you.
  • IM-18071459-0 Profile Picture
    45 on at
    hi Sohail.. i did as you suggested.
     
    StringBuilder.Append('Msg1');
    StringBuilder.Append(10);
    StringBuilder.Append('Msg2');
    StringBuilder.Append(10);
    StringBuilder.Append('Msg3');
    ToSend:=StringBuilder.ToString();
    JsonTextWriter.WriteValue(ToSend);
     
    the output is: Msg1Msg2Msg3
  • Verified answer
    Sohail Ahmed Profile Picture
    11,136 Super User 2025 Season 2 on at
    StringBuilder.Append('Msg1');
    StringBuilder.Append(CRLFSeparator());
    StringBuilder.Append('Msg2');
    StringBuilder.Append(CRLFSeparator());
    StringBuilder.Append('Msg3');
    ToSend := StringBuilder.ToString();
    JsonTextWriter.WriteValue(ToSend);
     
     
    i guess you missed 2nd portion of my code.
     

    Tip for Debugging

    If you're still seeing the result as a single line in JSON:

    • Confirm that the consumer of the JSON (e.g., a browser, API, or viewer) renders line breaks, as some systems escape them visually.
    • Check if JsonTextWriter.Formatting is set to None or Indented — for visual inspection, Indented helps.
     

    ✅ Mark this answer as verified if it helps you.

     
  • Verified answer
    IM-18071459-0 Profile Picture
    45 on at
    Hi Sohail,
     
    thanks a lot :) It works now.
     
    below the codes:
     
    StringBuilder.Append('Msg1');
    StringBuilder.Append(CRLFSeparator());
    StringBuilder.Append('Msg2');
    StringBuilder.Append(CRLFSeparator());
    StringBuilder.Append('Msg3');
    ToSend := StringBuilder.ToString();
    JsonTextWriter.WriteValue(ToSend);
     
     
    LOCAL CTRLFSeparator() LF : Text[1]
    LF[1]:=10;
    EXIT(LF);
  • Sohail Ahmed Profile Picture
    11,136 Super User 2025 Season 2 on at
    @IM-18071459-0 Glad it helped 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

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