about summary refs log tree commit diff
path: root/Utilities/LibMatrix.E2eeTestKit/Pages/CSTJTest.razor
blob: 0d01428b28fcc064ad8a82ddeae2b2c9476de883 (plain) (blame)
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
@page "/CSTJTest"
@using System.Text.Json
@using System.Text.Json.Nodes
@using LibMatrix.Extensions

<PageTitle>Counter</PageTitle>

<h3>Canonicalise JSON</h3>
<hr/>

<InputTextArea @bind-Value="@JsonInput" rows="@(JsonInput.Split('\n').Length + 1)"></InputTextArea>
<br/>
<pre>@JsonOutput</pre>

@code {
    private string _jsonInput = "";

    private string JsonInput {
        get => _jsonInput;
        set {
            _jsonInput = value;
            try {
                Console.WriteLine("Input updated");
                var obj = JsonSerializer.Deserialize<dynamic>(value);
                Console.WriteLine("Deserialised");
                JsonOutput = CanonicalJsonSerializer.Serialize(obj);
                Console.WriteLine("Serialised: " + JsonOutput ?? "null");
            }
            catch (Exception e) {
                JsonOutput = e.ToString();
            }

            StateHasChanged();
        }
    }

    private string? JsonOutput { get; set; }

}