Skip to content

Instantly share code, notes, and snippets.

@MelbourneDeveloper
Created June 24, 2021 07:44
Show Gist options
  • Save MelbourneDeveloper/aa1577ce7238b355e47650a9814d27cd to your computer and use it in GitHub Desktop.
Save MelbourneDeveloper/aa1577ce7238b355e47650a9814d27cd to your computer and use it in GitHub Desktop.
Json Data Structure
using System.Collections.Immutable;
namespace JsonDataStructure
{
public record JsonValue
{
public ValueType ValueType { get; }
public string? StringValue { get; init; }
public bool? BooleanValue { get; init; }
public decimal? NumberValue { get; init; }
public ImmutableDictionary<string, JsonValue>? JsonObjectValue { get; init; }
public ImmutableList<JsonValue>? JsonArrayValue { get; init; }
public JsonValue(string value) { StringValue = value; ValueType = ValueType.OfString; }
public JsonValue(bool value) { BooleanValue = value; ValueType = ValueType.OfBoolean; }
public JsonValue(decimal value) { NumberValue = value; ValueType = ValueType.OfNumber; }
public JsonValue(ImmutableDictionary<string, JsonValue> value) { JsonObjectValue = value; ValueType = ValueType.OfObject; }
public JsonValue(ImmutableList<JsonValue> value) { JsonArrayValue = value; ValueType = ValueType.OfArray; }
}
public enum ValueType
{
OfString,
OfNumber,
OfObject,
OfArray,
OfBoolean
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment