Types
JSONDecoder {.importc: "json_decoder", header: "pd_api.h".} = object decodeError* {.importc: "decodeError".}: proc (decoder: ptr JSONDecoder; error: cstring; linenum: cint) {.cdecl.} ## the following functions are each optional willDecodeSublist* {.importc: "willDecodeSublist".}: proc ( decoder: ptr JSONDecoder; name: cstring; type: JSONValueType) {.cdecl.} shouldDecodeTableValueForKey* {.importc: "shouldDecodeTableValueForKey".}: proc ( decoder: ptr JSONDecoder; key: cstring): cint {.cdecl.} didDecodeTableValue* {.importc: "didDecodeTableValue".}: proc ( decoder: ptr JSONDecoder; key: cstring; value: JSONValue) {.cdecl.} shouldDecodeArrayValueAtIndex* {.importc: "shouldDecodeArrayValueAtIndex".}: proc ( decoder: ptr JSONDecoder; pos: cint): cint {.cdecl.} didDecodeArrayValue* {.importc: "didDecodeArrayValue".}: proc ( decoder: ptr JSONDecoder; pos: cint; value: JSONValue) {.cdecl.} ## if pos==0, this was a bare value at the root of the file didDecodeSublist* {.importc: "didDecodeSublist".}: proc ( decoder: ptr JSONDecoder; name: cstring; type: JSONValueType): pointer {. cdecl.} userdata* {.importc: "userdata".}: pointer returnString* {.importc: "returnString".}: cint ## when set, the decoder skips parsing and returns the current subtree as a string path* {.importc: "path".}: cstring ## updated during parsing, reflects current position in tree
JSONEncoder {.importc: "json_encoder", header: "pd_api.h".} = object writeStringFunc* {.importc: "writeStringFunc".}: ptr WriteFunc userdata* {.importc: "userdata".}: pointer pretty* {.importc: "pretty".}: cint startedTable* {.importc: "startedTable".}: cint startedArray* {.importc: "startedArray".}: cint depth* {.importc: "depth".}: cint startArray* {.importc: "startArray".}: proc (encoder: ptr JSONEncoder) {.cdecl.} addArrayMember* {.importc: "addArrayMember".}: proc (encoder: ptr JSONEncoder) {. cdecl.} endArray* {.importc: "endArray".}: proc (encoder: ptr JSONEncoder) {.cdecl.} startTable* {.importc: "startTable".}: proc (encoder: ptr JSONEncoder) {.cdecl.} addTableMember* {.importc: "addTableMember".}: proc (encoder: ptr JSONEncoder; name: cstring; len: cint) {.cdecl.} endTable* {.importc: "endTable".}: proc (encoder: ptr JSONEncoder) {.cdecl.} writeNull* {.importc: "writeNull".}: proc (encoder: ptr JSONEncoder) {.cdecl.} writeFalse* {.importc: "writeFalse".}: proc (encoder: ptr JSONEncoder) {.cdecl.} writeTrue* {.importc: "writeTrue".}: proc (encoder: ptr JSONEncoder) {.cdecl.} writeInt* {.importc: "writeInt".}: proc (encoder: ptr JSONEncoder; num: cint) {. cdecl.} writeDouble* {.importc: "writeDouble".}: proc (encoder: ptr JSONEncoder; num: cdouble) {.cdecl.} writeString* {.importc: "writeString".}: proc (encoder: ptr JSONEncoder; str: cstring; len: cint) {.cdecl.}
JSONReader {.importc: "json_reader", header: "pd_api.h".} = object read* {.importc: "read".}: proc (userdata: pointer; buf: ptr uint8; bufsize: cint): cint {.cdecl.} ## fill buffer, return bytes written or -1 on end of data userdata* {.importc: "userdata".}: pointer ## passed back to the read function above
JSONValue {.importc: "json_value", header: "pd_api.h".} = object data* {.importc: "data".}: JSONValueUnion
JSONValueType {.size: 1.} = enum kJSONNull, kJSONTrue, kJSONFalse, kJSONInteger, kJSONFloat, kJSONString, kJSONArray, kJSONTable
JSONValueUnion {.importc: "json_value::no_name", header: "pd_api.h", bycopy, union.} = object intval* {.importc: "intval".}: cint floatval* {.importc: "floatval".}: cfloat stringval* {.importc: "stringval".}: cstring arrayval* {.importc: "arrayval".}: pointer tableval* {.importc: "tableval".}: pointer
PlaydateJSON {.importc: "const struct playdate_json", header: "pd_api.h".} = object
WriteFunc = proc (userdata: pointer; str: cstring; len: cint) {.cdecl.}
Procs
proc floatValue(this: JSONValue): float {.inline, ...raises: [], tags: [], forbids: [].}
proc stringValue(this: JSONValue): string {.inline, ...raises: [], tags: [], forbids: [].}