Created
June 24, 2021 07:44
-
-
Save MelbourneDeveloper/aa1577ce7238b355e47650a9814d27cd to your computer and use it in GitHub Desktop.
Json Data Structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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