Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
In code asp.net i get result like following:

[ { "CustomerId": 1, "Name": "Akki", "Country": "india" }, { "CustomerId": 3, "Name": "Jyothi", "Country": "france" }, { "CustomerId": 4, "Name": "Fatima", "Country": "india" }, { "CustomerId": 5, "Name": "Ankita1", "Country": "india" }, { "CustomerId": 6, "Name": "Yash", "Country": "india" }, { "CustomerId": 7, "Name": "Garauv", "Country": "india" }, { "CustomerId": 8, "Name": "grgr", "Country": "gegerg" }, { "CustomerId": 9, "Name": "prashant", "Country": "india" }, { "CustomerId": 10, "Name": "Rajesh", "Country": "Austerila" }, { "CustomerId": 11, "Name": "Fatima", "Country": "India" }, { "CustomerId": 12, "Name": "Rajesh", "Country": "Sydney" }, { "CustomerId": 13, "Name": "", "Country": "" } ]

i want to format above Array.json like following

[ 
{
 "CustomerId": 1,
 "Name": "Akki", 
"Country": "india" 
},
{ 
"CustomerId": 3, 
"Name": "Jyothi", 
"Country": "france"
 }, 
{ "CustomerId": 4, 
"Name": "Fatima",
 "Country": "india" 
}
]


and print on page

What I have tried:

i tried various thing ,but could not successes
Posted
Updated 26-Nov-19 20:22pm

1 solution

Quote:
In code asp.net i get result like following:
That is the standard way of data transfer, whitespaces and newlines are removed since they are only overhead on the raw payload and do not serve any performance improvement in the data parsing — on the contrary, they do the opposite, they take extra space and make the algorithm slower.
Quote:
i want to format above Array.json like following
That depends upon where you are showing the data. For example, several tools like Postman would contain a program that makes the syntax readable for humans. A program does not care about the readability, only the validity of the content.

On web browsers, there are extensions available that can improve the readability and structure of the JSON document for you. But all of this is totally debatable.

See this online tool for example, JSON Formatter & Validator[^]

In C#, you can use the JsonConvert library to deserialize the content with indentation,
C#
var indentedJson = JsonConvert.SerializeObject(obj, Formatting.Indented);
Taken from here: JSON formatter in C#? - Stack Overflow[^]
Serialize an Object[^]
 
Share this answer
 
Comments
phil.o 27-Nov-19 6:47am    
5'd
Afzaal Ahmad Zeeshan 27-Nov-19 11:44am    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900