-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConsoleWritelineJson.dib
43 lines (30 loc) · 1.32 KB
/
ConsoleWritelineJson.dib
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!meta
{"kernelInfo":{"defaultKernelName":null,"items":[{"name":"csharp","languageName":"C#","aliases":["c#","cs"]},{"name":"fsharp","languageName":"F#","aliases":["f#","fs"]},{"name":"pwsh","languageName":"PowerShell","aliases":["powershell"]},{"name":"javascript","languageName":"JavaScript","aliases":["js"]},{"name":"html","languageName":"HTML"},{"name":"sql","languageName":"SQL"},{"name":"kql","languageName":"KQL"},{"name":"mermaid","languageName":"Mermaid"},{"name":"httpRequest","languageName":"http"},{"name":"value"}]}}
#!markdown
# Print Json to Terminal
Output:
#!csharp
public class Admin
{
public string name = "admin";
public string adminName = "admin";
public string password = "password";
public string email = "admin@localhost";
public bool isSuperAdmin = true;
public Admin()
{
}
}
var admin = new Admin();
string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(admin);
Console.WriteLine(jsonString);
#!csharp
using System.Text.Json;
var json = "{\"name\":\"John\",\"age\":30,\"car\":null, \"Hi\": {\"you\": 3 } }";
dynamic jsonObject = JsonSerializer.Deserialize<dynamic>(json);
var options = new JsonSerializerOptions
{
WriteIndented = true
};
string indentedJson = JsonSerializer.Serialize(jsonObject, options);
Console.WriteLine(indentedJson);