Line Jump in JSON.NET

0

on vb.net I am creating a person class and the resulting object has the fields Id, Name, Age. Then, using JSON.NET, I convert that object into a .json file and save it on the hard disk, but when I open it, everything remains in a single line like this:

{"Id":4,"Nombre":"Juan Perez","Edad":18}

I would like it to appear like this

{
 "Id":4,
 "Nombre":"Juan Perez",
 "Edad":18
}

I mean skip lines ... I need help with this ... thanks

    
asked by edusito87 18.09.2018 в 19:54
source

1 answer

0

Here is an example:

class:

public class Account
{
    public string Email { get; set; }
    public bool Active { get; set; }
    public DateTime CreatedDate { get; set; }
    public IList<string> Roles { get; set; }
}

Using the appropriate "formatting":

Account account = new Account
{
    Email = "[email protected]",
    Active = true,
    CreatedDate = new DateTime(2013, 1, 20, 0, 0, 0, DateTimeKind.Utc),
    Roles = new List<string>
    {
        "User",
        "Admin"
    }
};

string json = JsonConvert.SerializeObject(account, Formatting.Indented);
// {
//   "Email": "[email protected]",
//   "Active": true,
//   "CreatedDate": "2013-01-20T00:00:00Z",
//   "Roles": [
//     "User",
//     "Admin"
//   ]
// }

Console.WriteLine(json);

Extracted from the official documentation: link

    
answered by 18.09.2018 в 20:33