Skip to content

Commit

Permalink
Update JsonDisplay.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
pwelter34 committed Apr 12, 2024
1 parent 61d2008 commit 8718249
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/LoreSoft.Blazor.Controls/JsonDisplay.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Text.Json;
#nullable enable

using System.Text.Json;

using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
Expand All @@ -8,10 +10,10 @@ namespace LoreSoft.Blazor.Controls;
public class JsonDisplay : ComponentBase
{
[Parameter]
public string Json { get; set; }
public string? Json { get; set; }

[Parameter]
public JsonElement JsonElement { get; set; }
public JsonElement? JsonElement { get; set; }

[Parameter(CaptureUnmatchedValues = true)]
public Dictionary<string, object>? Attributes { get; set; }
Expand All @@ -24,9 +26,9 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
var document = JsonDocument.Parse(Json);
AppendValue(builder, document.RootElement);
}
else
else if (JsonElement.HasValue)
{
AppendValue(builder, JsonElement);
AppendValue(builder, JsonElement.Value);
}
}

Expand Down Expand Up @@ -59,6 +61,7 @@ private void AppendObject(RenderTreeBuilder builder, JsonElement jsonElement)
builder.OpenElement(3, "table");
builder.AddAttribute(4, "class", "json-object");
builder.AddMultipleAttributes(5, Attributes);
builder.SetKey(jsonElement);

foreach (var jsonProperty in jsonElement.EnumerateObject())
{
Expand Down

0 comments on commit 8718249

Please sign in to comment.