Skip to content
Snippets Groups Projects
Commit 241675d0 authored by Jiří Kalvoda's avatar Jiří Kalvoda
Browse files

StatusBarI3: Remove null from JSON

parent 2b39ea5e
No related branches found
No related tags found
No related merge requests found
...@@ -29,6 +29,21 @@ namespace i3csstatus { ...@@ -29,6 +29,21 @@ namespace i3csstatus {
return kill(p.Id, sig); return kill(p.Id, sig);
} }
} }
static class JsonExtended
{
public static JsonObject RemoveNull(this JsonObject o)
{
List<string> toDelete = new();
foreach(var (k, v) in o)
{
if(v == null)
toDelete.Add(k);
}
foreach(var k in toDelete)
o.Remove(k);
return o;
}
}
static class ColorToHexExtended static class ColorToHexExtended
{ {
static public string ToHex(this Color c) static public string ToHex(this Color c)
...@@ -348,7 +363,7 @@ namespace i3csstatus { ...@@ -348,7 +363,7 @@ namespace i3csstatus {
["full_text"] = e.text, ["full_text"] = e.text,
["short_text"] = e.short_text, ["short_text"] = e.short_text,
["color"] = e.color?.ToHex(), ["color"] = e.color?.ToHex(),
}).ToArray()); }.RemoveNull()).ToArray());
var opt = new JsonSerializerOptions(); var opt = new JsonSerializerOptions();
opt.DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull; opt.DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull;
w.Write(","); w.Write(",");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment