Updated 7 November 2026

JSON

json (same table as c8b.json) decodes with the native parser. json.open/openFile keep large documents in native memory behind a proxy table.

Conventions on every page: Availability says whether a symbol exists on the console BIOS, the emulator, or both. c8b and C8B are the same table.

Contents

json / c8b.json

json

json

Global JSON module, same table as c8b.json.

  • Availability: Console (BIOS) and emulator

c8b.json.decode

json.decode(str)

Parses JSON into Lua tables (native streaming parser). Returns nil on empty input or error (error is printed).

  • Returns: value or nil
  • Availability: Console (BIOS) and emulator
local t = json.decode('{"a":1}')

c8b.json.decodeWithError

json.decodeWithError(str)

Like decode but returns the error.

  • Returns: value or nil, error
  • Availability: Console (BIOS) and emulator

c8b.json.decodeFile

json.decodeFile(pathOrFile)

Decodes a file by path (the file is streamed, not loaded whole) or from a file object with read().

  • Returns: value or nil
  • Availability: Console (BIOS) and emulator

c8b.json.encode

json.encode(value, [pretty])

Encodes a Lua value as JSON.

  • Returns: string
  • Availability: Console (BIOS) and emulator

c8b.json.encodePretty

json.encodePretty(value)

Indented encode.

  • Returns: string
  • Availability: Console (BIOS) and emulator

c8b.json.encodeToFile

json.encodeToFile(fileOrPath, [pretty], value)

Writes JSON to a file object or path.

  • Returns: boolean
  • Availability: Console (BIOS) and emulator
  • Note: Writing to a path is not supported and returns false. Use c8b.file.writeString(path, json.encode(v)) or c8b.datastore.write.

c8b.json.open

json.open(str)

Parses JSON into a native document and returns a proxy table that reads fields lazily from native memory (keeps big data out of the Lua heap). Supports indexing, #, pairs, ipairs.

  • Returns: proxy or nil, error
  • Availability: Console (BIOS) and emulator

c8b.json.openFile

json.openFile(path)

json.open for a file.

  • Returns: proxy or nil, error
  • Availability: Console (BIOS) and emulator

c8b.json.toTable

json.toTable(proxy)

Converts a proxy to plain Lua tables (non-proxies returned as-is).

  • Returns: table
  • Availability: Console (BIOS) and emulator

jsonProxy:toTable

proxy:toTable()

Method form of json.toTable.

  • Returns: table
  • Availability: Console (BIOS) and emulator

Low-level bindings (C8B.*)

C8B.Json_free

C8B.Json_free(handle)

Native JSON binding: free.

  • Availability: Console (BIOS) and emulator

C8B.Json_open

C8B.Json_open(jsonStr)

Native behind json.open.

  • Returns: 2 value(s): nil, string
  • Availability: Console (BIOS) and emulator

C8B.Json_parse

C8B.Json_parse(jsonStr, len)

Parses JSON into a native document handle (handle API: getType/getField/... then Json_free).

  • Returns: 1 value(s): handle
  • Availability: Console (BIOS) and emulator

C8B.Json_encode

C8B.Json_encode(handle, pretty)

Encodes a Lua value to a JSON string (2nd argument: pretty).

  • Returns: 1 value(s): nil, string
  • Availability: Console (BIOS) and emulator

C8B.Json_getBool

C8B.Json_getBool(handle)

Native JSON binding: get bool.

  • Returns: 1 value(s): boolean
  • Availability: Console (BIOS) and emulator

C8B.Json_getKeys

C8B.Json_getKeys(handle)

Native JSON binding: get keys.

  • Returns: 1 value(s): nil, string
  • Availability: Console (BIOS) and emulator

C8B.Json_getSize

C8B.Json_getSize(handle)

Native JSON binding: get size.

  • Returns: 1 value(s): integer
  • Availability: Console (BIOS) and emulator

C8B.Json_getType

C8B.Json_getType(handle)

Native JSON binding: get type.

  • Returns: 1 value(s): integer
  • Availability: Console (BIOS) and emulator

C8B.Json_toTable

C8B.Json_toTable(proxy)

Native behind json.toTable.

  • Returns: 1 value(s):
  • Availability: Console (BIOS) and emulator

C8B.Json_getField

C8B.Json_getField(handle, key)

Native JSON binding: get field.

  • Returns: 1 value(s): handle
  • Availability: Console (BIOS) and emulator

C8B.Json_hasField

C8B.Json_hasField(handle, key)

Native JSON binding: has field.

  • Returns: 1 value(s): boolean
  • Availability: Console (BIOS) and emulator

C8B.Json_openFile

C8B.Json_openFile(path)

Native behind json.openFile.

  • Returns: 2 value(s): error string, nil, string
  • Availability: Console (BIOS) and emulator

C8B.Json_encodeLen

C8B.Json_encodeLen(handle, pretty)

Length of the encoded JSON.

  • Returns: 1 value(s): integer
  • Availability: Console (BIOS) and emulator

C8B.Json_getNumber

C8B.Json_getNumber(handle)

Native JSON binding: get number.

  • Returns: 1 value(s): number
  • Availability: Console (BIOS) and emulator

C8B.Json_getString

C8B.Json_getString(handle)

Native JSON binding: get string.

  • Returns: 1 value(s): nil, string
  • Availability: Console (BIOS) and emulator

C8B.Json_decodeFile

C8B.Json_decodeFile(path)

Native behind json.decodeFile (path form).

  • Returns: 2 value(s): error string, nil
  • Availability: Console (BIOS) and emulator

C8B.Json_getKeysLen

C8B.Json_getKeysLen(handle)

Native JSON binding: get keys len.

  • Returns: 1 value(s): integer
  • Availability: Console (BIOS) and emulator

C8B.Json_parseToLua

C8B.Json_parseToLua(jsonStr)

Parses a JSON string straight into Lua tables.

  • Availability: Console (BIOS) and emulator

C8B.Json_getArrayItem

C8B.Json_getArrayItem(handle, index)

Native JSON binding: get array item.

  • Returns: 1 value(s): handle
  • Availability: Console (BIOS) and emulator

C8B.Json_getStringLen

C8B.Json_getStringLen(handle)

Native JSON binding: get string len.

  • Returns: 1 value(s): integer
  • Availability: Console (BIOS) and emulator

C8B.Json_parseWithError

C8B.Json_parseWithError(jsonStr, jsonLen)

Parses into a native handle; returns handle, error.

  • Returns: 2 value(s): handle, nil, string
  • Availability: Console (BIOS) and emulator