Home > Software design >  How to break line in Json
How to break line in Json

Time:11-26

I am trying to break line to show text in next line but its now working using nbreak var

tried giving the "//n" as well instead of assign var but its not working any help what i am missing here

function GetOrgJSON(employeeList,manager,total){
    var nbreak = '\\n';
    var note = '';
    var employeeProcessed=[];
    for(var i=0;i<employeeList.length;i  ){
        
        var objEmp = employeeList[i];      
        if(objEmp.Manager == manager && employeeProcessed.indexOf(objEmp.Name) < 0 ){
            var empUl = GetOrgJSON(employeeList,objEmp.ID,0);
            var tcount=0;
            if(empUl !=""){
            tcount=JSON.parse('['   empUl   ']').length;
            } 
            
            note  = '{"name":"' objEmp.Name '   ' tcount ' ' nbreak '  ' objEmp.MainRole ' ' nbreak ' ' objEmp.Country '",';
            note  = '"Email":"' objEmp.Email '",';
            note  = '"title":"' objEmp.Designation '"';
            
            employeeProcessed.push(objEmp.Name);
            
            //var empUl = GetOrgJSON(employeeList,objEmp.ID,0);
            
            if(empUl !=""){
                //total =JSON.parse('['   empUl   ']').length; 
                note  =',"children": ['   empUl   ']';
            }
            note  ='},';
        }       
    } 
    note=note.slice(0,note.length-1);
    return note;
}

CodePudding user response:

please, try to use only \n. When you write \\n you are escaping it and it's taken as plain text.

CodePudding user response:

Try using \n like this. Please find the sample code with the same format as yours.

var nbreak = '\n';
var note = '{"name":"dsdds dfd ' nbreak '  fdfd",';
note  = '"Email":"hello",';
alert(note);
  • Related