API ReferenceGE Extensionsgameplayrallyutil
Rally JSONL Utilities
Utility module for reading JSON Lines (JSONL) files - line-delimited JSON format used for recce recordings (driveline, cuts, transcripts).
Utility module for reading JSON Lines (JSONL) files - line-delimited JSON format used for recce recordings (driveline, cuts, transcripts).
Public API
| Function | Signature | Returns | Description |
|---|---|---|---|
startsWithDoubleSlash | (line) | bool | Check if line is a // comment |
readFileToMemory | (fname) | string? | Read entire file contents via io.open |
splitIntoLines | (content) | table | Split string into array of lines |
parseJsonlFile | (fname, processLine, rallyUtil) | results, err | Parse JSONL file with optional transform callback |
readJsonlLines | (fname, callback) | bool | Simple line-by-line reader using io.lines |
M.parseJsonlFile | (fname, processLine, rallyUtil) | - | processLine(obj) should return the processed object or nil to skip |
M.readFileToMemory | (fname) | - | Read entire file into memory |
M.readJsonlLines | (fname, callback) | - | Calls callback(obj) for each line |
M.splitIntoLines | (content) | - | Split content into lines |
M.startsWithDoubleSlash | (line) | - | Check if a line starts with a comment marker |
How It Works
parseJsonlFile(fname, processLine, rallyUtil)
- Checks file existence via
FS:fileExists - Reads entire file into memory
- Splits into lines, trims whitespace (using
rallyUtil.trimString) - Skips empty lines and
//comments - Decodes each line as JSON via
jsonDecode - Optionally transforms via
processLine(obj)callback - Returns array of parsed objects
readJsonlLines(fname, callback)
Simpler alternative using io.lines iterator. Calls callback(obj) for each decoded line. No comment handling or trimming.
local jsonlUtils = require('gameplay/rally/util/jsonlUtils')
local rallyUtil = require('gameplay/rally/util')
-- Parse a driveline recording
local points, err = jsonlUtils.parseJsonlFile(
'/path/to/driveline.json',
function(obj)
obj.pos = vec3(obj.pos)
return obj
end,
rallyUtil
)
-- Simple read
jsonlUtils.readJsonlLines('/path/to/data.jsonl', function(obj)
print(obj.ts, obj.pos.x)
end)Notes
- JSONL format: one JSON object per line, no wrapping array
- Comment lines starting with
//are supported byparseJsonlFileonly readFileToMemoryuses rawio.open, not BeamNG'sFSAPIparseJsonlFileusesFS:fileExistsfor the existence check
See Also
- Rally Utility Colors - Related reference
- Rally Utility Normalizer - Related reference
- Gameplay Systems Guide - Guide
Rally Utility Colors
Constants module defining all color values and visual parameters used throughout the rally editor and pacenote system. Colors are RGB float arrays `{r, g, b}` or ImGui `ImVec4` for UI elements.
Rally Utility Normalizer
Simple text normalization module that applies word-replacement mappings to pacenote strings.