typeElements.jsonl
Schema
_key(required): integer
Range: 582 .. 92825elements(required): array of object_key(required): integer
Range: 1 .. 11_value(required): integer
Range: 7 .. 2056
Code snippets
// <auto-generated />
//
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
// using QuickType;
//
// var typeElement = TypeElement.FromJson(jsonString);
namespace QuickType
{
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
public partial class TypeElement
{
[JsonProperty("_key")]
public long Key { get; set; }
[JsonProperty("elements")]
public Element[] Elements { get; set; }
}
public partial class Element
{
[JsonProperty("_key")]
public long Key { get; set; }
[JsonProperty("_value")]
public long Value { get; set; }
}
public partial class TypeElement
{
public static TypeElement FromJson(string json) => JsonConvert.DeserializeObject<TypeElement>(json, QuickType.Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this TypeElement self) => JsonConvert.SerializeObject(self, QuickType.Converter.Settings);
}
internal static class Converter
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Converters =
{
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
},
};
}
}
// Code generated from JSON Schema using quicktype. DO NOT EDIT.
// To parse and unparse this JSON data, add this code to your project and do:
//
// typeElement, err := UnmarshalTypeElement(bytes)
// bytes, err = typeElement.Marshal()
package model
import "encoding/json"
func UnmarshalTypeElement(data []byte) (TypeElement, error) {
var r TypeElement
err := json.Unmarshal(data, &r)
return r, err
}
func (r *TypeElement) Marshal() ([]byte, error) {
return json.Marshal(r)
}
type TypeElement struct {
Key int64 `json:"_key"`
Elements []Element `json:"elements"`
}
type Element struct {
Key int64 `json:"_key"`
Value int64 `json:"_value"`
}
{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"_key":{"type":"integer","minimum":582,"maximum":92825},"elements":{"type":"array","items":{"type":"object","properties":{"_key":{"type":"integer","minimum":1,"maximum":11},"_value":{"type":"integer","minimum":7,"maximum":2056}},"required":["_key","_value"]},"minItems":2,"maxItems":11}},"required":["_key","elements"]}
// To parse the JSON, install kotlin's serialization plugin and do:
//
// val json = Json { allowStructuredMapKeys = true }
// val typeElement = json.parse(TypeElement.serializer(), jsonString)
package model
import kotlinx.serialization.*
import kotlinx.serialization.json.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
@Serializable
data class TypeElement (
@SerialName("_key")
val key: Long,
val elements: List<Element>
)
@Serializable
data class Element (
@SerialName("_key")
val key: Long,
@SerialName("_value")
val value: Long
)
<?php
// This is a autogenerated file:TypeElement
class TypeElement {
private int $key; // json:_key Required
private array $elements; // json:elements Required
/**
* @param int $key
* @param array $elements
*/
public function __construct(int $key, array $elements) {
$this->key = $key;
$this->elements = $elements;
}
/**
* @param int $value
* @throws Exception
* @return int
*/
public static function fromKey(int $value): int {
return $value; /*int*/
}
/**
* @throws Exception
* @return int
*/
public function toKey(): int {
if (TypeElement::validateKey($this->key)) {
return $this->key; /*int*/
}
throw new Exception('never get to this TypeElement::key');
}
/**
* @param int
* @return bool
* @throws Exception
*/
public static function validateKey(int $value): bool {
if (!is_integer($value)) {
throw new Exception("Attribute Error:TypeElement::key");
}
return true;
}
/**
* @throws Exception
* @return int
*/
public function getKey(): int {
if (TypeElement::validateKey($this->key)) {
return $this->key;
}
throw new Exception('never get to getKey TypeElement::key');
}
/**
* @return int
*/
public static function sampleKey(): int {
return 31; /*31:key*/
}
/**
* @param array $value
* @throws Exception
* @return array
*/
public static function fromElements(array $value): array {
return array_map(function ($value) {
return Element::from($value); /*class*/
}, $value);
}
/**
* @throws Exception
* @return array
*/
public function toElements(): array {
if (TypeElement::validateElements($this->elements)) {
return array_map(function ($value) {
return $value->to(); /*class*/
}, $this->elements);
}
throw new Exception('never get to this TypeElement::elements');
}
/**
* @param array
* @return bool
* @throws Exception
*/
public static function validateElements(array $value): bool {
if (!is_array($value)) {
throw new Exception("Attribute Error:TypeElement::elements");
}
array_walk($value, function($value_v) {
$value_v->validate();
});
return true;
}
/**
* @throws Exception
* @return array
*/
public function getElements(): array {
if (TypeElement::validateElements($this->elements)) {
return $this->elements;
}
throw new Exception('never get to getElements TypeElement::elements');
}
/**
* @return array
*/
public static function sampleElements(): array {
return array(
Element::sample() /*32:*/
); /* 32:elements*/
}
/**
* @throws Exception
* @return bool
*/
public function validate(): bool {
return TypeElement::validateKey($this->key)
|| TypeElement::validateElements($this->elements);
}
/**
* @return stdClass
* @throws Exception
*/
public function to(): stdClass {
$out = new stdClass();
$out->{'_key'} = $this->toKey();
$out->{'elements'} = $this->toElements();
return $out;
}
/**
* @param stdClass $obj
* @return TypeElement
* @throws Exception
*/
public static function from(stdClass $obj): TypeElement {
return new TypeElement(
TypeElement::fromKey($obj->{'_key'})
,TypeElement::fromElements($obj->{'elements'})
);
}
/**
* @return TypeElement
*/
public static function sample(): TypeElement {
return new TypeElement(
TypeElement::sampleKey()
,TypeElement::sampleElements()
);
}
}
// This is a autogenerated file:Element
class Element {
private int $key; // json:_key Required
private int $value; // json:_value Required
/**
* @param int $key
* @param int $value
*/
public function __construct(int $key, int $value) {
$this->key = $key;
$this->value = $value;
}
/**
* @param int $value
* @throws Exception
* @return int
*/
public static function fromKey(int $value): int {
return $value; /*int*/
}
/**
* @throws Exception
* @return int
*/
public function toKey(): int {
if (Element::validateKey($this->key)) {
return $this->key; /*int*/
}
throw new Exception('never get to this Element::key');
}
/**
* @param int
* @return bool
* @throws Exception
*/
public static function validateKey(int $value): bool {
if (!is_integer($value)) {
throw new Exception("Attribute Error:Element::key");
}
return true;
}
/**
* @throws Exception
* @return int
*/
public function getKey(): int {
if (Element::validateKey($this->key)) {
return $this->key;
}
throw new Exception('never get to getKey Element::key');
}
/**
* @return int
*/
public static function sampleKey(): int {
return 31; /*31:key*/
}
/**
* @param int $value
* @throws Exception
* @return int
*/
public static function fromValue(int $value): int {
return $value; /*int*/
}
/**
* @throws Exception
* @return int
*/
public function toValue(): int {
if (Element::validateValue($this->value)) {
return $this->value; /*int*/
}
throw new Exception('never get to this Element::value');
}
/**
* @param int
* @return bool
* @throws Exception
*/
public static function validateValue(int $value): bool {
if (!is_integer($value)) {
throw new Exception("Attribute Error:Element::value");
}
return true;
}
/**
* @throws Exception
* @return int
*/
public function getValue(): int {
if (Element::validateValue($this->value)) {
return $this->value;
}
throw new Exception('never get to getValue Element::value');
}
/**
* @return int
*/
public static function sampleValue(): int {
return 32; /*32:value*/
}
/**
* @throws Exception
* @return bool
*/
public function validate(): bool {
return Element::validateKey($this->key)
|| Element::validateValue($this->value);
}
/**
* @return stdClass
* @throws Exception
*/
public function to(): stdClass {
$out = new stdClass();
$out->{'_key'} = $this->toKey();
$out->{'_value'} = $this->toValue();
return $out;
}
/**
* @param stdClass $obj
* @return Element
* @throws Exception
*/
public static function from(stdClass $obj): Element {
return new Element(
Element::fromKey($obj->{'_key'})
,Element::fromValue($obj->{'_value'})
);
}
/**
* @return Element
*/
public static function sample(): Element {
return new Element(
Element::sampleKey()
,Element::sampleValue()
);
}
}
from typing import Any, List, TypeVar, Callable, Type, cast
T = TypeVar("T")
def from_int(x: Any) -> int:
assert isinstance(x, int) and not isinstance(x, bool)
return x
def from_list(f: Callable[[Any], T], x: Any) -> List[T]:
assert isinstance(x, list)
return [f(y) for y in x]
def to_class(c: Type[T], x: Any) -> dict:
assert isinstance(x, c)
return cast(Any, x).to_dict()
class Element:
key: int
value: int
def __init__(self, key: int, value: int) -> None:
self.key = key
self.value = value
@staticmethod
def from_dict(obj: Any) -> 'Element':
assert isinstance(obj, dict)
key = from_int(obj.get("_key"))
value = from_int(obj.get("_value"))
return Element(key, value)
def to_dict(self) -> dict:
result: dict = {}
result["_key"] = from_int(self.key)
result["_value"] = from_int(self.value)
return result
class TypeElement:
key: int
elements: List[Element]
def __init__(self, key: int, elements: List[Element]) -> None:
self.key = key
self.elements = elements
@staticmethod
def from_dict(obj: Any) -> 'TypeElement':
assert isinstance(obj, dict)
key = from_int(obj.get("_key"))
elements = from_list(Element.from_dict, obj.get("elements"))
return TypeElement(key, elements)
def to_dict(self) -> dict:
result: dict = {}
result["_key"] = from_int(self.key)
result["elements"] = from_list(lambda x: to_class(Element, x), self.elements)
return result
def type_element_from_dict(s: Any) -> TypeElement:
return TypeElement.from_dict(s)
def type_element_to_dict(x: TypeElement) -> Any:
return to_class(TypeElement, x)
// To parse this data:
//
// import { Convert, TypeElement } from "./file";
//
// const typeElement = Convert.toTypeElement(json);
//
// These functions will throw an error if the JSON doesn't
// match the expected interface, even if the JSON is valid.
export interface TypeElement {
_key: number;
elements: Element[];
[property: string]: any;
}
export interface Element {
_key: number;
_value: number;
[property: string]: any;
}
// Converts JSON strings to/from your types
// and asserts the results of JSON.parse at runtime
export class Convert {
public static toTypeElement(json: string): TypeElement {
return cast(JSON.parse(json), r("TypeElement"));
}
public static typeElementToJson(value: TypeElement): string {
return JSON.stringify(uncast(value, r("TypeElement")), null, 2);
}
}
function invalidValue(typ: any, val: any, key: any, parent: any = ''): never {
const prettyTyp = prettyTypeName(typ);
const parentText = parent ? ` on ${parent}` : '';
const keyText = key ? ` for key "${key}"` : '';
throw Error(`Invalid value${keyText}${parentText}. Expected ${prettyTyp} but got ${JSON.stringify(val)}`);
}
function prettyTypeName(typ: any): string {
if (Array.isArray(typ)) {
if (typ.length === 2 && typ[0] === undefined) {
return `an optional ${prettyTypeName(typ[1])}`;
} else {
return `one of [${typ.map(a => { return prettyTypeName(a); }).join(", ")}]`;
}
} else if (typeof typ === "object" && typ.literal !== undefined) {
return typ.literal;
} else {
return typeof typ;
}
}
function jsonToJSProps(typ: any): any {
if (typ.jsonToJS === undefined) {
const map: any = {};
typ.props.forEach((p: any) => map[p.json] = { key: p.js, typ: p.typ });
typ.jsonToJS = map;
}
return typ.jsonToJS;
}
function jsToJSONProps(typ: any): any {
if (typ.jsToJSON === undefined) {
const map: any = {};
typ.props.forEach((p: any) => map[p.js] = { key: p.json, typ: p.typ });
typ.jsToJSON = map;
}
return typ.jsToJSON;
}
function transform(val: any, typ: any, getProps: any, key: any = '', parent: any = ''): any {
function transformPrimitive(typ: string, val: any): any {
if (typeof typ === typeof val) return val;
return invalidValue(typ, val, key, parent);
}
function transformUnion(typs: any[], val: any): any {
// val must validate against one typ in typs
const l = typs.length;
for (let i = 0; i < l; i++) {
const typ = typs[i];
try {
return transform(val, typ, getProps);
} catch (_) {}
}
return invalidValue(typs, val, key, parent);
}
function transformEnum(cases: string[], val: any): any {
if (cases.indexOf(val) !== -1) return val;
return invalidValue(cases.map(a => { return l(a); }), val, key, parent);
}
function transformArray(typ: any, val: any): any {
// val must be an array with no invalid elements
if (!Array.isArray(val)) return invalidValue(l("array"), val, key, parent);
return val.map(el => transform(el, typ, getProps));
}
function transformDate(val: any): any {
if (val === null) {
return null;
}
const d = new Date(val);
if (isNaN(d.valueOf())) {
return invalidValue(l("Date"), val, key, parent);
}
return d;
}
function transformObject(props: { [k: string]: any }, additional: any, val: any): any {
if (val === null || typeof val !== "object" || Array.isArray(val)) {
return invalidValue(l(ref || "object"), val, key, parent);
}
const result: any = {};
Object.getOwnPropertyNames(props).forEach(key => {
const prop = props[key];
const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined;
result[prop.key] = transform(v, prop.typ, getProps, key, ref);
});
Object.getOwnPropertyNames(val).forEach(key => {
if (!Object.prototype.hasOwnProperty.call(props, key)) {
result[key] = transform(val[key], additional, getProps, key, ref);
}
});
return result;
}
if (typ === "any") return val;
if (typ === null) {
if (val === null) return val;
return invalidValue(typ, val, key, parent);
}
if (typ === false) return invalidValue(typ, val, key, parent);
let ref: any = undefined;
while (typeof typ === "object" && typ.ref !== undefined) {
ref = typ.ref;
typ = typeMap[typ.ref];
}
if (Array.isArray(typ)) return transformEnum(typ, val);
if (typeof typ === "object") {
return typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val)
: typ.hasOwnProperty("arrayItems") ? transformArray(typ.arrayItems, val)
: typ.hasOwnProperty("props") ? transformObject(getProps(typ), typ.additional, val)
: invalidValue(typ, val, key, parent);
}
// Numbers can be parsed by Date but shouldn't be.
if (typ === Date && typeof val !== "number") return transformDate(val);
return transformPrimitive(typ, val);
}
function cast<T>(val: any, typ: any): T {
return transform(val, typ, jsonToJSProps);
}
function uncast<T>(val: T, typ: any): any {
return transform(val, typ, jsToJSONProps);
}
function l(typ: any) {
return { literal: typ };
}
function a(typ: any) {
return { arrayItems: typ };
}
function u(...typs: any[]) {
return { unionMembers: typs };
}
function o(props: any[], additional: any) {
return { props, additional };
}
function m(additional: any) {
return { props: [], additional };
}
function r(name: string) {
return { ref: name };
}
const typeMap: any = {
"TypeElement": o([
{ json: "_key", js: "_key", typ: 0 },
{ json: "elements", js: "elements", typ: a(r("Element")) },
], "any"),
"Element": o([
{ json: "_key", js: "_key", typ: 0 },
{ json: "_value", js: "_value", typ: 0 },
], "any"),
};