jsonPrettyEncoderCustom Reference
Module defined in `lua/common/jsonPrettyEncoderCustom.lua`. A customizable JSON pretty-printer with weighted key sorting and callback-controlled folding (inline vs expanded formatting).
Module defined in lua/common/jsonPrettyEncoderCustom.lua. A customizable JSON pretty-printer with weighted key sorting and callback-controlled folding (inline vs expanded formatting).
Exports
Functions
M.encode(v, lvl, numberPrecision, tableWeights, foldingCallback, _levelPath)
Encodes a Lua value as pretty-printed JSON with custom key ordering and folding control.
- Parameters:
v- any - Value to encodelvl- number|nil - Current indentation level (default: 1)numberPrecision- number|nil - Decimal precision for non-integer numbers (nil =%.10g)tableWeights- table - Map of key names (lowercase) to sort weights (1=first, 50=default, 99=last)
- Returns:
self(module table, for chaining)_levelPath- string|nil - Internal path tracking (used by foldingCallback)
- Returns: string - JSON string
Example:
local json = require('jsonPrettyEncoderCustom')
local result = json.encode(data, nil, nil,
{control = 10, bindings = 99}, -- key sort weights
function(item, lvl, path) -- folding callback
return path:sub(1,10) == '/bindings/' and tableSize(item) < 4
end
)Internal Notes
- Key weights: 1 = first, 50 = default, 99 = last. Keys at same weight are sorted alphabetically
- The folding callback receives the table item, indentation level, and a
/-delimited path string - Handles: strings, numbers, booleans, tables (arrays and objects), vec3/quat cdata, nil → "null"
- Infinity →
9e999, NaN →9e999 - Uses
tableKeys()from utils for key extraction
jsonDebug Reference
Module defined in `lua/common/jsonDebug.lua`. Debug variant of the SJSON parser that adds duplicate key detection. Structurally identical to `json.lua` but emits warnings when duplicate keys are found
kdtreebox2d Reference
Module defined in `lua/common/kdtreebox2d.lua`. K-d tree implementation for 2D axis-aligned bounding boxes (4 dimensions: xmin, ymin, xmax, ymax). Supports efficient spatial range queries with both ne