const JsonPrimitive = Schema.Union(
Schema.Boolean,
Schema.Number,
Schema.String,
);
interface JsonObject {
type: "JsonObject";
value: Record<string, JsonValue | undefined>;
}
interface JsonValue {
type: "JsonValue";
value: boolean | number | string | JsonObject | JsonArray;
}
interface JsonArray {
type: "JsonArray";
value: readonly JsonValue[];
}
const JsonArray = Schema.Struct({
type: Schema.Literal("JsonArray"),
value: Schema.Array(
Schema.suspend((): Schema.Schema<JsonValue> => JsonValue),
),
});
const JsonObject = Schema.Struct({
type: Schema.Literal("JsonObject"),
value: Schema.Record({
key: Schema.String,
value: Schema.UndefinedOr(
Schema.suspend((): Schema.Schema<JsonValue> => JsonValue),
),
}),
});
const JsonValue = Schema.Struct({
type: Schema.Literal("JsonValue"),
value: Schema.Union(
JsonPrimitive,
Schema.suspend((): Schema.Schema<JsonObject> => JsonObject),
Schema.suspend((): Schema.Schema<JsonArray> => JsonArray),
),
});
const JsonPrimitive = Schema.Union(
Schema.Boolean,
Schema.Number,
Schema.String,
);
interface JsonObject {
type: "JsonObject";
value: Record<string, JsonValue | undefined>;
}
interface JsonValue {
type: "JsonValue";
value: boolean | number | string | JsonObject | JsonArray;
}
interface JsonArray {
type: "JsonArray";
value: readonly JsonValue[];
}
const JsonArray = Schema.Struct({
type: Schema.Literal("JsonArray"),
value: Schema.Array(
Schema.suspend((): Schema.Schema<JsonValue> => JsonValue),
),
});
const JsonObject = Schema.Struct({
type: Schema.Literal("JsonObject"),
value: Schema.Record({
key: Schema.String,
value: Schema.UndefinedOr(
Schema.suspend((): Schema.Schema<JsonValue> => JsonValue),
),
}),
});
const JsonValue = Schema.Struct({
type: Schema.Literal("JsonValue"),
value: Schema.Union(
JsonPrimitive,
Schema.suspend((): Schema.Schema<JsonObject> => JsonObject),
Schema.suspend((): Schema.Schema<JsonArray> => JsonArray),
),
});