json.jamo (built in)

json: reads and writes JSON, the text format most save files and web services use. use "json.jamo"

A Json value is null, a bool, a number, text, a list or an object. Objects keep their keys in the order they were added. parse_json never stops the program: when the text isn't JSON, the value it gives back has an error that says what's wrong and on which line.

constJSON_MOST_DEPTH

const JSON_MOST_DEPTH = 500

enumJsonKind

enum JsonKind
    NULL
    BOOL
    NUMBER
    TEXT
    LIST
    OBJECT
end

structJson

struct Json
    kind: JsonKind
    truth: bool
    number: float
    text: string
    items: [Json]
    keys: [string]
    values: [Json]
    error: string
end

funcjson_null

func json_null(): Json

funcjson_bool

func json_bool(value: bool): Json

funcjson_number

func json_number(value: float): Json

funcjson_int

func json_int(value: int): Json

funcjson_text

func json_text(value: string): Json

funcjson_list

func json_list(): Json

funcjson_object

func json_object(): Json

funcJson.add

func Json.add(item: Json)

Adds an item to the end of a list

funcJson.set

func Json.set(key: string, value: Json)

Sets a key in an object, replacing what it had

funcJson.has

func Json.has(key: string): bool

funcindex_of_key

func index_of_key(keys: [string], key: string): int

funcJson.get

func Json.get(key: string): Json

An object's value for a key, or null when it has no such key

funcJson.at

func Json.at(place: int): Json

A list's item at a place, counting from 0, or null when there's nothing there

funcJson.size

func Json.size(): int

How many items a list has, or keys an object has

funcJson.is_null

func Json.is_null(): bool

funcJson.as_int

func Json.as_int(): int

The number as an int, dropping any decimals. Anything that isn't a number gives 0

funcjson_escape

func json_escape(text: string, out: TextBuilder)

funcjson_number_text

func json_number_text(value: float): string

Whole numbers are written without decimals. Others show up to 6 decimals, the way Jamo shows floats. JSON has no NaN or infinity, so they're written as null

funcjson_write

func json_write(value: Json, out: TextBuilder, pretty: bool, depth: int)

funcjson_new_line

func json_new_line(out: TextBuilder, pretty: bool, depth: int)

functo_json

func to_json(value: Json): string

The value as JSON on one line

functo_json_pretty

func to_json_pretty(value: Json): string

The value as JSON, one item a line and indented, for files people may read

structJsonReader

struct JsonReader
    text: string
    at: int
    line: int
    error: string
end

funcJsonReader.fail_here

func JsonReader.fail_here(words: string)

funcJsonReader.next_byte

func JsonReader.next_byte(): int

funcJsonReader.skip_space

func JsonReader.skip_space()

funcJsonReader.word

func JsonReader.word(text: string): bool

funcslice_or_empty

func slice_or_empty(text: string, from: int, to: int): string

funcJsonReader.read_value

func JsonReader.read_value(depth: int): Json

funcJsonReader.read_list

func JsonReader.read_list(depth: int): Json

funcJsonReader.read_object

func JsonReader.read_object(depth: int): Json

funcjson_hex

func json_hex(code: int): int

funcJsonReader.read_hex4

func JsonReader.read_hex4(): int

funcjson_add_utf8

func json_add_utf8(out: TextBuilder, code: int)

funcJsonReader.read_text

func JsonReader.read_text(): string

Reads text in double quotes, starting at the opening quote

funcjson_byte

func json_byte(value: int): int

funcis_digit_code

func is_digit_code(code: int): bool

funcJsonReader.read_number

func JsonReader.read_number(): Json

Reads a number. The exponent moves the decimal point in the digits themselves, so the answer rounds exactly

funcparse_json

func parse_json(text: string): Json

Reads JSON text. When it isn't JSON, the answer is null with an error saying why, and the line